|
| 1 | +package com.reajason.javaweb.integration.jetty; |
| 2 | + |
| 3 | +import com.reajason.javaweb.integration.TestCasesProvider; |
| 4 | +import com.reajason.javaweb.memshell.Packers; |
| 5 | +import com.reajason.javaweb.memshell.Server; |
| 6 | +import com.reajason.javaweb.memshell.ShellTool; |
| 7 | +import com.reajason.javaweb.memshell.ShellType; |
| 8 | +import lombok.extern.slf4j.Slf4j; |
| 9 | +import net.bytebuddy.jar.asm.Opcodes; |
| 10 | +import org.junit.jupiter.api.AfterAll; |
| 11 | +import org.junit.jupiter.params.ParameterizedTest; |
| 12 | +import org.junit.jupiter.params.provider.Arguments; |
| 13 | +import org.junit.jupiter.params.provider.MethodSource; |
| 14 | +import org.testcontainers.containers.GenericContainer; |
| 15 | +import org.testcontainers.containers.Network; |
| 16 | +import org.testcontainers.containers.wait.strategy.Wait; |
| 17 | +import org.testcontainers.images.builder.ImageFromDockerfile; |
| 18 | +import org.testcontainers.junit.jupiter.Container; |
| 19 | +import org.testcontainers.junit.jupiter.Testcontainers; |
| 20 | + |
| 21 | +import java.util.List; |
| 22 | +import java.util.stream.Stream; |
| 23 | + |
| 24 | +import static com.reajason.javaweb.integration.ContainerTool.*; |
| 25 | +import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; |
| 26 | +import static com.reajason.javaweb.integration.ShellAssertionTool.testShellInjectAssertOk; |
| 27 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 28 | + |
| 29 | +/** |
| 30 | + * @author ReaJason |
| 31 | + * @since 2024/12/7 |
| 32 | + */ |
| 33 | +@Slf4j |
| 34 | +@Testcontainers |
| 35 | +public class Jetty75ContainerTest { |
| 36 | + public static final String imageName = "reajason/jetty:7.5.4-jdk6"; |
| 37 | + static Network network = Network.newNetwork(); |
| 38 | + @Container |
| 39 | + public final static GenericContainer<?> python = new GenericContainer<>(new ImageFromDockerfile() |
| 40 | + .withDockerfile(neoGeorgDockerfile)) |
| 41 | + .withNetwork(network); |
| 42 | + @Container |
| 43 | + public final static GenericContainer<?> container = new GenericContainer<>(imageName) |
| 44 | + .withCopyToContainer(warFile, "/usr/local/jetty/webapps/app.war") |
| 45 | + .withCopyToContainer(jattachFile, "/jattach") |
| 46 | + .withCopyToContainer(jettyPid, "/fetch_pid.sh") |
| 47 | + .withNetwork(network) |
| 48 | + .withNetworkAliases("app") |
| 49 | + .waitingFor(Wait.forHttp("/app")) |
| 50 | + .withExposedPorts(8080); |
| 51 | + |
| 52 | + static Stream<Arguments> casesProvider() { |
| 53 | + Server server = Server.Jetty; |
| 54 | + List<String> supportedShellTypes = List.of( |
| 55 | + ShellType.SERVLET, ShellType.FILTER, ShellType.LISTENER, |
| 56 | + ShellType.JETTY_AGENT_HANDLER, |
| 57 | + ShellType.JETTY_AGENT_HANDLER_ASM |
| 58 | + ); |
| 59 | + List<Packers> testPackers = List.of(Packers.JSP, Packers.JSPX, Packers.JavaDeserialize); |
| 60 | + return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); |
| 61 | + } |
| 62 | + |
| 63 | + @AfterAll |
| 64 | + static void tearDown() { |
| 65 | + String logs = container.getLogs(); |
| 66 | + assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); |
| 67 | + } |
| 68 | + |
| 69 | + @ParameterizedTest(name = "{0}|{1}{2}|{3}") |
| 70 | + @MethodSource("casesProvider") |
| 71 | + void test(String imageName, String shellType, ShellTool shellTool, Packers packer) { |
| 72 | + testShellInjectAssertOk(getUrl(container), Server.Jetty, shellType, shellTool, Opcodes.V1_6, packer, container, python); |
| 73 | + } |
| 74 | +} |
0 commit comments