From 7c126d8189ae1472a0719b73efbf99b61280996f Mon Sep 17 00:00:00 2001 From: ReaJason Date: Sat, 17 Jan 2026 14:45:17 +0800 Subject: [PATCH] refactor: memshell integration-test --- .../integration/AbstractContainerTest.java | 258 ++++++++++++++++++ .../integration/ContainerTestConfig.java | 147 ++++++++++ .../javaweb/integration/ContainerTool.java | 9 + .../glassfish/GlassFish3ContainerTest.java | 108 +++----- .../glassfish/GlassFish4ContainerTest.java | 100 ++----- .../glassfish/GlassFish501ContainerTest.java | 100 ++----- .../glassfish/GlassFish510ContainerTest.java | 100 ++----- .../glassfish/GlassFish6ContainerTest.java | 102 +++---- .../glassfish/GlassFish7ContainerTest.java | 102 +++---- .../jbossas/Jboss423ContainerTest.java | 101 +++---- .../jbossas/Jboss510ContainerTest.java | 100 +++---- .../jbossas/Jboss610ContainerTest.java | 96 +++---- .../jbossas/Jboss711ContainerTest.java | 99 +++---- .../jbosseap/JbossEap6ContainerTest.java | 98 +++---- .../jbosseap/JbossEap7ContainerTest.java | 92 ++----- .../jbosseap/JbossEap81ContainerTest.java | 96 +++---- .../memshell/jetty/Jetty10ContainerTest.java | 101 +++---- .../memshell/jetty/Jetty11ContainerTest.java | 104 +++---- .../jetty/Jetty12ee10ContainerTest.java | 101 +++---- .../jetty/Jetty12ee11ContainerTest.java | 104 +++---- .../jetty/Jetty12ee8ContainerTest.java | 97 +++---- .../jetty/Jetty12ee9ContainerTest.java | 101 +++---- .../memshell/jetty/Jetty61ContainerTest.java | 96 ++----- .../memshell/jetty/Jetty75ContainerTest.java | 97 +++---- .../memshell/jetty/Jetty76ContainerTest.java | 96 +++---- .../memshell/jetty/Jetty81ContainerTest.java | 97 +++---- .../memshell/jetty/Jetty92ContainerTest.java | 99 +++---- .../memshell/jetty/Jetty93ContainerTest.java | 100 +++---- .../memshell/jetty/Jetty94ContainerTest.java | 100 +++---- .../payara/Payara5201ContainerTest.java | 100 ++----- .../payara/Payara520225ContainerTest.java | 100 ++----- .../payara/Payara620222ContainerTest.java | 102 +++---- .../resin/Resin3116ContainerTest.java | 94 ++----- .../memshell/resin/Resin318ContainerTest.java | 90 ++---- .../resin/Resin4058ContainerTest.java | 90 ++---- .../resin/Resin4067ContainerTest.java | 91 ++---- .../SpringBoot2WebFluxContainerTest.java | 84 ++---- .../SpringBoot3WebFluxContainerTest.java | 83 ++---- .../SpringBoot1ContainerTest.java | 104 +++---- .../SpringBoot2ContainerTest.java | 125 ++++----- .../SpringBoot2JettyContainerTest.java | 120 ++++---- .../SpringBoot2UndertowContainerTest.java | 116 ++++---- .../SpringBoot2WarContainerTest.java | 104 +++---- .../SpringBoot3ContainerTest.java | 132 ++++----- .../SpringBoot3ExpressionContainerTest.java | 6 +- .../struct2/Struct2ContainerTest.java | 80 ++---- .../tomcat/Tomcat10ContainerTest.java | 108 +++----- .../tomcat/Tomcat11ContainerTest.java | 107 +++----- .../tomcat/Tomcat11JRE21ContainerTest.java | 104 +++---- .../memshell/tomcat/Tomcat5ContainerTest.java | 98 +++---- .../memshell/tomcat/Tomcat6ContainerTest.java | 99 +++---- .../memshell/tomcat/Tomcat7ContainerTest.java | 103 +++---- .../memshell/tomcat/Tomcat8ContainerTest.java | 101 +++---- .../memshell/tomcat/Tomcat9ContainerTest.java | 102 +++---- .../weblogic/WebLogic1036ContainerTest.java | 98 ++----- .../weblogic/WebLogic12214ContainerTest.java | 100 ++----- .../weblogic/WebLogic14110ContainerTest.java | 100 ++----- .../weblogic/WebLogic14120ContainerTest.java | 50 ++++ .../websphere/OpenLiberty18ContainerTest.java | 101 ++----- .../websphere/OpenLiberty20ContainerTest.java | 101 ++----- .../websphere/OpenLiberty22ContainerTest.java | 101 ++----- .../websphere/OpenLiberty25ContainerTest.java | 101 ++----- .../websphere/WebSphere855ContainerTest.java | 101 ++----- .../websphere/WebSphere905ContainerTest.java | 100 ++----- .../websphere7/WebSphere700ContainerTest.java | 86 ++---- .../wildfly/Wildfly18ContainerTest.java | 91 ++---- .../wildfly/Wildfly23ContainerTest.java | 91 ++---- .../wildfly/Wildfly26ContainerTest.java | 91 ++---- .../wildfly/Wildfly27ContainerTest.java | 95 +++---- .../wildfly/Wildfly30ContainerTest.java | 96 +++---- .../wildfly/Wildfly36ContainerTest.java | 96 +++---- .../wildfly/Wildfly9ContainerTest.java | 100 +++---- 72 files changed, 2628 insertions(+), 4515 deletions(-) create mode 100644 integration-test/src/test/java/com/reajason/javaweb/integration/AbstractContainerTest.java create mode 100644 integration-test/src/test/java/com/reajason/javaweb/integration/ContainerTestConfig.java create mode 100644 integration-test/src/test/java/com/reajason/javaweb/integration/memshell/weblogic/WebLogic14120ContainerTest.java diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/AbstractContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/AbstractContainerTest.java new file mode 100644 index 00000000..3c541844 --- /dev/null +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/AbstractContainerTest.java @@ -0,0 +1,258 @@ +package com.reajason.javaweb.integration; + +import com.reajason.javaweb.memshell.ShellTool; +import com.reajason.javaweb.memshell.ShellType; +import com.reajason.javaweb.packer.Packers; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.EnumSource; +import org.junit.jupiter.params.provider.MethodSource; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.Network; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.images.builder.ImageFromDockerfile; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; + +import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * @author ReaJason + * @since 2025/9/19 + */ +@Slf4j +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public abstract class AbstractContainerTest { + private static final String NO_PROBE = "__NO_PROBE__"; + + protected static Network newNetwork() { + return Network.newNetwork(); + } + + protected static GenericContainer buildPythonContainer(Network network) { + return new GenericContainer<>(new ImageFromDockerfile() + .withDockerfile(ContainerTool.neoGeorgDockerfile)) + .withNetwork(network); + } + + protected static GenericContainer buildContainer(ContainerTestConfig config, Network network) { + GenericContainer container = createContainer(config); + if (config.getWarFile() != null && StringUtils.isNotBlank(config.getWarDeployPath())) { + container.withCopyToContainer(config.getWarFile(), config.getWarDeployPath()); + } + if(config.getJarFile() != null && StringUtils.isNotBlank(config.getJarDeployPath())){ + container.withCopyToContainer(config.getJarFile(), config.getJarDeployPath()); + } + if (config.getJattachFile() != null) { + container.withCopyToContainer(config.getJattachFile(), "/jattach"); + } + if (config.getPidScript() != null) { + container.withCopyToContainer(config.getPidScript(), "/fetch_pid.sh"); + } + Map env = config.getEnv(); + if (env != null) { + env.forEach(container::withEnv); + } + if (network != null) { + container.withNetwork(network); + if (StringUtils.isNotBlank(config.getNetworkAlias())) { + container.withNetworkAliases(config.getNetworkAlias()); + } + } + if (config.getWaitStrategy() != null) { + container.waitingFor(config.getWaitStrategy()); + } else if (StringUtils.isNotBlank(config.getHealthCheckPath())) { + container.waitingFor(Wait.forHttp(config.getHealthCheckPath())); + } + container.withExposedPorts(config.getExposedPort()); + if (config.isPrivilegedMode()) { + container.withPrivilegedMode(true); + } + if(config.getCommand() != null){ + container.withCommand(config.getCommand()); + } + return container; + } + + protected static GenericContainer buildContainer(ContainerTestConfig config) { + return buildContainer(config, null); + } + + protected abstract ContainerTestConfig getConfig(); + + @AfterAll + void tearDown() { + GenericContainer container = getContainer(); + if (container == null) { + return; + } + long logDelayMillis = getConfig().getLogDelayMillis(); + if (logDelayMillis > 0) { + try { + Thread.sleep(logDelayMillis); + } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); + } + } + String logs = container.getLogs(); + if (getConfig().isLogContainerOutput()) { + log.info(logs); + } + if (getConfig().isAssertLogs()) { + assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); + } + } + + @ParameterizedTest(name = "{0}|{1}{2}|{3}") + @MethodSource("casesProvider") + void test(String imageName, String shellType, String shellTool, Packers packer) { + runShellInject(getConfig(), shellType, shellTool, packer); + } + + @ParameterizedTest + @MethodSource("probeShellTypesProvider") + void testProbeInject(String shellType) { + if (NO_PROBE.equals(shellType)) { + Assumptions.assumeTrue(false, "No probe shell types configured."); + } + runProbeInject(getConfig(), shellType); + } + + @ParameterizedTest + @EnumSource(names = {"ClassLoaderJSP", "ClassLoaderJSPUnicode", "DefineClassJSP", "DefineClassJSPUnicode", "JSPX", "JSPXUnicode"}) + void testJspPackers(Packers packer) { + ContainerTestConfig config = getConfig(); + if (config.isEnableJspPackerTest()) { + String shellType = config.isJakarta() ? ShellType.JAKARTA_FILTER : ShellType.FILTER; + String shellTool = ShellTool.Command; + runShellInject(config, shellType, shellTool, packer); + } + } + + protected Stream casesProvider() { + return generateTestCases(getConfig()); + } + + protected Stream probeShellTypesProvider() { + List probeShellTypes = getConfig().getProbeShellTypes(); + if (probeShellTypes == null || probeShellTypes.isEmpty()) { + return Stream.of(NO_PROBE); + } + return probeShellTypes.stream(); + } + + protected static Stream generateTestCases(ContainerTestConfig config) { + if (config.getUnSupportedCases() != null || config.getUnSupportedShellTools() != null) { + return TestCasesProvider.getTestCases( + config.getImageName(), + config.getServer(), + config.getSupportedShellTypes(), + config.getTestPackers(), + config.getUnSupportedCases(), + config.getUnSupportedShellTools()); + } + return TestCasesProvider.getTestCases( + config.getImageName(), + config.getServer(), + config.getSupportedShellTypes(), + config.getTestPackers()); + } + + protected void runShellInject(ContainerTestConfig config, String shellType, String shellTool, Packers packer) { + String url = getUrl(); + if (StringUtils.isNotBlank(config.getServerVersion())) { + ShellAssertion.shellInjectIsOk(url, config.getServer(), config.getServerVersion(), shellType, shellTool, + config.getTargetJdkVersion(), packer, getContainer(), getPythonContainer()); + } else { + ShellAssertion.shellInjectIsOk(url, config.getServer(), shellType, shellTool, + config.getTargetJdkVersion(), packer, getContainer(), getPythonContainer()); + } + } + + protected void runProbeInject(ContainerTestConfig config, String shellType) { + String url = getUrl(); + int probeTargetJdkVersion = config.getProbeTargetJdkVersion() == null + ? config.getTargetJdkVersion() + : config.getProbeTargetJdkVersion(); + if (StringUtils.isNotBlank(config.getServerVersion())) { + ShellAssertion.testProbeInject(url, config.getServer(), config.getServerVersion(), shellType, probeTargetJdkVersion); + } else { + ShellAssertion.testProbeInject(url, config.getServer(), shellType, probeTargetJdkVersion); + } + } + + protected String getUrl() { + GenericContainer container = getContainer(); + ContainerTestConfig config = getConfig(); + String host = container.getHost(); + int port = container.getMappedPort(config.getExposedPort()); + String url = "http://" + host + ":" + port; + String contextPath = config.getContextPath(); + if (StringUtils.isNotBlank(contextPath)) { + if (!contextPath.startsWith("/")) { + contextPath = "/" + contextPath; + } + url += contextPath; + } + log.info("container started, app url is : {}", url); + return url; + } + + protected GenericContainer getContainer() { + return getContainerField("container", true); + } + + protected GenericContainer getPythonContainer() { + return getContainerField("python", false); + } + + private static GenericContainer createContainer(ContainerTestConfig config) { + if (config.getDockerfilePath() != null) { + return new GenericContainer<>(new ImageFromDockerfile() + .withDockerfile(config.getDockerfilePath())); + } + if (StringUtils.isBlank(config.getImageName())) { + throw new IllegalArgumentException("imageName is required when dockerfilePath is not set."); + } + return new GenericContainer<>(config.getImageName()); + } + + private GenericContainer getContainerField(String fieldName, boolean required) { + Field field = findField(getClass(), fieldName); + if (field == null) { + if (required) { + throw new IllegalStateException("Missing @" + fieldName + " container on " + getClass().getName()); + } + return null; + } + try { + field.setAccessible(true); + Object value = field.get(Modifier.isStatic(field.getModifiers()) ? null : this); + return (GenericContainer) value; + } catch (IllegalAccessException ex) { + throw new IllegalStateException("Unable to access " + fieldName + " on " + getClass().getName(), ex); + } + } + + private static Field findField(Class type, String name) { + Class current = type; + while (current != null) { + try { + return current.getDeclaredField(name); + } catch (NoSuchFieldException ex) { + current = current.getSuperclass(); + } + } + return null; + } +} diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/ContainerTestConfig.java b/integration-test/src/test/java/com/reajason/javaweb/integration/ContainerTestConfig.java new file mode 100644 index 00000000..ca5f6e4a --- /dev/null +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/ContainerTestConfig.java @@ -0,0 +1,147 @@ +package com.reajason.javaweb.integration; + +import com.reajason.javaweb.Server; +import com.reajason.javaweb.packer.Packers; +import lombok.Builder; +import lombok.Getter; +import net.bytebuddy.jar.asm.Opcodes; +import org.apache.commons.lang3.tuple.Triple; +import org.testcontainers.containers.wait.strategy.WaitStrategy; +import org.testcontainers.utility.MountableFile; + +import java.nio.file.Path; +import java.util.List; +import java.util.Map; + +/** + * @author ReaJason + * @since 2025/9/19 + */ +@Getter +@Builder +public class ContainerTestConfig { + private final String imageName; + private final Path dockerfilePath; + private final String command; + + private final String server; + private final String serverVersion; + @Builder.Default + private final int targetJdkVersion = Opcodes.V1_8; + private final Integer probeTargetJdkVersion; + + @Builder.Default + private final int exposedPort = 8080; + @Builder.Default + private final String contextPath = "/app"; + @Builder.Default + private final String healthCheckPath = "/app"; + private final WaitStrategy waitStrategy; + + private final MountableFile warFile; + private final String warDeployPath; + + private final MountableFile jarFile; + private final String jarDeployPath; + + @Builder.Default + private final MountableFile jattachFile = ContainerTool.jattachFile; + private final MountableFile pidScript; + + private final List supportedShellTypes; + private final List testPackers; + private final List probeShellTypes; + private final List> unSupportedCases; + private final List unSupportedShellTools; + + @Builder.Default + private final boolean assertLogs = true; + @Builder.Default + private final boolean logContainerOutput = true; + @Builder.Default + private final long logDelayMillis = 0L; + @Builder.Default + private final boolean privilegedMode = false; + @Builder.Default + private final String networkAlias = "app"; + private final Map env; + @Builder.Default + private final boolean jakarta = false; + @Builder.Default + private final boolean enableJspPackerTest = true; + + public static ContainerTestConfigBuilder tomcat(String imageName) { + return builder() + .imageName(imageName) + .server(Server.Tomcat) + .warFile(ContainerTool.warFile) + .warDeployPath("/usr/local/tomcat/webapps/app.war") + .pidScript(ContainerTool.tomcatPid); + } + + public static ContainerTestConfigBuilder jetty(String imageName) { + return builder() + .imageName(imageName) + .server(Server.Jetty) + .warFile(ContainerTool.warFile) + .warDeployPath("/var/lib/jetty/webapps/app.war") + .pidScript(ContainerTool.jettyPid); + } + + public static ContainerTestConfigBuilder resin(String imageName, String warDeployPath) { + return builder() + .imageName(imageName) + .server(Server.Resin) + .warFile(ContainerTool.warFile) + .warDeployPath(warDeployPath) + .pidScript(ContainerTool.resinPid); + } + + public static ContainerTestConfigBuilder jboss(String imageName, String warDeployPath) { + return builder() + .imageName(imageName) + .server(Server.JBoss) + .warFile(ContainerTool.warFile) + .warDeployPath(warDeployPath) + .pidScript(ContainerTool.jbossPid); + } + + public static ContainerTestConfigBuilder undertow(String imageName, String warDeployPath) { + return builder() + .imageName(imageName) + .server(Server.Undertow) + .warFile(ContainerTool.warFile) + .warDeployPath(warDeployPath) + .pidScript(ContainerTool.jbossPid); + } + + public static ContainerTestConfigBuilder glassFish(String imageName, String warDeployPath) { + return builder() + .imageName(imageName) + .server(Server.GlassFish) + .warFile(ContainerTool.warFile) + .warDeployPath(warDeployPath) + .pidScript(ContainerTool.glassfishPid); + } + + public static ContainerTestConfigBuilder webLogic(String imageName, String warDeployPath) { + return builder() + .imageName(imageName) + .server(Server.WebLogic) + .warFile(ContainerTool.warFile) + .warDeployPath(warDeployPath) + .pidScript(ContainerTool.weblogicPid) + .exposedPort(7001); + } + + public static ContainerTestConfigBuilder webSphere(String imageName, String warDeployPath) { + return builder() + .imageName(imageName) + .server(Server.WebSphere) + .warFile(ContainerTool.warFile) + .warDeployPath(warDeployPath) + .pidScript(ContainerTool.webspherePid) + .exposedPort(9080) + .privilegedMode(true); + } +} diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/ContainerTool.java b/integration-test/src/test/java/com/reajason/javaweb/integration/ContainerTool.java index f99124d1..7d23419d 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/ContainerTool.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/ContainerTool.java @@ -18,6 +18,15 @@ public class ContainerTool { public static final MountableFile warFile = MountableFile.forHostPath(Path.of("..", "vul", "vul-webapp", "build", "libs", "vul-webapp.war").toAbsolutePath(), 0666); public static final MountableFile struct2WarFile = MountableFile.forHostPath(Path.of("..", "vul", "vul-struct2", "build", "libs", "vul-struct2.war").toAbsolutePath()); public static final MountableFile springBoot2WarFile = MountableFile.forHostPath(Path.of("..", "vul", "vul-springboot2", "build", "libs", "vul-springboot2.war").toAbsolutePath()); + + public static final MountableFile springBoot1JarFile = MountableFile.forHostPath(Path.of("..", "vul", "vul-springboot1", "build", "libs", "vul-springboot1.jar").toAbsolutePath()); + public static final MountableFile springBoot2JarFile = MountableFile.forHostPath(Path.of("..", "vul", "vul-springboot2", "build", "libs", "vul-springboot2.jar").toAbsolutePath()); + public static final MountableFile springBoot2JettyJarFile = MountableFile.forHostPath(Path.of("..", "vul", "vul-springboot2-jetty", "build", "libs", "vul-springboot2-jetty.jar").toAbsolutePath()); + public static final MountableFile springBoot2UndertowJarFile = MountableFile.forHostPath(Path.of("..", "vul", "vul-springboot2-undertow", "build", "libs", "vul-springboot2-undertow.jar").toAbsolutePath()); + public static final MountableFile springBoot2WebfluxJarFile = MountableFile.forHostPath(Path.of("..", "vul", "vul-springboot2-webflux", "build", "libs", "vul-springboot2-webflux.jar").toAbsolutePath()); + public static final MountableFile springBoot3JarFile = MountableFile.forHostPath(Path.of("..", "vul", "vul-springboot3", "build", "libs", "vul-springboot3.jar").toAbsolutePath()); + public static final MountableFile springBoot3WebfluxJarFile = MountableFile.forHostPath(Path.of("..", "vul", "vul-springboot3-webflux", "build", "libs", "vul-springboot3-webflux.jar").toAbsolutePath()); + public static final Path neoGeorgDockerfile = Path.of("..", "assets", "neoreg", "Dockerfile").toAbsolutePath(); public static final Path springBoot1Dockerfile = Path.of("..", "vul", "vul-springboot1", "Dockerfile").toAbsolutePath(); public static final Path springBoot2Dockerfile = Path.of("..", "vul", "vul-springboot2", "Dockerfile").toAbsolutePath(); diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/glassfish/GlassFish3ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/glassfish/GlassFish3ContainerTest.java index 053139f1..3c34de17 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/glassfish/GlassFish3ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/glassfish/GlassFish3ContainerTest.java @@ -1,99 +1,59 @@ package com.reajason.javaweb.integration.memshell.glassfish; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellTool; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; import org.apache.commons.lang3.tuple.Triple; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/12 */ -@Slf4j @Testcontainers -public class GlassFish3ContainerTest { - public static final String imageName = "reajason/glassfish:3.1.2.2-jdk6"; - static Network network = Network.newNetwork(); +public class GlassFish3ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.glassFish( + "reajason/glassfish:3.1.2.2-jdk6", + "/usr/local/glassfish3/glassfish/domains/domain1/autodeploy/app.war") + .targetJdkVersion(Opcodes.V1_6) + .waitStrategy(Wait.forLogMessage(".*(deployed|done).*", 1)) + .supportedShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.AGENT_FILTER_CHAIN, + ShellType.CATALINA_AGENT_CONTEXT_VALVE + )) + .testPackers(List.of(Packers.JSP)) + .unSupportedCases(List.of( + Triple.of(ShellType.AGENT_FILTER_CHAIN, ShellTool.Suo5v2, Packers.AgentJar), + Triple.of(ShellType.CATALINA_AGENT_CONTEXT_VALVE, ShellTool.Suo5v2, Packers.AgentJar) + )) + .probeShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.VALVE + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public static final GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/usr/local/glassfish3/glassfish/domains/domain1/autodeploy/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(glassfishPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forLogMessage(".*(deployed|done).*", 1)) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - @BeforeAll - static void setup() { - container.waitingFor(Wait.forHttp("/app")); - } - - static Stream casesProvider() { - String server = Server.GlassFish; - List supportedShellTypes = List.of( - ShellType.FILTER, - ShellType.LISTENER, - ShellType.VALVE, - ShellType.AGENT_FILTER_CHAIN, - ShellType.CATALINA_AGENT_CONTEXT_VALVE - ); - List testPackers = List.of(Packers.JSP); - List> unSupportedCases = List.of( - Triple.of(ShellType.AGENT_FILTER_CHAIN, ShellTool.Suo5v2, Packers.AgentJar), // request.inputStream is empty - Triple.of(ShellType.CATALINA_AGENT_CONTEXT_VALVE, ShellTool.Suo5v2, Packers.AgentJar) // request.inputStream is empty - ); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers, unSupportedCases); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.GlassFish, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.FILTER, - ShellType.LISTENER, - ShellType.VALVE,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.GlassFish, shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/glassfish/GlassFish4ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/glassfish/GlassFish4ContainerTest.java index aa791320..82c80ad4 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/glassfish/GlassFish4ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/glassfish/GlassFish4ContainerTest.java @@ -1,93 +1,51 @@ package com.reajason.javaweb.integration.memshell.glassfish; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/12 */ -@Slf4j @Testcontainers -public class GlassFish4ContainerTest { - public static final String imageName = "reajason/glassfish:4.1.2-quick"; - static Network network = Network.newNetwork(); +public class GlassFish4ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.glassFish( + "reajason/glassfish:4.1.2-quick", + "/usr/local/glassfish4/glassfish/domains/domain1/autodeploy/app.war") + .targetJdkVersion(Opcodes.V1_6) + .supportedShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.AGENT_FILTER_CHAIN, + ShellType.CATALINA_AGENT_CONTEXT_VALVE + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.VALVE + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public static final GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/usr/local/glassfish4/glassfish/domains/domain1/autodeploy/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(glassfishPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - @BeforeAll - static void setup() { - container.waitingFor(Wait.forLogMessage(".*(deployed|done).*", 1)); - } - - static Stream casesProvider() { - String server = Server.GlassFish; - List supportedShellTypes = List.of( - ShellType.FILTER, - ShellType.LISTENER, - ShellType.VALVE, - ShellType.AGENT_FILTER_CHAIN, - ShellType.CATALINA_AGENT_CONTEXT_VALVE - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.GlassFish, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.FILTER, - ShellType.LISTENER, - ShellType.VALVE,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.GlassFish, shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/glassfish/GlassFish501ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/glassfish/GlassFish501ContainerTest.java index b6aa1b98..326ca326 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/glassfish/GlassFish501ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/glassfish/GlassFish501ContainerTest.java @@ -1,93 +1,51 @@ package com.reajason.javaweb.integration.memshell.glassfish; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/12 */ -@Slf4j @Testcontainers -public class GlassFish501ContainerTest { - public static final String imageName = "reajason/glassfish:5.0.1"; - static Network network = Network.newNetwork(); +public class GlassFish501ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.glassFish( + "reajason/glassfish:5.0.1", + "/usr/local/glassfish5/glassfish/domains/domain1/autodeploy/app.war") + .targetJdkVersion(Opcodes.V1_6) + .supportedShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.AGENT_FILTER_CHAIN, + ShellType.CATALINA_AGENT_CONTEXT_VALVE + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.VALVE + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public static final GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/usr/local/glassfish5/glassfish/domains/domain1/autodeploy/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(glassfishPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.GlassFish; - List supportedShellTypes = List.of( - ShellType.FILTER, - ShellType.LISTENER, - ShellType.VALVE, - ShellType.AGENT_FILTER_CHAIN, - ShellType.CATALINA_AGENT_CONTEXT_VALVE - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @BeforeAll - static void setup() { - container.waitingFor(Wait.forLogMessage(".*(deployed|done).*", 1)); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.GlassFish, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.FILTER, - ShellType.LISTENER, - ShellType.VALVE,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.GlassFish, shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/glassfish/GlassFish510ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/glassfish/GlassFish510ContainerTest.java index 40bc6e31..911f9fdd 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/glassfish/GlassFish510ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/glassfish/GlassFish510ContainerTest.java @@ -1,93 +1,51 @@ package com.reajason.javaweb.integration.memshell.glassfish; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/12 */ -@Slf4j @Testcontainers -public class GlassFish510ContainerTest { - public static final String imageName = "reajason/glassfish:5.1.0"; - static Network network = Network.newNetwork(); +public class GlassFish510ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.glassFish( + "reajason/glassfish:5.1.0", + "/usr/local/glassfish5/glassfish/domains/domain1/autodeploy/app.war") + .targetJdkVersion(Opcodes.V1_6) + .supportedShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.AGENT_FILTER_CHAIN, + ShellType.CATALINA_AGENT_CONTEXT_VALVE + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.VALVE + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public static final GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/usr/local/glassfish5/glassfish/domains/domain1/autodeploy/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(glassfishPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.GlassFish; - List supportedShellTypes = List.of( - ShellType.FILTER, - ShellType.LISTENER, - ShellType.VALVE, - ShellType.AGENT_FILTER_CHAIN, - ShellType.CATALINA_AGENT_CONTEXT_VALVE - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @BeforeAll - static void setup() { - container.waitingFor(Wait.forLogMessage(".*(deployed|done).*", 1)); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.GlassFish, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.FILTER, - ShellType.LISTENER, - ShellType.VALVE,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.GlassFish, shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/glassfish/GlassFish6ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/glassfish/GlassFish6ContainerTest.java index 6ae7e92b..f0b65d8b 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/glassfish/GlassFish6ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/glassfish/GlassFish6ContainerTest.java @@ -1,92 +1,58 @@ package com.reajason.javaweb.integration.memshell.glassfish; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellTool; import com.reajason.javaweb.memshell.ShellType; +import com.reajason.javaweb.memshell.shelltool.antsword.AntSword; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; +import static com.reajason.javaweb.integration.ContainerTool.warJakartaFile; /** * @author ReaJason * @since 2024/12/12 */ -@Slf4j @Testcontainers -public class GlassFish6ContainerTest { - public static final String imageName = "reajason/glassfish:6.2.6-jdk11"; - static Network network = Network.newNetwork(); +public class GlassFish6ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.glassFish( + "reajason/glassfish:6.2.6-jdk11", + "/usr/local/glassfish6/glassfish/domains/domain1/autodeploy/app.war") + .warFile(warJakartaFile) + .targetJdkVersion(Opcodes.V11) + .assertLogs(false) + .supportedShellTypes(List.of( + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_LISTENER, + ShellType.JAKARTA_VALVE, + ShellType.AGENT_FILTER_CHAIN, + ShellType.CATALINA_AGENT_CONTEXT_VALVE + )) + .unSupportedShellTools(List.of(ShellTool.AntSword)) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_LISTENER, + ShellType.JAKARTA_VALVE + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public static final GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warJakartaFile, "/usr/local/glassfish6/glassfish/domains/domain1/autodeploy/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(glassfishPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.GlassFish; - List supportedShellTypes = List.of( - ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_LISTENER, - ShellType.JAKARTA_VALVE, - ShellType.AGENT_FILTER_CHAIN, - ShellType.CATALINA_AGENT_CONTEXT_VALVE - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers, null, List.of(ShellTool.AntSword)); - } - - @BeforeAll - static void setup() { - container.waitingFor(Wait.forLogMessage(".*(deployed|done).*", 1)); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); -// assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.GlassFish, shellType, shellTool, Opcodes.V11, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_LISTENER, - ShellType.JAKARTA_VALVE,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.GlassFish, shellType, Opcodes.V11); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/glassfish/GlassFish7ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/glassfish/GlassFish7ContainerTest.java index 1ea0adc1..3e52ebb9 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/glassfish/GlassFish7ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/glassfish/GlassFish7ContainerTest.java @@ -1,94 +1,56 @@ package com.reajason.javaweb.integration.memshell.glassfish; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellTool; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; +import static com.reajason.javaweb.integration.ContainerTool.warJakartaFile; /** * @author ReaJason * @since 2024/12/12 */ -@Slf4j @Testcontainers -public class GlassFish7ContainerTest { - public static final String imageName = "reajason/glassfish:7.0.20-jdk17"; - static Network network = Network.newNetwork(); +public class GlassFish7ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.glassFish( + "reajason/glassfish:7.0.20-jdk17", + "/usr/local/glassfish7/glassfish/domains/domain1/autodeploy/app.war") + .warFile(warJakartaFile) + .targetJdkVersion(Opcodes.V17) + .supportedShellTypes(List.of( + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_LISTENER, + ShellType.JAKARTA_VALVE, + ShellType.AGENT_FILTER_CHAIN, + ShellType.CATALINA_AGENT_CONTEXT_VALVE + )) + .unSupportedShellTools(List.of(ShellTool.AntSword)) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_LISTENER, + ShellType.JAKARTA_VALVE + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public static final GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warJakartaFile, "/usr/local/glassfish7/glassfish/domains/domain1/autodeploy/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(glassfishPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forLogMessage(".*JMXService.*", 1)) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.GlassFish; - List supportedShellTypes = List.of( - ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_LISTENER, - ShellType.JAKARTA_VALVE, - ShellType.AGENT_FILTER_CHAIN, - ShellType.CATALINA_AGENT_CONTEXT_VALVE - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers, null, List.of(ShellTool.AntSword)); - } - - @BeforeAll - static void setup() { - container.waitingFor(Wait.forHttp("/app/test")); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.GlassFish, shellType, shellTool, Opcodes.V17, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_LISTENER, - ShellType.JAKARTA_VALVE,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.GlassFish, shellType, Opcodes.V17); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbossas/Jboss423ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbossas/Jboss423ContainerTest.java index 4b259829..cae21b4e 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbossas/Jboss423ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbossas/Jboss423ContainerTest.java @@ -1,89 +1,56 @@ package com.reajason.javaweb.integration.memshell.jbossas; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; +import java.util.Map; /** * @author ReaJason * @since 2024/12/10 */ -@Slf4j @Testcontainers -public class Jboss423ContainerTest { - public static final String imageName = "reajason/jboss:4-jdk6"; - static Network network = Network.newNetwork(); +public class Jboss423ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.jboss( + "reajason/jboss:4-jdk6", + "/usr/local/jboss/server/default/deploy/app.war") + .targetJdkVersion(Opcodes.V1_6) + .env(Map.of("JAVA_OPTS", + "-Xms128m -Xmx512m -XX:MaxPermSize=128M -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000")) + .supportedShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.PROXY_VALVE, + ShellType.AGENT_FILTER_CHAIN, + ShellType.CATALINA_AGENT_CONTEXT_VALVE + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.PROXY_VALVE + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public static final GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/usr/local/jboss/server/default/deploy/app.war") - .withEnv("JAVA_OPTS", "-Xms128m -Xmx512m -XX:MaxPermSize=128M -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jbossPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.JBoss; - List supportedShellTypes = List.of( - ShellType.FILTER, - ShellType.LISTENER, - ShellType.VALVE, - ShellType.PROXY_VALVE, - ShellType.AGENT_FILTER_CHAIN, - ShellType.CATALINA_AGENT_CONTEXT_VALVE - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.JBoss, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.FILTER, - ShellType.LISTENER, - ShellType.VALVE, - ShellType.PROXY_VALVE,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.JBoss, shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbossas/Jboss510ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbossas/Jboss510ContainerTest.java index f040012d..33d93a6a 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbossas/Jboss510ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbossas/Jboss510ContainerTest.java @@ -1,91 +1,55 @@ package com.reajason.javaweb.integration.memshell.jbossas; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellTool; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/10 */ -@Slf4j @Testcontainers -public class Jboss510ContainerTest { - public static final String imageName = "reajason/jboss:5-jdk6"; - static Network network = Network.newNetwork(); +public class Jboss510ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.jboss( + "reajason/jboss:5-jdk6", + "/usr/local/jboss/server/web/deploy/app.war") + .targetJdkVersion(Opcodes.V1_6) + .supportedShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.PROXY_VALVE, + ShellType.AGENT_FILTER_CHAIN, + ShellType.CATALINA_AGENT_CONTEXT_VALVE + )) + .testPackers(List.of(Packers.JSP)) + .unSupportedShellTools(List.of(ShellTool.Behinder)) + .probeShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.PROXY_VALVE + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public static final GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/usr/local/jboss/server/web/deploy/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jbossPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.JBoss; - List supportedShellTypes = List.of( - ShellType.FILTER, ShellType.LISTENER, - ShellType.VALVE, - ShellType.PROXY_VALVE, - ShellType.AGENT_FILTER_CHAIN, - ShellType.CATALINA_AGENT_CONTEXT_VALVE - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers, - null, List.of(ShellTool.Behinder) // Behinder SocketTimeOuts - ); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.JBoss, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.FILTER, - ShellType.LISTENER, - ShellType.VALVE, - ShellType.PROXY_VALVE,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.JBoss, shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbossas/Jboss610ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbossas/Jboss610ContainerTest.java index 180f87a6..0266d46a 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbossas/Jboss610ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbossas/Jboss610ContainerTest.java @@ -1,87 +1,53 @@ package com.reajason.javaweb.integration.memshell.jbossas; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/10 */ -@Slf4j @Testcontainers -public class Jboss610ContainerTest { - public static final String imageName = "reajason/jboss:6-jdk7"; - static Network network = Network.newNetwork(); +public class Jboss610ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.jboss( + "reajason/jboss:6-jdk7", + "/usr/local/jboss/server/jbossweb-standalone/deploy/app.war") + .targetJdkVersion(Opcodes.V1_6) + .supportedShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.PROXY_VALVE, + ShellType.AGENT_FILTER_CHAIN, + ShellType.CATALINA_AGENT_CONTEXT_VALVE + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.PROXY_VALVE + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public static final GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/usr/local/jboss/server/jbossweb-standalone/deploy/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jbossPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.JBoss; - List supportedShellTypes = List.of( - ShellType.FILTER, ShellType.LISTENER, - ShellType.VALVE, - ShellType.PROXY_VALVE, - ShellType.AGENT_FILTER_CHAIN, - ShellType.CATALINA_AGENT_CONTEXT_VALVE - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.JBoss, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.FILTER, - ShellType.LISTENER, - ShellType.VALVE, - ShellType.PROXY_VALVE,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.JBoss, shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbossas/Jboss711ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbossas/Jboss711ContainerTest.java index c221d170..9c9857f7 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbossas/Jboss711ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbossas/Jboss711ContainerTest.java @@ -1,90 +1,53 @@ package com.reajason.javaweb.integration.memshell.jbossas; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/10 */ -@Slf4j @Testcontainers -public class Jboss711ContainerTest { - public static final String imageName = "reajason/jboss:7-jdk7"; - static Network network = Network.newNetwork(); +public class Jboss711ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.jboss( + "reajason/jboss:7-jdk7", + "/usr/local/jboss/standalone/deployments/app.war") + .targetJdkVersion(Opcodes.V1_7) + .supportedShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.PROXY_VALVE, + ShellType.AGENT_FILTER_CHAIN, + ShellType.CATALINA_AGENT_CONTEXT_VALVE + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.PROXY_VALVE + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public static final GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/usr/local/jboss/standalone/deployments/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jbossPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - /** - * 找不到 Templates 类暂时先不测试反序列化 - */ - static Stream casesProvider() { - String server = Server.JBoss; - List supportedShellTypes = List.of( - ShellType.FILTER, ShellType.LISTENER, - ShellType.VALVE, - ShellType.PROXY_VALVE, - ShellType.AGENT_FILTER_CHAIN, - ShellType.CATALINA_AGENT_CONTEXT_VALVE - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.JBoss, shellType, shellTool, Opcodes.V1_7, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.FILTER, - ShellType.LISTENER, - ShellType.VALVE, - ShellType.PROXY_VALVE,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.JBoss, shellType, Opcodes.V1_7); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbosseap/JbossEap6ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbosseap/JbossEap6ContainerTest.java index b3275bda..a1b8daf1 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbosseap/JbossEap6ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbosseap/JbossEap6ContainerTest.java @@ -1,89 +1,53 @@ package com.reajason.javaweb.integration.memshell.jbosseap; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/10 */ -@Slf4j @Testcontainers -public class JbossEap6ContainerTest { - public static final String imageName = "reajason/jboss:eap-6-jdk8"; - static Network network = Network.newNetwork(); +public class JbossEap6ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.jboss( + "reajason/jboss:eap-6-jdk8", + "/usr/local/jboss/standalone/deployments/app.war") + .targetJdkVersion(Opcodes.V1_6) + .supportedShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.PROXY_VALVE, + ShellType.AGENT_FILTER_CHAIN, + ShellType.CATALINA_AGENT_CONTEXT_VALVE + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.PROXY_VALVE + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public static final GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/usr/local/jboss/standalone/deployments/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jbossPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.JBoss; - List supportedShellTypes = List.of( - ShellType.FILTER, - ShellType.LISTENER, - ShellType.VALVE, - ShellType.PROXY_VALVE, - ShellType.AGENT_FILTER_CHAIN, - ShellType.CATALINA_AGENT_CONTEXT_VALVE - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.JBoss, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.FILTER, - ShellType.LISTENER, - ShellType.VALVE, - ShellType.PROXY_VALVE,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.JBoss, shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbosseap/JbossEap7ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbosseap/JbossEap7ContainerTest.java index 9d98c5df..150ab830 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbosseap/JbossEap7ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbosseap/JbossEap7ContainerTest.java @@ -1,86 +1,50 @@ package com.reajason.javaweb.integration.memshell.jbosseap; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/10 */ -@Slf4j @Testcontainers -public class JbossEap7ContainerTest { - public static final String imageName = "reajason/jboss:eap-7-jdk8"; - static Network network = Network.newNetwork(); +public class JbossEap7ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.undertow( + "reajason/jboss:eap-7-jdk8", + "/usr/local/jboss/standalone/deployments/app.war") + .targetJdkVersion(Opcodes.V1_6) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.UNDERTOW_AGENT_SERVLET_HANDLER + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public static final GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/usr/local/jboss/standalone/deployments/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jbossPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Undertow; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.UNDERTOW_AGENT_SERVLET_HANDLER - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Undertow, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Undertow, shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbosseap/JbossEap81ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbosseap/JbossEap81ContainerTest.java index 0e2bb2ef..367fafec 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbosseap/JbossEap81ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jbosseap/JbossEap81ContainerTest.java @@ -1,89 +1,55 @@ package com.reajason.javaweb.integration.memshell.jbosseap; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellTool; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; +import static com.reajason.javaweb.integration.ContainerTool.warJakartaFile; /** * @author ReaJason * @since 2024/12/10 */ -@Slf4j @Testcontainers -public class JbossEap81ContainerTest { - public static final String imageName = "reajason/jboss:eap-8.1-jdk17"; - static Network network = Network.newNetwork(); +public class JbossEap81ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.undertow( + "reajason/jboss:eap-8.1-jdk17", + "/usr/local/jboss/standalone/deployments/app.war") + .warFile(warJakartaFile) + .targetJdkVersion(Opcodes.V17) + .supportedShellTypes(List.of( + ShellType.JAKARTA_SERVLET, + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_LISTENER, + ShellType.UNDERTOW_AGENT_SERVLET_HANDLER + )) + .testPackers(List.of(Packers.JSP)) + .unSupportedShellTools(List.of(ShellTool.AntSword)) + .probeShellTypes(List.of( + ShellType.JAKARTA_SERVLET, + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_LISTENER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public static final GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warJakartaFile, "/usr/local/jboss/standalone/deployments/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jbossPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Undertow; - List supportedShellTypes = List.of( - ShellType.JAKARTA_SERVLET, - ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_LISTENER, - ShellType.UNDERTOW_AGENT_SERVLET_HANDLER - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers, - null, List.of(ShellTool.AntSword) // AntSword not support jakarta - ); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Undertow, shellType, shellTool, Opcodes.V17, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.JAKARTA_SERVLET, - ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_LISTENER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Undertow, shellType, Opcodes.V17); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty10ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty10ContainerTest.java index c1eb9af4..bb41d35c 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty10ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty10ContainerTest.java @@ -1,90 +1,55 @@ package com.reajason.javaweb.integration.memshell.jetty; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/7 */ -@Slf4j @Testcontainers -public class Jetty10ContainerTest { - public static final String imageName = "jetty:10-jre11"; - static Network network = Network.newNetwork(); +public class Jetty10ContainerTest extends AbstractContainerTest { + + private static final ContainerTestConfig CONFIG = ContainerTestConfig + .jetty("jetty:10-jre11") + .serverVersion("7+") + .targetJdkVersion(Opcodes.V11) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.HANDLER, + ShellType.CUSTOMIZER, + ShellType.JETTY_AGENT_HANDLER + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.HANDLER, + ShellType.CUSTOMIZER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/var/lib/jetty/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jettyPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Jetty; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.HANDLER, - ShellType.CUSTOMIZER, - ShellType.JETTY_AGENT_HANDLER - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Jetty, "7+", shellType, shellTool, Opcodes.V11, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.HANDLER, - ShellType.CUSTOMIZER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Jetty, "7+", shellType, Opcodes.V11); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty11ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty11ContainerTest.java index 6bd22172..7109130a 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty11ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty11ContainerTest.java @@ -1,92 +1,60 @@ package com.reajason.javaweb.integration.memshell.jetty; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellTool; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; +import static com.reajason.javaweb.integration.ContainerTool.warJakartaFile; /** * @author ReaJason * @since 2024/12/7 */ -@Slf4j @Testcontainers -public class Jetty11ContainerTest { - public static final String imageName = "jetty:11.0-jre17"; - static Network network = Network.newNetwork(); +public class Jetty11ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig + .jetty("jetty:11.0-jre17") + .warFile(warJakartaFile) + .serverVersion("7+") + .jakarta(true) + .targetJdkVersion(Opcodes.V17) + .supportedShellTypes(List.of( + ShellType.JAKARTA_SERVLET, + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_LISTENER, + ShellType.JAKARTA_HANDLER, + ShellType.CUSTOMIZER, + ShellType.JETTY_AGENT_HANDLER + )) + .testPackers(List.of(Packers.JSP)) + .unSupportedShellTools(List.of(ShellTool.AntSword)) + .probeShellTypes(List.of( + ShellType.JAKARTA_SERVLET, + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_LISTENER, + ShellType.JAKARTA_HANDLER, + ShellType.CUSTOMIZER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warJakartaFile, "/var/lib/jetty/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jettyPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Jetty; - List supportedShellTypes = List.of( - ShellType.JAKARTA_SERVLET, - ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_LISTENER, - ShellType.JAKARTA_HANDLER, - ShellType.CUSTOMIZER, - ShellType.JETTY_AGENT_HANDLER - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers, - null, List.of(ShellTool.AntSword) - ); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Jetty, "7+", shellType, shellTool, Opcodes.V17, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.JAKARTA_SERVLET, - ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_LISTENER, - ShellType.JAKARTA_HANDLER, - ShellType.CUSTOMIZER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Jetty, "7+", shellType, Opcodes.V17); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty12ee10ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty12ee10ContainerTest.java index 055f0a76..52578fab 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty12ee10ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty12ee10ContainerTest.java @@ -1,90 +1,59 @@ package com.reajason.javaweb.integration.memshell.jetty; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellTool; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; +import static com.reajason.javaweb.integration.ContainerTool.warJakartaFile; /** * @author ReaJason * @since 2024/12/7 */ -@Slf4j @Testcontainers -public class Jetty12ee10ContainerTest { - public static final String imageName = "reajason/jetty:12.0-jre21-ee10"; - static Network network = Network.newNetwork(); +public class Jetty12ee10ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig + .jetty("reajason/jetty:12.0-jre21-ee10") + .warFile(warJakartaFile) + .jakarta(true) + .serverVersion("12") + .targetJdkVersion(Opcodes.V21) + .probeTargetJdkVersion(Opcodes.V17) + .supportedShellTypes(List.of( + ShellType.JAKARTA_SERVLET, + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_LISTENER, + ShellType.JAKARTA_HANDLER, + ShellType.JETTY_AGENT_HANDLER + )) + .testPackers(List.of(Packers.Base64)) + .unSupportedShellTools(List.of(ShellTool.AntSword)) + .probeShellTypes(List.of( + ShellType.JAKARTA_SERVLET, + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_LISTENER, + ShellType.JAKARTA_HANDLER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warJakartaFile, "/var/lib/jetty/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jettyPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Jetty; - List supportedShellTypes = List.of( - ShellType.JAKARTA_SERVLET, - ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_LISTENER, - ShellType.JAKARTA_HANDLER, - ShellType.JETTY_AGENT_HANDLER - ); - List testPackers = List.of(Packers.Base64); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers, - null, List.of(ShellTool.AntSword) // AntSword not supported Jakarta - ); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Jetty, "12", shellType, shellTool, Opcodes.V21, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.JAKARTA_SERVLET, - ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_LISTENER, - ShellType.JAKARTA_HANDLER}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Jetty, "12", shellType, Opcodes.V17); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty12ee11ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty12ee11ContainerTest.java index 038ea252..15a9a106 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty12ee11ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty12ee11ContainerTest.java @@ -1,91 +1,59 @@ package com.reajason.javaweb.integration.memshell.jetty; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellTool; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; +import static com.reajason.javaweb.integration.ContainerTool.warJakartaFile; /** * @author ReaJason - * @since 2025/11/11 + * @since 2024/12/7 */ -@Slf4j @Testcontainers -public class Jetty12ee11ContainerTest { - public static final String imageName = "reajason/jetty:12.1-jre21-ee11"; - static Network network = Network.newNetwork(); +public class Jetty12ee11ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig + .jetty("reajason/jetty:12.1-jre21-ee11") + .warFile(warJakartaFile) + .jakarta(true) + .serverVersion("12") + .targetJdkVersion(Opcodes.V21) + .probeTargetJdkVersion(Opcodes.V17) + .supportedShellTypes(List.of( + ShellType.JAKARTA_SERVLET, + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_LISTENER, + ShellType.JAKARTA_HANDLER, + ShellType.JETTY_AGENT_HANDLER + )) + .testPackers(List.of(Packers.Base64)) + .unSupportedShellTools(List.of(ShellTool.AntSword)) + .probeShellTypes(List.of( + ShellType.JAKARTA_SERVLET, + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_LISTENER, + ShellType.JAKARTA_HANDLER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warJakartaFile, "/var/lib/jetty/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jettyPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Jetty; - List supportedShellTypes = List.of( - ShellType.JAKARTA_SERVLET, - ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_LISTENER, - ShellType.JAKARTA_HANDLER, - ShellType.JETTY_AGENT_HANDLER - ); - List testPackers = List.of(Packers.Base64); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers, - null, List.of(ShellTool.AntSword) // AntSword not supported Jakarta - ); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Jetty, "12", shellType, shellTool, Opcodes.V21, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.JAKARTA_SERVLET, - ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_LISTENER, - ShellType.JAKARTA_HANDLER}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Jetty, "12", shellType, Opcodes.V17); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty12ee8ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty12ee8ContainerTest.java index 354196dc..c7bf4a70 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty12ee8ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty12ee8ContainerTest.java @@ -1,88 +1,53 @@ package com.reajason.javaweb.integration.memshell.jetty; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/7 */ -@Slf4j @Testcontainers -public class Jetty12ee8ContainerTest { - public static final String imageName = "reajason/jetty:12.0-jre21-ee8"; - static Network network = Network.newNetwork(); +public class Jetty12ee8ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig + .jetty("reajason/jetty:12.0-jre21-ee8") + .serverVersion("12") + .targetJdkVersion(Opcodes.V21) + .probeTargetJdkVersion(Opcodes.V17) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.HANDLER, + ShellType.JETTY_AGENT_HANDLER + )) + .testPackers(List.of(Packers.Base64)) + .probeShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.HANDLER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/var/lib/jetty/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jettyPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Jetty; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.HANDLER, - ShellType.JETTY_AGENT_HANDLER - ); - List testPackers = List.of(Packers.Base64); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Jetty, "12", shellType, shellTool, Opcodes.V21, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.HANDLER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Jetty, "12", shellType, Opcodes.V17); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty12ee9ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty12ee9ContainerTest.java index c5253b22..26c6fde2 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty12ee9ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty12ee9ContainerTest.java @@ -1,90 +1,59 @@ package com.reajason.javaweb.integration.memshell.jetty; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellTool; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; +import static com.reajason.javaweb.integration.ContainerTool.warJakartaFile; /** * @author ReaJason * @since 2024/12/7 */ -@Slf4j @Testcontainers -public class Jetty12ee9ContainerTest { - public static final String imageName = "reajason/jetty:12.0-jre21-ee9"; - static Network network = Network.newNetwork(); +public class Jetty12ee9ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig + .jetty("reajason/jetty:12.0-jre21-ee9") + .warFile(warJakartaFile) + .jakarta(true) + .serverVersion("12") + .targetJdkVersion(Opcodes.V21) + .probeTargetJdkVersion(Opcodes.V17) + .supportedShellTypes(List.of( + ShellType.JAKARTA_SERVLET, + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_LISTENER, + ShellType.JAKARTA_HANDLER, + ShellType.JETTY_AGENT_HANDLER + )) + .testPackers(List.of(Packers.Base64)) + .unSupportedShellTools(List.of(ShellTool.AntSword)) + .probeShellTypes(List.of( + ShellType.JAKARTA_SERVLET, + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_LISTENER, + ShellType.JAKARTA_HANDLER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warJakartaFile, "/var/lib/jetty/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jettyPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Jetty; - List supportedShellTypes = List.of( - ShellType.JAKARTA_SERVLET, - ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_LISTENER, - ShellType.JAKARTA_HANDLER, - ShellType.JETTY_AGENT_HANDLER - ); - List testPackers = List.of(Packers.Base64); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers, - null, List.of(ShellTool.AntSword) // AntSword not supported Jakarta - ); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Jetty, "12", shellType, shellTool, Opcodes.V21, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.JAKARTA_SERVLET, - ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_LISTENER, - ShellType.JAKARTA_HANDLER}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Jetty, "12", shellType, Opcodes.V17); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty61ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty61ContainerTest.java index 0e89d877..fbe40903 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty61ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty61ContainerTest.java @@ -1,88 +1,52 @@ package com.reajason.javaweb.integration.memshell.jetty; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/7 */ -@Slf4j @Testcontainers -public class Jetty61ContainerTest { - public static final String imageName = "reajason/jetty:6.1-jdk6"; - static Network network = Network.newNetwork(); +public class Jetty61ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig + .jetty("reajason/jetty:6.1-jdk6") + .serverVersion("6") + .targetJdkVersion(Opcodes.V1_6) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.HANDLER, + ShellType.JETTY_AGENT_HANDLER + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.HANDLER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/usr/local/jetty/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jettyPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Jetty; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.HANDLER, - ShellType.JETTY_AGENT_HANDLER - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Jetty, "6", shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.HANDLER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Jetty, "6", shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty75ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty75ContainerTest.java index 409c6f0e..b4a7a913 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty75ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty75ContainerTest.java @@ -1,88 +1,53 @@ package com.reajason.javaweb.integration.memshell.jetty; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/7 */ -@Slf4j @Testcontainers -public class Jetty75ContainerTest { - public static final String imageName = "reajason/jetty:7.5.4-jdk6"; - static Network network = Network.newNetwork(); +public class Jetty75ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig + .jetty("reajason/jetty:7.5.4-jdk6") + .warDeployPath("/usr/local/jetty/webapps/app.war") + .serverVersion("7+") + .targetJdkVersion(Opcodes.V1_6) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.HANDLER, + ShellType.JETTY_AGENT_HANDLER + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.HANDLER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/usr/local/jetty/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jettyPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Jetty; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.HANDLER, - ShellType.JETTY_AGENT_HANDLER - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info("logs: {}", logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Jetty,"7+", shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.HANDLER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Jetty, "7+", shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty76ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty76ContainerTest.java index ffe45914..91dd15e0 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty76ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty76ContainerTest.java @@ -1,87 +1,53 @@ package com.reajason.javaweb.integration.memshell.jetty; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/7 */ -@Slf4j @Testcontainers -public class Jetty76ContainerTest { - public static final String imageName = "reajason/jetty:7.6-jdk6"; - static Network network = Network.newNetwork(); +public class Jetty76ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig + .jetty("reajason/jetty:7.6-jdk6") + .warDeployPath("/usr/local/jetty/webapps/app.war") + .serverVersion("7+") + .targetJdkVersion(Opcodes.V1_6) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.HANDLER, + ShellType.JETTY_AGENT_HANDLER + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.HANDLER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/usr/local/jetty/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jettyPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Jetty; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.HANDLER, - ShellType.JETTY_AGENT_HANDLER - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Jetty, "7+", shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.HANDLER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Jetty, "7+", shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty81ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty81ContainerTest.java index 6a60ebab..57f4caa1 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty81ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty81ContainerTest.java @@ -1,88 +1,53 @@ package com.reajason.javaweb.integration.memshell.jetty; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/7 */ -@Slf4j @Testcontainers -public class Jetty81ContainerTest { - public static final String imageName = "reajason/jetty:8.1-jdk7"; - static Network network = Network.newNetwork(); +public class Jetty81ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig + .jetty("reajason/jetty:8.1-jdk7") + .warDeployPath("/usr/local/jetty/webapps/app.war") + .serverVersion("7+") + .targetJdkVersion(Opcodes.V1_6) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.HANDLER, + ShellType.JETTY_AGENT_HANDLER + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.HANDLER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/usr/local/jetty/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jettyPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Jetty; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.HANDLER, - ShellType.JETTY_AGENT_HANDLER - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info("logs: {}", logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Jetty, "7+", shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.HANDLER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Jetty, "7+", shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty92ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty92ContainerTest.java index 12c16a7c..7654e231 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty92ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty92ContainerTest.java @@ -1,91 +1,54 @@ package com.reajason.javaweb.integration.memshell.jetty; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/7 */ -@Slf4j @Testcontainers -public class Jetty92ContainerTest { +public class Jetty92ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig + .jetty("jetty:9.2-jre7") + .serverVersion("7+") + .targetJdkVersion(Opcodes.V1_6) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.HANDLER, + ShellType.CUSTOMIZER, + ShellType.JETTY_AGENT_HANDLER + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.HANDLER, + ShellType.CUSTOMIZER + )) + .build(); - public static final String imageName = "jetty:9.2-jre7"; - static Network network = Network.newNetwork(); + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/var/lib/jetty/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jettyPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Jetty; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.HANDLER, - ShellType.CUSTOMIZER, - ShellType.JETTY_AGENT_HANDLER - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Jetty, "7+", shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.HANDLER, - ShellType.CUSTOMIZER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Jetty, "7+", shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty93ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty93ContainerTest.java index 670aead6..0d693d76 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty93ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty93ContainerTest.java @@ -1,90 +1,54 @@ package com.reajason.javaweb.integration.memshell.jetty; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/7 */ -@Slf4j @Testcontainers -public class Jetty93ContainerTest { - public static final String imageName = "reajason/jetty:9.3"; - static Network network = Network.newNetwork(); +public class Jetty93ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig + .jetty("reajason/jetty:9.3") + .serverVersion("7+") + .targetJdkVersion(Opcodes.V1_6) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.HANDLER, + ShellType.CUSTOMIZER, + ShellType.JETTY_AGENT_HANDLER + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.HANDLER, + ShellType.CUSTOMIZER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/var/lib/jetty/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jettyPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Jetty; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.HANDLER, - ShellType.CUSTOMIZER, - ShellType.JETTY_AGENT_HANDLER - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Jetty, "7+", shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.HANDLER, - ShellType.CUSTOMIZER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Jetty, "7+", shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty94ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty94ContainerTest.java index e26391c8..c225a950 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty94ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/jetty/Jetty94ContainerTest.java @@ -1,90 +1,54 @@ package com.reajason.javaweb.integration.memshell.jetty; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/7 */ -@Slf4j @Testcontainers -public class Jetty94ContainerTest { - public static final String imageName = "jetty:9.4-jre8"; - static Network network = Network.newNetwork(); +public class Jetty94ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig + .jetty("jetty:9.4-jre8") + .serverVersion("7+") + .targetJdkVersion(Opcodes.V1_6) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.HANDLER, + ShellType.CUSTOMIZER, + ShellType.JETTY_AGENT_HANDLER + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.HANDLER, + ShellType.CUSTOMIZER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/var/lib/jetty/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jettyPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Jetty; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.HANDLER, - ShellType.CUSTOMIZER, - ShellType.JETTY_AGENT_HANDLER - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Jetty, "7+", shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.HANDLER, - ShellType.CUSTOMIZER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Jetty, "7+", shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/payara/Payara5201ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/payara/Payara5201ContainerTest.java index a2a4d4e2..52b88a5d 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/payara/Payara5201ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/payara/Payara5201ContainerTest.java @@ -1,93 +1,53 @@ package com.reajason.javaweb.integration.memshell.payara; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/12 */ -@Slf4j @Testcontainers -public class Payara5201ContainerTest { - public static final String imageName = "reajason/payara:5.201"; - static Network network = Network.newNetwork(); +public class Payara5201ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.glassFish( + "reajason/payara:5.201", + "/usr/local/payara5/glassfish/domains/domain1/autodeploy/app.war") + .targetJdkVersion(Opcodes.V1_6) + .waitStrategy(Wait.forLogMessage(".*JMXService.*", 1)) + .supportedShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.AGENT_FILTER_CHAIN, + ShellType.CATALINA_AGENT_CONTEXT_VALVE + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.VALVE + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public static final GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/usr/local/payara5/glassfish/domains/domain1/autodeploy/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(glassfishPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forLogMessage(".*JMXService.*", 1)) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.GlassFish; - List supportedShellTypes = List.of( - ShellType.FILTER, - ShellType.LISTENER, - ShellType.VALVE, - ShellType.AGENT_FILTER_CHAIN, - ShellType.CATALINA_AGENT_CONTEXT_VALVE - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @BeforeAll - static void setup() { - container.waitingFor(Wait.forHttp("/app")); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.GlassFish, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.FILTER, - ShellType.LISTENER, - ShellType.VALVE,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.GlassFish, shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/payara/Payara520225ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/payara/Payara520225ContainerTest.java index ff983028..eb5361ee 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/payara/Payara520225ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/payara/Payara520225ContainerTest.java @@ -1,93 +1,53 @@ package com.reajason.javaweb.integration.memshell.payara; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/12 */ -@Slf4j @Testcontainers -public class Payara520225ContainerTest { - public static final String imageName = "reajason/payara:5.2022.5"; - static Network network = Network.newNetwork(); +public class Payara520225ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.glassFish( + "reajason/payara:5.2022.5", + "/usr/local/payara5/glassfish/domains/domain1/autodeploy/app.war") + .targetJdkVersion(Opcodes.V1_6) + .waitStrategy(Wait.forLogMessage(".*JMXService.*", 1)) + .supportedShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.AGENT_FILTER_CHAIN, + ShellType.CATALINA_AGENT_CONTEXT_VALVE + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.VALVE + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public static final GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/usr/local/payara5/glassfish/domains/domain1/autodeploy/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(glassfishPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forLogMessage(".*JMXService.*", 1)) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.GlassFish; - List supportedShellTypes = List.of( - ShellType.FILTER, - ShellType.LISTENER, - ShellType.VALVE, - ShellType.AGENT_FILTER_CHAIN, - ShellType.CATALINA_AGENT_CONTEXT_VALVE - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @BeforeAll - static void setup() { - container.waitingFor(Wait.forHttp("/app")); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.GlassFish, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.FILTER, - ShellType.LISTENER, - ShellType.VALVE,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.GlassFish, shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/payara/Payara620222ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/payara/Payara620222ContainerTest.java index dcfff81b..95fd6b6c 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/payara/Payara620222ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/payara/Payara620222ContainerTest.java @@ -1,92 +1,60 @@ package com.reajason.javaweb.integration.memshell.payara; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellTool; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; +import static com.reajason.javaweb.integration.ContainerTool.warJakartaFile; /** * @author ReaJason * @since 2024/12/12 */ -@Slf4j @Testcontainers -public class Payara620222ContainerTest { - public static final String imageName = "reajason/payara:6.2022.2-jdk11"; - static Network network = Network.newNetwork(); +public class Payara620222ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.glassFish( + "reajason/payara:6.2022.2-jdk11", + "/usr/local/payara6/glassfish/domains/domain1/autodeploy/app.war") + .warFile(warJakartaFile) + .jakarta(true) + .targetJdkVersion(Opcodes.V11) + .waitStrategy(Wait.forLogMessage(".*JMXService.*", 1)) + .assertLogs(false) + .supportedShellTypes(List.of( + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_LISTENER, + ShellType.JAKARTA_VALVE, + ShellType.AGENT_FILTER_CHAIN, + ShellType.CATALINA_AGENT_CONTEXT_VALVE + )) + .testPackers(List.of(Packers.JSP)) + .unSupportedShellTools(List.of(ShellTool.AntSword)) + .probeShellTypes(List.of( + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_LISTENER, + ShellType.JAKARTA_VALVE + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public static final GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warJakartaFile, "/usr/local/payara6/glassfish/domains/domain1/autodeploy/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(glassfishPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forLogMessage(".*JMXService.*", 1)) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.GlassFish; - List supportedShellTypes = List.of( - ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_LISTENER, - ShellType.JAKARTA_VALVE, - ShellType.AGENT_FILTER_CHAIN, - ShellType.CATALINA_AGENT_CONTEXT_VALVE - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers, null, List.of(ShellTool.AntSword)); - } - - @BeforeAll - static void setup() { - container.waitingFor(Wait.forHttp("/app/test")); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); -// assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.GlassFish, shellType, shellTool, Opcodes.V11, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_LISTENER, - ShellType.JAKARTA_VALVE,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.GlassFish, shellType, Opcodes.V11); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/resin/Resin3116ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/resin/Resin3116ContainerTest.java index 881ca726..55f40223 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/resin/Resin3116ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/resin/Resin3116ContainerTest.java @@ -1,87 +1,49 @@ package com.reajason.javaweb.integration.memshell.resin; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.SneakyThrows; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/4 */ -@Slf4j @Testcontainers -public class Resin3116ContainerTest { - public static final String imageName = "reajason/resin:3.1.16"; - static Network network = Network.newNetwork(); +public class Resin3116ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.resin( + "reajason/resin:3.1.16", + "/usr/local/resin3/webapps/app.war") + .targetJdkVersion(Opcodes.V1_6) + .logDelayMillis(1000L) + .supportedShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.AGENT_FILTER_CHAIN + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/usr/local/resin3/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(resinPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Resin; - List supportedShellTypes = List.of( - ShellType.FILTER, - ShellType.LISTENER, - ShellType.AGENT_FILTER_CHAIN - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } - - @AfterAll - @SneakyThrows - static void tearDown() { - Thread.sleep(1000); - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Resin, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.FILTER, - ShellType.LISTENER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Resin, shellType, Opcodes.V1_6); - } -} \ No newline at end of file +} diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/resin/Resin318ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/resin/Resin318ContainerTest.java index a410aeb4..89b4daab 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/resin/Resin318ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/resin/Resin318ContainerTest.java @@ -1,84 +1,48 @@ package com.reajason.javaweb.integration.memshell.resin; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/4 */ -@Slf4j @Testcontainers -public class Resin318ContainerTest { - public static final String imageName = "reajason/resin:3.1.8-jdk7"; - static Network network = Network.newNetwork(); +public class Resin318ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.resin( + "reajason/resin:3.1.8-jdk7", + "/usr/local/resin3/webapps/app.war") + .targetJdkVersion(Opcodes.V1_6) + .supportedShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.AGENT_FILTER_CHAIN + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/usr/local/resin3/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(resinPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Resin; - List supportedShellTypes = List.of( - ShellType.FILTER, - ShellType.LISTENER, - ShellType.AGENT_FILTER_CHAIN - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Resin, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.FILTER, - ShellType.LISTENER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Resin, shellType, Opcodes.V1_6); - } -} \ No newline at end of file +} diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/resin/Resin4058ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/resin/Resin4058ContainerTest.java index dfa14406..5c7fc192 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/resin/Resin4058ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/resin/Resin4058ContainerTest.java @@ -1,84 +1,48 @@ package com.reajason.javaweb.integration.memshell.resin; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/4 */ -@Slf4j @Testcontainers -public class Resin4058ContainerTest { - public static final String imageName = "reajason/resin:4.0.58"; - static Network network = Network.newNetwork(); +public class Resin4058ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.resin( + "reajason/resin:4.0.58", + "/usr/local/resin4/webapps/app.war") + .targetJdkVersion(Opcodes.V1_6) + .supportedShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.AGENT_FILTER_CHAIN + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/usr/local/resin4/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(resinPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Resin; - List supportedShellTypes = List.of( - ShellType.FILTER, - ShellType.LISTENER, - ShellType.AGENT_FILTER_CHAIN - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Resin, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.FILTER, - ShellType.LISTENER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Resin, shellType, Opcodes.V1_6); - } -} \ No newline at end of file +} diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/resin/Resin4067ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/resin/Resin4067ContainerTest.java index e3d508b0..305f137a 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/resin/Resin4067ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/resin/Resin4067ContainerTest.java @@ -1,84 +1,49 @@ package com.reajason.javaweb.integration.memshell.resin; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/4 */ -@Slf4j @Testcontainers -public class Resin4067ContainerTest { - public static final String imageName = "reajason/resin:4.0.67-jdk11"; - static Network network = Network.newNetwork(); +public class Resin4067ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.resin( + "reajason/resin:4.0.67-jdk11", + "/usr/local/resin4/webapps/app.war") + .targetJdkVersion(Opcodes.V11) + .probeTargetJdkVersion(Opcodes.V1_6) + .supportedShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER, + ShellType.AGENT_FILTER_CHAIN + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.FILTER, + ShellType.LISTENER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/usr/local/resin4/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(resinPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Resin; - List supportedShellTypes = List.of( - ShellType.FILTER, - ShellType.LISTENER, - ShellType.AGENT_FILTER_CHAIN - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Resin, shellType, shellTool, Opcodes.V11, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.FILTER, - ShellType.LISTENER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Resin, shellType, Opcodes.V1_6); - } -} \ No newline at end of file +} diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebflux/SpringBoot2WebFluxContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebflux/SpringBoot2WebFluxContainerTest.java index 2f284f14..68a2092f 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebflux/SpringBoot2WebFluxContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebflux/SpringBoot2WebFluxContainerTest.java @@ -1,78 +1,54 @@ package com.reajason.javaweb.integration.memshell.springwebflux; import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; +import com.reajason.javaweb.integration.ContainerTool; +import com.reajason.javaweb.integration.VulTool; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.neoGeorgDockerfile; -import static com.reajason.javaweb.integration.ContainerTool.springBoot2WebfluxDockerfile; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/22 */ @Testcontainers -@Slf4j -public class SpringBoot2WebFluxContainerTest { - public static final String imageName = "springboot2-webflux"; +public class SpringBoot2WebFluxContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.builder() + .imageName("eclipse-temurin:8u472-b08-jdk") + .jarFile(ContainerTool.springBoot2WebfluxJarFile) + .jarDeployPath("/app/app.jar") + .command("java -jar /app/app.jar") + .server(Server.SpringWebFlux) + .targetJdkVersion(Opcodes.V1_8) + .enableJspPackerTest(false) + .contextPath("") + .healthCheckPath("/test") + .jattachFile(null) + .supportedShellTypes(List.of( + ShellType.SPRING_WEBFLUX_WEB_FILTER, + ShellType.SPRING_WEBFLUX_HANDLER_METHOD, + ShellType.NETTY_HANDLER + )) + .testPackers(List.of(Packers.Base64)) + .build(); - static Network network = Network.newNetwork(); + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(springBoot2WebfluxDockerfile)) - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/test")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.SpringWebFlux; - List supportedShellTypes = List.of(ShellType.SPRING_WEBFLUX_WEB_FILTER, ShellType.SPRING_WEBFLUX_HANDLER_METHOD, ShellType.NETTY_HANDLER); - List testPackers = List.of(Packers.Base64); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info("container stopped, logs is : {}", logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.SpringWebFlux, shellType, shellTool, Opcodes.V1_8, packer, container, python); - } - - public static String getUrl(GenericContainer container) { - String host = container.getHost(); - int port = container.getMappedPort(8080); - String url = "http://" + host + ":" + port; - log.info("container started, app url is : {}", url); - return url; + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebflux/SpringBoot3WebFluxContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebflux/SpringBoot3WebFluxContainerTest.java index e84ff663..c66817af 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebflux/SpringBoot3WebFluxContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebflux/SpringBoot3WebFluxContainerTest.java @@ -1,76 +1,53 @@ package com.reajason.javaweb.integration.memshell.springwebflux; import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; +import com.reajason.javaweb.integration.ContainerTool; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.neoGeorgDockerfile; -import static com.reajason.javaweb.integration.ContainerTool.springBoot3WebfluxDockerfile; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/22 */ @Testcontainers -@Slf4j -public class SpringBoot3WebFluxContainerTest { - public static final String imageName = "springboot3-webflux"; - static Network network = Network.newNetwork(); +public class SpringBoot3WebFluxContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.builder() + .imageName("eclipse-temurin:17.0.17_10-jdk") + .jarFile(ContainerTool.springBoot3WebfluxJarFile) + .jarDeployPath("/app/app.jar") + .command("java -jar /app/app.jar") + .server(Server.SpringWebFlux) + .targetJdkVersion(Opcodes.V17) + .enableJspPackerTest(false) + .contextPath("") + .healthCheckPath("/test") + .jattachFile(null) + .supportedShellTypes(List.of( + ShellType.SPRING_WEBFLUX_WEB_FILTER, + ShellType.SPRING_WEBFLUX_HANDLER_METHOD, + ShellType.NETTY_HANDLER + )) + .testPackers(List.of(Packers.Base64)) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(springBoot3WebfluxDockerfile)) - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/test")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.SpringWebFlux; - List supportedShellTypes = List.of(ShellType.SPRING_WEBFLUX_WEB_FILTER, ShellType.SPRING_WEBFLUX_HANDLER_METHOD, ShellType.NETTY_HANDLER); - List testPackers = List.of(Packers.Base64); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.SpringWebFlux, shellType, shellTool, Opcodes.V17, packer, container, python); - } - - public static String getUrl(GenericContainer container) { - String host = container.getHost(); - int port = container.getMappedPort(8080); - String url = "http://" + host + ":" + port; - log.info("container started, app url is : {}", url); - return url; + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot1ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot1ContainerTest.java index fe047fa6..4be86a53 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot1ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot1ContainerTest.java @@ -1,92 +1,58 @@ package com.reajason.javaweb.integration.memshell.springwebmvc; import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; +import com.reajason.javaweb.integration.ContainerTool; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/22 */ @Testcontainers -@Slf4j -public class SpringBoot1ContainerTest { - public static final String imageName = "springboot1"; - static Network network = Network.newNetwork(); +public class SpringBoot1ContainerTest extends AbstractContainerTest { + + private static final ContainerTestConfig CONFIG = ContainerTestConfig.builder() + .imageName("eclipse-temurin:8u472-b08-jdk") + .jarFile(ContainerTool.springBoot1JarFile) + .jarDeployPath("/app/app.jar") + .command("java -jar /app/app.jar") + .server(Server.SpringWebMvc) + .pidScript(ContainerTool.springbootPid) + .targetJdkVersion(Opcodes.V1_8) + .enableJspPackerTest(false) + .contextPath("") + .healthCheckPath("/test") + .supportedShellTypes(List.of( + ShellType.SPRING_WEBMVC_INTERCEPTOR, + ShellType.SPRING_WEBMVC_CONTROLLER_HANDLER, + ShellType.SPRING_WEBMVC_AGENT_FRAMEWORK_SERVLET + )) + .testPackers(List.of(Packers.SpEL)) + .probeShellTypes(List.of( + ShellType.SPRING_WEBMVC_INTERCEPTOR, + ShellType.SPRING_WEBMVC_CONTROLLER_HANDLER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(springBoot1Dockerfile)) - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(springbootPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/test")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.SpringWebMvc; - List supportedShellTypes = List.of( - ShellType.SPRING_WEBMVC_INTERCEPTOR, - ShellType.SPRING_WEBMVC_CONTROLLER_HANDLER, - ShellType.SPRING_WEBMVC_AGENT_FRAMEWORK_SERVLET - ); - List testPackers = List.of(Packers.SpEL); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.SpringWebMvc, shellType, shellTool, Opcodes.V1_8, packer, container, python); - } - - public static String getUrl(GenericContainer container) { - String host = container.getHost(); - int port = container.getMappedPort(8080); - String url = "http://" + host + ":" + port; - log.info("container started, app url is : {}", url); - return url; - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.SPRING_WEBMVC_INTERCEPTOR, - ShellType.SPRING_WEBMVC_CONTROLLER_HANDLER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.SpringWebMvc, shellType, Opcodes.V1_8); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot2ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot2ContainerTest.java index 84520b86..3dc38c2c 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot2ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot2ContainerTest.java @@ -1,114 +1,85 @@ package com.reajason.javaweb.integration.memshell.springwebmvc; import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; +import com.reajason.javaweb.integration.ContainerTool; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; import java.util.stream.Stream; -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; - /** * @author ReaJason * @since 2024/12/22 */ @Testcontainers -@Slf4j -public class SpringBoot2ContainerTest { - public static final String imageName = "springboot2"; +public class SpringBoot2ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.builder() + .imageName("eclipse-temurin:8u472-b08-jdk") + .jarFile(ContainerTool.springBoot2JarFile) + .jarDeployPath("/app/app.jar") + .command("java -jar /app/app.jar") + .server(Server.SpringWebMvc) + .pidScript(ContainerTool.javaPid) + .enableJspPackerTest(false) + .targetJdkVersion(Opcodes.V1_8) + .contextPath("") + .healthCheckPath("/test") + .supportedShellTypes(List.of( + ShellType.SPRING_WEBMVC_INTERCEPTOR, + ShellType.SPRING_WEBMVC_CONTROLLER_HANDLER, + ShellType.SPRING_WEBMVC_AGENT_FRAMEWORK_SERVLET + )) + .testPackers(List.of(Packers.H2JS)) + .probeShellTypes(List.of( + ShellType.SPRING_WEBMVC_INTERCEPTOR, + ShellType.SPRING_WEBMVC_CONTROLLER_HANDLER + )) + .build(); - static Network network = Network.newNetwork(); + private static final ContainerTestConfig TOMCAT_CONFIG = ContainerTestConfig.builder() + .imageName("springboot-2") + .server(Server.Tomcat) + .targetJdkVersion(Opcodes.V1_8) + .supportedShellTypes(List.of( + ShellType.FILTER, + ShellType.VALVE, + ShellType.WEBSOCKET, + ShellType.AGENT_FILTER_CHAIN, + ShellType.CATALINA_AGENT_CONTEXT_VALVE + )) + .testPackers(List.of(Packers.H2JS)) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); @Container - public final static GenericContainer container = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(springBoot2Dockerfile)) - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(javaPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/test")) - .withExposedPorts(8080); - - static Stream casesProvider() { - String server = Server.SpringWebMvc; - List supportedShellTypes = List.of( - ShellType.SPRING_WEBMVC_INTERCEPTOR, - ShellType.SPRING_WEBMVC_CONTROLLER_HANDLER, - ShellType.SPRING_WEBMVC_AGENT_FRAMEWORK_SERVLET - ); - List testPackers = List.of(Packers.H2JS); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.SpringWebMvc, shellType, shellTool, Opcodes.V1_8, packer, container, python); - } - - public static String getUrl(GenericContainer container) { - String host = container.getHost(); - int port = container.getMappedPort(8080); - String url = "http://" + host + ":" + port; - log.info("container started, app url is : {}", url); - return url; - } + public static final GenericContainer container = buildContainer(CONFIG, network); static Stream tomcatCasesProvider() { - String server = Server.Tomcat; - List supportedShellTypes = List.of( - ShellType.FILTER, -// ShellType.LISTENER, - ShellType.VALVE, - ShellType.WEBSOCKET, - ShellType.AGENT_FILTER_CHAIN, - ShellType.CATALINA_AGENT_CONTEXT_VALVE - ); - List testPackers = List.of(Packers.H2JS); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); + return generateTestCases(TOMCAT_CONFIG); } @ParameterizedTest(name = "{0}|{1}{2}|{3}") @MethodSource("tomcatCasesProvider") void testTomcat(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Tomcat, shellType, shellTool, Opcodes.V1_8, packer, container, python); + runShellInject(TOMCAT_CONFIG, shellType, shellTool, packer); } - @ParameterizedTest - @ValueSource(strings = {ShellType.SPRING_WEBMVC_INTERCEPTOR, - ShellType.SPRING_WEBMVC_CONTROLLER_HANDLER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.SpringWebMvc, shellType, Opcodes.V1_8); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot2JettyContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot2JettyContainerTest.java index a197edc1..5b58017b 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot2JettyContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot2JettyContainerTest.java @@ -1,104 +1,82 @@ package com.reajason.javaweb.integration.memshell.springwebmvc; import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; +import com.reajason.javaweb.integration.ContainerTool; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; import java.util.stream.Stream; -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; - /** * @author ReaJason * @since 2024/12/22 */ @Testcontainers -@Slf4j -public class SpringBoot2JettyContainerTest { - public static final String imageName = "springboot2-jetty"; +public class SpringBoot2JettyContainerTest extends AbstractContainerTest { - static Network network = Network.newNetwork(); + private static final ContainerTestConfig CONFIG = ContainerTestConfig.builder() + .imageName("eclipse-temurin:8u472-b08-jdk") + .jarFile(ContainerTool.springBoot2JettyJarFile) + .jarDeployPath("/app/app.jar") + .command("java -jar /app/app.jar") + .server(Server.SpringWebMvc) + .pidScript(ContainerTool.springbootPid) + .enableJspPackerTest(false) + .targetJdkVersion(Opcodes.V1_8) + .contextPath("") + .healthCheckPath("/test") + .supportedShellTypes(List.of( + ShellType.SPRING_WEBMVC_INTERCEPTOR, + ShellType.SPRING_WEBMVC_CONTROLLER_HANDLER, + ShellType.SPRING_WEBMVC_AGENT_FRAMEWORK_SERVLET + )) + .testPackers(List.of(Packers.SpEL)) + .build(); + + private static final ContainerTestConfig JETTY_CONFIG = ContainerTestConfig.builder() + .imageName("springboot2-jetty") + .server(Server.Jetty) + .serverVersion("7+") + .targetJdkVersion(Opcodes.V1_8) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.HANDLER, + ShellType.CUSTOMIZER, + ShellType.JETTY_AGENT_HANDLER + )) + .testPackers(List.of(Packers.SpEL)) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); @Container - public final static GenericContainer container = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(springBoot2JettyDockerfile)) - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(springbootPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/test")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.SpringWebMvc; - List supportedShellTypes = List.of( - ShellType.SPRING_WEBMVC_INTERCEPTOR, - ShellType.SPRING_WEBMVC_CONTROLLER_HANDLER, - ShellType.SPRING_WEBMVC_AGENT_FRAMEWORK_SERVLET - ); - List testPackers = List.of(Packers.ScriptEngine, Packers.SpEL, Packers.Base64); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.SpringWebMvc, shellType, shellTool, Opcodes.V1_8, packer, container, python); - } - - public static String getUrl(GenericContainer container) { - String host = container.getHost(); - int port = container.getMappedPort(8080); - String url = "http://" + host + ":" + port; - log.info("container started, app url is : {}", url); - return url; - } - - static Stream jettyCasesProvider() { - String server = Server.Jetty; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.HANDLER, - ShellType.CUSTOMIZER, -// ShellType.LISTENER, - ShellType.JETTY_AGENT_HANDLER - ); - List testPackers = List.of(Packers.SpEL); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); + static Stream jettyCasesProvider() { + return generateTestCases(JETTY_CONFIG); } @ParameterizedTest(name = "{0}|{1}{2}|{3}") @MethodSource("jettyCasesProvider") void testJetty(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Jetty, "7+", shellType, shellTool, Opcodes.V1_8, packer, container, python); + runShellInject(JETTY_CONFIG, shellType, shellTool, packer); + } + + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot2UndertowContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot2UndertowContainerTest.java index eb11f68d..823c5dfb 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot2UndertowContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot2UndertowContainerTest.java @@ -1,102 +1,78 @@ package com.reajason.javaweb.integration.memshell.springwebmvc; import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; +import com.reajason.javaweb.integration.ContainerTool; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; import java.util.stream.Stream; -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; - /** * @author ReaJason * @since 2024/12/22 */ @Testcontainers -@Slf4j -public class SpringBoot2UndertowContainerTest { - public static final String imageName = "springboot2-undertow"; +public class SpringBoot2UndertowContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.builder() + .imageName("eclipse-temurin:8u472-b08-jdk") + .jarFile(ContainerTool.springBoot2UndertowJarFile) + .jarDeployPath("/app/app.jar") + .command("java -jar /app/app.jar") + .server(Server.SpringWebMvc) + .pidScript(ContainerTool.springbootPid) + .enableJspPackerTest(false) + .targetJdkVersion(Opcodes.V1_8) + .contextPath("") + .healthCheckPath("/test") + .supportedShellTypes(List.of( + ShellType.SPRING_WEBMVC_INTERCEPTOR, + ShellType.SPRING_WEBMVC_CONTROLLER_HANDLER, + ShellType.SPRING_WEBMVC_AGENT_FRAMEWORK_SERVLET + )) + .testPackers(List.of(Packers.ScriptEngine, Packers.SpEL, Packers.Base64)) + .build(); - static Network network = Network.newNetwork(); + private static final ContainerTestConfig UNDERTOW_CONFIG = ContainerTestConfig.builder() + .imageName("springboot2-undertow") + .server(Server.Undertow) + .targetJdkVersion(Opcodes.V1_8) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.UNDERTOW_AGENT_SERVLET_HANDLER + )) + .testPackers(List.of(Packers.SpEL)) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); @Container - public final static GenericContainer container = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(springBoot2UndertowDockerfile)) - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(springbootPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/test")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.SpringWebMvc; - List supportedShellTypes = List.of( - ShellType.SPRING_WEBMVC_INTERCEPTOR, - ShellType.SPRING_WEBMVC_CONTROLLER_HANDLER, - ShellType.SPRING_WEBMVC_AGENT_FRAMEWORK_SERVLET - ); - List testPackers = List.of(Packers.ScriptEngine, Packers.SpEL, Packers.Base64); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.SpringWebMvc, shellType, shellTool, Opcodes.V1_8, packer, container, python); - } - - public static String getUrl(GenericContainer container) { - String host = container.getHost(); - int port = container.getMappedPort(8080); - String url = "http://" + host + ":" + port; - log.info("container started, app url is : {}", url); - return url; - } - - static Stream undertowCasesProvider() { - String server = Server.Undertow; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, -// ShellType.LISTENER, - ShellType.UNDERTOW_AGENT_SERVLET_HANDLER - ); - List testPackers = List.of(Packers.SpEL); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); + static Stream undertowCasesProvider() { + return generateTestCases(UNDERTOW_CONFIG); } @ParameterizedTest(name = "{0}|{1}{2}|{3}") @MethodSource("undertowCasesProvider") - void testJetty(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Undertow, shellType, shellTool, Opcodes.V1_8, packer, container, python); + void testUndertow(String imageName, String shellType, String shellTool, Packers packer) { + runShellInject(UNDERTOW_CONFIG, shellType, shellTool, packer); + } + + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot2WarContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot2WarContainerTest.java index 23330a43..44e3ef3c 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot2WarContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot2WarContainerTest.java @@ -1,93 +1,79 @@ package com.reajason.javaweb.integration.memshell.springwebmvc; import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; +import com.reajason.javaweb.integration.ContainerTool; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; import java.util.stream.Stream; -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; - /** * @author ReaJason * @since 2024/12/22 */ @Testcontainers -@Slf4j -public class SpringBoot2WarContainerTest { +public class SpringBoot2WarContainerTest extends AbstractContainerTest { public static final String imageName = "tomcat:8-jre8"; - static Network network = Network.newNetwork(); + + private static final ContainerTestConfig CONFIG = ContainerTestConfig.builder() + .imageName(imageName) + .server(Server.SpringWebMvc) + .warFile(ContainerTool.springBoot2WarFile) + .warDeployPath("/usr/local/tomcat/webapps/app.war") + .pidScript(ContainerTool.tomcatPid) + .enableJspPackerTest(false) + .targetJdkVersion(Opcodes.V1_8) + .supportedShellTypes(List.of( + ShellType.SPRING_WEBMVC_INTERCEPTOR, + ShellType.SPRING_WEBMVC_CONTROLLER_HANDLER + )) + .testPackers(List.of(Packers.SpEL)) + .build(); + + private static final ContainerTestConfig TOMCAT_CONFIG = ContainerTestConfig.builder() + .imageName(imageName) + .server(Server.Tomcat) + .targetJdkVersion(Opcodes.V1_8) + .supportedShellTypes(List.of( + ShellType.FILTER, + ShellType.VALVE, + ShellType.WEBSOCKET, + ShellType.AGENT_FILTER_CHAIN, + ShellType.CATALINA_AGENT_CONTEXT_VALVE + )) + .testPackers(List.of(Packers.SpEL)) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(springBoot2WarFile, "/usr/local/tomcat/webapps/app.war") - .withNetwork(network) - .withNetworkAliases("app") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(tomcatPid, "/fetch_pid.sh") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); - - static Stream casesProvider() { - String server = Server.SpringWebMvc; - List supportedShellTypes = List.of( - ShellType.SPRING_WEBMVC_INTERCEPTOR, - ShellType.SPRING_WEBMVC_CONTROLLER_HANDLER -// ShellType.SPRING_WEBMVC_AGENT_FRAMEWORK_SERVLET // TODO: 这个地方会报奇怪的错误,需要排查 - ); - List testPackers = List.of(Packers.ScriptEngine, Packers.SpEL, Packers.Base64); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.SpringWebMvc, shellType, shellTool, Opcodes.V1_8, packer, container, python); - } + public static final GenericContainer container = buildContainer(CONFIG, network); static Stream tomcatCasesProvider() { - String server = Server.Tomcat; - List supportedShellTypes = List.of( - ShellType.FILTER, -// ShellType.LISTENER, - ShellType.VALVE, - ShellType.WEBSOCKET, - ShellType.AGENT_FILTER_CHAIN, - ShellType.CATALINA_AGENT_CONTEXT_VALVE - ); - List testPackers = List.of(Packers.SpEL); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); + return generateTestCases(TOMCAT_CONFIG); } @ParameterizedTest(name = "{0}|{1}{2}|{3}") @MethodSource("tomcatCasesProvider") void testTomcat(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Tomcat, shellType, shellTool, Opcodes.V1_8, packer, container, python); + runShellInject(TOMCAT_CONFIG, shellType, shellTool, packer); + } + + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot3ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot3ContainerTest.java index cf2b2fe9..74f64dc4 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot3ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot3ContainerTest.java @@ -1,114 +1,90 @@ package com.reajason.javaweb.integration.memshell.springwebmvc; import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; +import com.reajason.javaweb.integration.ContainerTool; import com.reajason.javaweb.memshell.ShellTool; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; import java.util.stream.Stream; -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; - /** * @author ReaJason * @since 2024/12/22 */ @Testcontainers -@Slf4j -public class SpringBoot3ContainerTest { - public static final String imageName = "springboot3"; - static Network network = Network.newNetwork(); +public class SpringBoot3ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.builder() + .imageName("eclipse-temurin:17.0.17_10-jdk") + .jarFile(ContainerTool.springBoot3JarFile) + .jakarta(true) + .jarDeployPath("/app/app.jar") + .command("java -jar /app/app.jar") + .server(Server.SpringWebMvc) + .pidScript(ContainerTool.springbootPid) + .targetJdkVersion(Opcodes.V17) + .enableJspPackerTest(false) + .contextPath("") + .healthCheckPath("/test") + .supportedShellTypes(List.of( + ShellType.SPRING_WEBMVC_JAKARTA_INTERCEPTOR, + ShellType.SPRING_WEBMVC_JAKARTA_CONTROLLER_HANDLER, + ShellType.SPRING_WEBMVC_AGENT_FRAMEWORK_SERVLET + )) + .testPackers(List.of(Packers.H2)) + .unSupportedShellTools(List.of(ShellTool.AntSword)) + .probeShellTypes(List.of( + ShellType.SPRING_WEBMVC_JAKARTA_INTERCEPTOR, + ShellType.SPRING_WEBMVC_JAKARTA_CONTROLLER_HANDLER + )) + .build(); + + private static final ContainerTestConfig TOMCAT_CONFIG = ContainerTestConfig.builder() + .imageName("springboot3") + .server(Server.Tomcat) + .targetJdkVersion(Opcodes.V17) + .supportedShellTypes(List.of( + ShellType.JAKARTA_FILTER, +// ShellType.LISTENER, + ShellType.JAKARTA_VALVE, + ShellType.JAKARTA_WEBSOCKET, + ShellType.AGENT_FILTER_CHAIN, + ShellType.CATALINA_AGENT_CONTEXT_VALVE + )) + .testPackers(List.of(Packers.H2)) + .unSupportedShellTools(List.of(ShellTool.AntSword)) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(springBoot3Dockerfile)) - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(springbootPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/test")) - .withExposedPorts(8080); - - static Stream casesProvider() { - String server = Server.SpringWebMvc; - List supportedShellTypes = List.of( - ShellType.SPRING_WEBMVC_JAKARTA_INTERCEPTOR, - ShellType.SPRING_WEBMVC_JAKARTA_CONTROLLER_HANDLER, - ShellType.SPRING_WEBMVC_AGENT_FRAMEWORK_SERVLET - ); - List testPackers = List.of(Packers.H2); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers, null, List.of(ShellTool.AntSword)); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.SpringWebMvc, shellType, shellTool, Opcodes.V17, packer, container, python); - } - - public static String getUrl(GenericContainer container) { - String host = container.getHost(); - int port = container.getMappedPort(8080); - String url = "http://" + host + ":" + port; - log.info("container started, app url is : {}", url); - return url; - } + public static final GenericContainer container = buildContainer(CONFIG, network); static Stream tomcatCasesProvider() { - String server = Server.Tomcat; - List supportedShellTypes = List.of( - ShellType.JAKARTA_FILTER, -// ShellType.LISTENER, - ShellType.JAKARTA_VALVE, - ShellType.JAKARTA_WEBSOCKET, - ShellType.AGENT_FILTER_CHAIN, - ShellType.CATALINA_AGENT_CONTEXT_VALVE - ); - List testPackers = List.of(Packers.H2); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers, null, List.of(ShellTool.AntSword)); + return generateTestCases(TOMCAT_CONFIG); } @ParameterizedTest(name = "{0}|{1}{2}|{3}") @MethodSource("tomcatCasesProvider") void testTomcat(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Tomcat, shellType, shellTool, Opcodes.V17, packer, container, python); + runShellInject(TOMCAT_CONFIG, shellType, shellTool, packer); } - - @ParameterizedTest - @ValueSource(strings = {ShellType.SPRING_WEBMVC_JAKARTA_INTERCEPTOR, - ShellType.SPRING_WEBMVC_JAKARTA_CONTROLLER_HANDLER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.SpringWebMvc, shellType, Opcodes.V17); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot3ExpressionContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot3ExpressionContainerTest.java index 9cb9075f..791e80b8 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot3ExpressionContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/springwebmvc/SpringBoot3ExpressionContainerTest.java @@ -1,6 +1,7 @@ package com.reajason.javaweb.integration.memshell.springwebmvc; import com.reajason.javaweb.Server; +import com.reajason.javaweb.integration.ContainerTool; import com.reajason.javaweb.integration.ShellAssertion; import com.reajason.javaweb.memshell.ShellTool; import com.reajason.javaweb.memshell.ShellType; @@ -32,8 +33,9 @@ public class SpringBoot3ExpressionContainerTest { public static final String imageName = "springboot3"; @Container - public final static GenericContainer container = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(springBoot3Dockerfile)) + public final static GenericContainer container = new GenericContainer<>("eclipse-temurin:17.0.17_10-jdk") + .withCopyFileToContainer(springBoot3JarFile, "/app/app.jar") + .withCommand("java -jar /app/app.jar") .withCopyToContainer(jattachFile, "/jattach") .withCopyToContainer(springbootPid, "/fetch_pid.sh") .waitingFor(Wait.forHttp("/test")) diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/struct2/Struct2ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/struct2/Struct2ContainerTest.java index 826daf1c..110ac50f 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/struct2/Struct2ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/struct2/Struct2ContainerTest.java @@ -1,81 +1,47 @@ package com.reajason.javaweb.integration.memshell.struct2; import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; +import com.reajason.javaweb.integration.ContainerTool; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/4 */ -@Slf4j @Testcontainers -public class Struct2ContainerTest { - public static final String imageName = "tomcat:8-jre8"; +public class Struct2ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.builder() + .imageName("tomcat:8-jre8") + .server(Server.Struct2) + .warFile(ContainerTool.struct2WarFile) + .warDeployPath("/usr/local/tomcat/webapps/app.war") + .pidScript(ContainerTool.tomcatPid) + .enableJspPackerTest(false) + .targetJdkVersion(Opcodes.V1_8) + .supportedShellTypes(List.of(ShellType.ACTION)) + .testPackers(List.of(Packers.ScriptEngine)) + .probeShellTypes(List.of(ShellType.ACTION)) + .build(); - static Network network = Network.newNetwork(); + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(struct2WarFile, "/usr/local/tomcat/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(tomcatPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Struct2; - List supportedShellTypes = List.of(ShellType.ACTION); - List testPackers = List.of(Packers.ScriptEngine); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Struct2, shellType, shellTool, Opcodes.V1_8, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.ACTION}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Struct2, shellType, Opcodes.V1_8); - } -} \ No newline at end of file +} diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat10ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat10ContainerTest.java index dffdfa2d..bebf7511 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat10ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat10ContainerTest.java @@ -1,95 +1,61 @@ package com.reajason.javaweb.integration.memshell.tomcat; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellTool; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; +import static com.reajason.javaweb.integration.ContainerTool.warJakartaFile; /** * @author ReaJason * @since 2024/12/4 */ -@Slf4j @Testcontainers -public class Tomcat10ContainerTest { - public static final String imageName = "tomcat:10.1-jre11"; - static Network network = Network.newNetwork(); +public class Tomcat10ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.tomcat("tomcat:10.1-jre11") + .warFile(warJakartaFile) + .targetJdkVersion(Opcodes.V11) + .supportedShellTypes(List.of( + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_SERVLET, + ShellType.JAKARTA_LISTENER, + ShellType.JAKARTA_VALVE, + ShellType.JAKARTA_PROXY_VALVE, + ShellType.JAKARTA_WEBSOCKET, + ShellType.UPGRADE, + ShellType.AGENT_FILTER_CHAIN, + ShellType.CATALINA_AGENT_CONTEXT_VALVE + )) + .testPackers(List.of(Packers.JSP, Packers.AgentJarWithJREAttacher)) + .unSupportedShellTools(List.of(ShellTool.AntSword)) + .probeShellTypes(List.of( + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_SERVLET, + ShellType.JAKARTA_LISTENER, + ShellType.JAKARTA_VALVE, + ShellType.JAKARTA_PROXY_VALVE, + ShellType.JAKARTA_WEBSOCKET + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warJakartaFile, "/usr/local/tomcat/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(tomcatPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Tomcat; - List supportedShellTypes = List.of( - ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_SERVLET, - ShellType.JAKARTA_LISTENER, - ShellType.JAKARTA_VALVE, - ShellType.JAKARTA_PROXY_VALVE, - ShellType.JAKARTA_WEBSOCKET, - ShellType.UPGRADE, - ShellType.AGENT_FILTER_CHAIN, - ShellType.CATALINA_AGENT_CONTEXT_VALVE - ); - List testPackers = List.of(Packers.JSP, Packers.AgentJarWithJREAttacher); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers, null, List.of(ShellTool.AntSword)); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Tomcat, shellType, shellTool, Opcodes.V11, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_SERVLET, - ShellType.JAKARTA_LISTENER, - ShellType.JAKARTA_VALVE, - ShellType.JAKARTA_PROXY_VALVE, - ShellType.JAKARTA_WEBSOCKET}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Tomcat, shellType, Opcodes.V11); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat11ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat11ContainerTest.java index 1d38f64f..6ecff2b4 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat11ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat11ContainerTest.java @@ -1,96 +1,61 @@ package com.reajason.javaweb.integration.memshell.tomcat; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellTool; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; +import static com.reajason.javaweb.integration.ContainerTool.warJakartaFile; /** * @author ReaJason * @since 2024/12/4 */ -@Slf4j @Testcontainers -public class Tomcat11ContainerTest { +public class Tomcat11ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.tomcat("tomcat:11.0-jre17") + .warFile(warJakartaFile) + .targetJdkVersion(Opcodes.V17) + .supportedShellTypes(List.of( + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_SERVLET, + ShellType.JAKARTA_LISTENER, + ShellType.JAKARTA_VALVE, + ShellType.JAKARTA_PROXY_VALVE, + ShellType.JAKARTA_WEBSOCKET, + ShellType.UPGRADE, + ShellType.AGENT_FILTER_CHAIN, + ShellType.CATALINA_AGENT_CONTEXT_VALVE + )) + .testPackers(List.of(Packers.JSP, Packers.AgentJarWithJREAttacher)) + .unSupportedShellTools(List.of(ShellTool.AntSword)) + .probeShellTypes(List.of( + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_SERVLET, + ShellType.JAKARTA_LISTENER, + ShellType.JAKARTA_VALVE, + ShellType.JAKARTA_PROXY_VALVE, + ShellType.JAKARTA_WEBSOCKET + )) + .build(); - public static final String imageName = "tomcat:11.0-jre17"; - static Network network = Network.newNetwork(); + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warJakartaFile, "/usr/local/tomcat/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(tomcatPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Tomcat; - List supportedShellTypes = List.of( - ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_SERVLET, - ShellType.JAKARTA_LISTENER, - ShellType.JAKARTA_VALVE, - ShellType.JAKARTA_PROXY_VALVE, - ShellType.JAKARTA_WEBSOCKET, - ShellType.UPGRADE, - ShellType.AGENT_FILTER_CHAIN, - ShellType.CATALINA_AGENT_CONTEXT_VALVE - ); - List testPackers = List.of(Packers.JSP, Packers.AgentJarWithJREAttacher); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers, null, List.of(ShellTool.AntSword)); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Tomcat, shellType, shellTool, Opcodes.V17, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_SERVLET, - ShellType.JAKARTA_LISTENER, - ShellType.JAKARTA_VALVE, - ShellType.JAKARTA_PROXY_VALVE, - ShellType.JAKARTA_WEBSOCKET}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Tomcat, shellType, Opcodes.V17); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat11JRE21ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat11JRE21ContainerTest.java index 9f1883f7..5d8a0a82 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat11JRE21ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat11JRE21ContainerTest.java @@ -1,96 +1,60 @@ package com.reajason.javaweb.integration.memshell.tomcat; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellTool; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; +import static com.reajason.javaweb.integration.ContainerTool.warJakartaFile; /** * @author ReaJason * @since 2024/12/4 */ -@Slf4j @Testcontainers -public class Tomcat11JRE21ContainerTest { +public class Tomcat11JRE21ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.tomcat("tomcat:11.0-jre21") + .warFile(warJakartaFile) + .targetJdkVersion(Opcodes.V21) + .supportedShellTypes(List.of( + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_SERVLET, + ShellType.JAKARTA_LISTENER, + ShellType.JAKARTA_VALVE, + ShellType.JAKARTA_PROXY_VALVE, + ShellType.JAKARTA_WEBSOCKET, + ShellType.AGENT_FILTER_CHAIN, + ShellType.CATALINA_AGENT_CONTEXT_VALVE + )) + .testPackers(List.of(Packers.JSP, Packers.AgentJarWithJREAttacher)) + .unSupportedShellTools(List.of(ShellTool.AntSword)) + .probeShellTypes(List.of( + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_SERVLET, + ShellType.JAKARTA_LISTENER, + ShellType.JAKARTA_VALVE, + ShellType.JAKARTA_PROXY_VALVE, + ShellType.JAKARTA_WEBSOCKET + )) + .build(); - public static final String imageName = "tomcat:11.0-jre21"; - static Network network = Network.newNetwork(); + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warJakartaFile, "/usr/local/tomcat/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(tomcatPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Tomcat; - List supportedShellTypes = List.of( - ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_SERVLET, - ShellType.JAKARTA_LISTENER, - ShellType.JAKARTA_VALVE, - ShellType.JAKARTA_PROXY_VALVE, - ShellType.JAKARTA_WEBSOCKET, - ShellType.AGENT_FILTER_CHAIN, - ShellType.CATALINA_AGENT_CONTEXT_VALVE - ); - List testPackers = List.of(Packers.JSP, Packers.AgentJarWithJREAttacher); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers, null, List.of(ShellTool.AntSword)); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Tomcat, shellType, shellTool, Opcodes.V21, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_SERVLET, - ShellType.JAKARTA_LISTENER, - ShellType.JAKARTA_VALVE, - ShellType.JAKARTA_PROXY_VALVE, - ShellType.JAKARTA_WEBSOCKET}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Tomcat, shellType, Opcodes.V21); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat5ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat5ContainerTest.java index a4a4257c..e6ff169e 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat5ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat5ContainerTest.java @@ -1,90 +1,54 @@ package com.reajason.javaweb.integration.memshell.tomcat; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/4 */ -@Slf4j @Testcontainers -public class Tomcat5ContainerTest { - public static final String imageName = "reajason/tomcat:5-jdk6"; +public class Tomcat5ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig + .tomcat("reajason/tomcat:5-jdk6") + .targetJdkVersion(Opcodes.V1_6) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.PROXY_VALVE, + ShellType.AGENT_FILTER_CHAIN, + ShellType.CATALINA_AGENT_CONTEXT_VALVE + )) + .testPackers(List.of(Packers.JSP, Packers.AgentJarWithJDKAttacher)) + .probeShellTypes(List.of( + ShellType.FILTER, + ShellType.SERVLET, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.PROXY_VALVE + )) + .build(); - static Network network = Network.newNetwork(); + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/usr/local/tomcat/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(tomcatPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Tomcat; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.VALVE, - ShellType.PROXY_VALVE, - ShellType.AGENT_FILTER_CHAIN, - ShellType.CATALINA_AGENT_CONTEXT_VALVE - ); - List testPackers = List.of(Packers.JSP, Packers.AgentJarWithJDKAttacher); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Tomcat, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.FILTER, ShellType.SERVLET, ShellType.LISTENER, - ShellType.VALVE, ShellType.PROXY_VALVE}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Tomcat, shellType, Opcodes.V1_6); - } -} \ No newline at end of file +} diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat6ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat6ContainerTest.java index 86dba01e..561e9b73 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat6ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat6ContainerTest.java @@ -1,88 +1,53 @@ package com.reajason.javaweb.integration.memshell.tomcat; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/4 */ -@Slf4j @Testcontainers -public class Tomcat6ContainerTest { - public static final String imageName = "reajason/tomcat:6-jdk6"; - static Network network = Network.newNetwork(); +public class Tomcat6ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.tomcat("reajason/tomcat:6-jdk6") + .targetJdkVersion(Opcodes.V1_6) + .supportedShellTypes(List.of( + ShellType.FILTER, + ShellType.SERVLET, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.PROXY_VALVE, + ShellType.AGENT_FILTER_CHAIN, + ShellType.CATALINA_AGENT_CONTEXT_VALVE + )) + .testPackers(List.of(Packers.JSP, Packers.AgentJarWithJDKAttacher)) + .probeShellTypes(List.of( + ShellType.FILTER, + ShellType.SERVLET, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.PROXY_VALVE + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/usr/local/tomcat/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(tomcatPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Tomcat; - List supportedShellTypes = List.of( - ShellType.FILTER, - ShellType.SERVLET, - ShellType.LISTENER, - ShellType.VALVE, - ShellType.PROXY_VALVE, - ShellType.AGENT_FILTER_CHAIN, - ShellType.CATALINA_AGENT_CONTEXT_VALVE - ); - List testPackers = List.of(Packers.JSP, Packers.AgentJarWithJDKAttacher); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Tomcat, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.FILTER, ShellType.SERVLET, ShellType.LISTENER, - ShellType.VALVE, ShellType.PROXY_VALVE}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Tomcat, shellType, Opcodes.V1_6); - } -} \ No newline at end of file +} diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat7ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat7ContainerTest.java index 65816cfa..7d102940 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat7ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat7ContainerTest.java @@ -1,89 +1,56 @@ package com.reajason.javaweb.integration.memshell.tomcat; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/4 */ -@Slf4j @Testcontainers -public class Tomcat7ContainerTest { - public static final String imageName = "tomcat:7.0.85-jre7"; - static Network network = Network.newNetwork(); +public class Tomcat7ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.tomcat("tomcat:7.0.85-jre7") + .targetJdkVersion(Opcodes.V1_7) + .probeTargetJdkVersion(Opcodes.V1_6) + .supportedShellTypes(List.of( + ShellType.FILTER, + ShellType.SERVLET, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.PROXY_VALVE, + ShellType.WEBSOCKET, + ShellType.AGENT_FILTER_CHAIN, + ShellType.CATALINA_AGENT_CONTEXT_VALVE + )) + .testPackers(List.of(Packers.JSP, Packers.AgentJarWithJREAttacher)) + .probeShellTypes(List.of( + ShellType.FILTER, + ShellType.SERVLET, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.PROXY_VALVE, + ShellType.WEBSOCKET + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/usr/local/tomcat/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(tomcatPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Tomcat; - List supportedShellTypes = List.of( - ShellType.FILTER, - ShellType.SERVLET, - ShellType.LISTENER, - ShellType.VALVE, - ShellType.PROXY_VALVE, - ShellType.WEBSOCKET, - ShellType.AGENT_FILTER_CHAIN, - ShellType.CATALINA_AGENT_CONTEXT_VALVE - ); - List testPackers = List.of(Packers.JSP, Packers.AgentJarWithJREAttacher); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Tomcat, shellType, shellTool, Opcodes.V1_7, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.FILTER, ShellType.SERVLET, ShellType.LISTENER, - ShellType.VALVE, ShellType.PROXY_VALVE, ShellType.WEBSOCKET}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Tomcat, shellType, Opcodes.V1_6); - } -} \ No newline at end of file +} diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat8ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat8ContainerTest.java index 9ba38c00..0011e0c1 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat8ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat8ContainerTest.java @@ -1,91 +1,56 @@ package com.reajason.javaweb.integration.memshell.tomcat; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/4 */ -@Slf4j @Testcontainers -public class Tomcat8ContainerTest { - public static final String imageName = "tomcat:8-jre8"; +public class Tomcat8ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.tomcat("tomcat:8-jre8") + .targetJdkVersion(Opcodes.V1_8) + .supportedShellTypes(List.of( + ShellType.FILTER, + ShellType.SERVLET, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.PROXY_VALVE, + ShellType.WEBSOCKET, + ShellType.UPGRADE, + ShellType.AGENT_FILTER_CHAIN, + ShellType.CATALINA_AGENT_CONTEXT_VALVE + )) + .testPackers(List.of(Packers.BigInteger, Packers.AgentJarWithJREAttacher)) + .probeShellTypes(List.of( + ShellType.FILTER, + ShellType.SERVLET, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.PROXY_VALVE, + ShellType.WEBSOCKET + )) + .build(); - static Network network = Network.newNetwork(); + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/usr/local/tomcat/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(tomcatPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Tomcat; - List supportedShellTypes = List.of( - ShellType.FILTER, - ShellType.SERVLET, - ShellType.LISTENER, - ShellType.VALVE, - ShellType.PROXY_VALVE, - ShellType.WEBSOCKET, - ShellType.UPGRADE, - ShellType.AGENT_FILTER_CHAIN, - ShellType.CATALINA_AGENT_CONTEXT_VALVE); - List testPackers = List.of(Packers.BigInteger, Packers.AgentJarWithJREAttacher); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Tomcat, shellType, shellTool, Opcodes.V1_8, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.FILTER, ShellType.SERVLET, ShellType.LISTENER, - ShellType.VALVE, ShellType.PROXY_VALVE, ShellType.WEBSOCKET}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Tomcat, shellType, Opcodes.V1_8); - } -} \ No newline at end of file +} diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat9ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat9ContainerTest.java index 4b08bd85..b8a89521 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat9ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/tomcat/Tomcat9ContainerTest.java @@ -1,90 +1,56 @@ package com.reajason.javaweb.integration.memshell.tomcat; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/4 */ -@Slf4j @Testcontainers -public class Tomcat9ContainerTest { - public static final String imageName = "tomcat:9-jre9"; - static Network network = Network.newNetwork(); +public class Tomcat9ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.tomcat("tomcat:9-jre9") + .targetJdkVersion(Opcodes.V9) + .supportedShellTypes(List.of( + ShellType.FILTER, + ShellType.SERVLET, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.PROXY_VALVE, + ShellType.WEBSOCKET, + ShellType.UPGRADE, + ShellType.AGENT_FILTER_CHAIN, + ShellType.CATALINA_AGENT_CONTEXT_VALVE + )) + .testPackers(List.of(Packers.JSP, Packers.ScriptEngine, Packers.AgentJarWithJREAttacher)) + .probeShellTypes(List.of( + ShellType.FILTER, + ShellType.SERVLET, + ShellType.LISTENER, + ShellType.VALVE, + ShellType.PROXY_VALVE, + ShellType.WEBSOCKET + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/usr/local/tomcat/webapps/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(tomcatPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Tomcat; - List supportedShellTypes = List.of( - ShellType.FILTER, - ShellType.SERVLET, - ShellType.LISTENER, - ShellType.VALVE, - ShellType.PROXY_VALVE, - ShellType.WEBSOCKET, - ShellType.UPGRADE, - ShellType.AGENT_FILTER_CHAIN, - ShellType.CATALINA_AGENT_CONTEXT_VALVE - ); - List testPackers = List.of(Packers.JSP, Packers.ScriptEngine, Packers.AgentJarWithJREAttacher); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Tomcat, shellType, shellTool, Opcodes.V9, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.FILTER, ShellType.SERVLET, ShellType.LISTENER, - ShellType.VALVE, ShellType.PROXY_VALVE, ShellType.WEBSOCKET}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Tomcat, shellType, Opcodes.V9); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/weblogic/WebLogic1036ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/weblogic/WebLogic1036ContainerTest.java index 87fd1f9d..eb2932f2 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/weblogic/WebLogic1036ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/weblogic/WebLogic1036ContainerTest.java @@ -1,91 +1,51 @@ package com.reajason.javaweb.integration.memshell.weblogic; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; /** * @author ReaJason * @since 2024/12/24 */ @Testcontainers -@Slf4j -public class WebLogic1036ContainerTest { - public static final String imageName = "reajason/weblogic:10.3.6"; - static Network network = Network.newNetwork(); +public class WebLogic1036ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.webLogic( + "reajason/weblogic:10.3.6", + "/opt/oracle/wls1036/user_projects/domains/base_domain/autodeploy/app.war") + .targetJdkVersion(Opcodes.V1_6) + .assertLogs(false) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.WEBLOGIC_AGENT_SERVLET_CONTEXT + )) + .testPackers(List.of(Packers.Base64)) + .probeShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/opt/oracle/wls1036/user_projects/domains/base_domain/autodeploy/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(weblogicPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(7001); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.WebLogic; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.WEBLOGIC_AGENT_SERVLET_CONTEXT - ); - List testPackers = List.of(Packers.Base64); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.WebLogic, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - public static String getUrl(GenericContainer container) { - String host = container.getHost(); - int port = container.getMappedPort(7001); - String url = "http://" + host + ":" + port + "/app"; - log.info("container started, app url is : {}", url); - return url; - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.WebLogic, shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/weblogic/WebLogic12214ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/weblogic/WebLogic12214ContainerTest.java index ebb007fc..e6a74d92 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/weblogic/WebLogic12214ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/weblogic/WebLogic12214ContainerTest.java @@ -1,94 +1,50 @@ package com.reajason.javaweb.integration.memshell.weblogic; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/24 */ @Testcontainers -@Slf4j -public class WebLogic12214ContainerTest { - public static final String imageName = "reajason/weblogic:12.2.1.4"; - static Network network = Network.newNetwork(); +public class WebLogic12214ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.webLogic( + "reajason/weblogic:12.2.1.4", + "/u01/oracle/user_projects/domains/domain1/autodeploy/app.war") + .targetJdkVersion(Opcodes.V1_6) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.WEBLOGIC_AGENT_SERVLET_CONTEXT + )) + .testPackers(List.of(Packers.Base64)) + .probeShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/u01/oracle/user_projects/domains/domain1/autodeploy/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(weblogicPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(7001); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.WebLogic; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.WEBLOGIC_AGENT_SERVLET_CONTEXT - ); - List testPackers = List.of(Packers.Base64); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.WebLogic, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - public static String getUrl(GenericContainer container) { - String host = container.getHost(); - int port = container.getMappedPort(7001); - String url = "http://" + host + ":" + port + "/app"; - log.info("container started, app url is : {}", url); - return url; - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.WebLogic, shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/weblogic/WebLogic14110ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/weblogic/WebLogic14110ContainerTest.java index e3e04b0f..3e101e1c 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/weblogic/WebLogic14110ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/weblogic/WebLogic14110ContainerTest.java @@ -1,94 +1,50 @@ package com.reajason.javaweb.integration.memshell.weblogic; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/24 */ @Testcontainers -@Slf4j -public class WebLogic14110ContainerTest { - public static final String imageName = "reajason/weblogic:14.1.1.0"; - static Network network = Network.newNetwork(); +public class WebLogic14110ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.webLogic( + "reajason/weblogic:14.1.1.0", + "/u01/oracle/user_projects/domains/domain1/autodeploy/app.war") + .targetJdkVersion(Opcodes.V1_6) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.WEBLOGIC_AGENT_SERVLET_CONTEXT + )) + .testPackers(List.of(Packers.Base64)) + .probeShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/u01/oracle/user_projects/domains/domain1/autodeploy/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(weblogicPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(7001); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.WebLogic; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.WEBLOGIC_AGENT_SERVLET_CONTEXT - ); - List testPackers = List.of(Packers.Base64); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.WebLogic, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - public static String getUrl(GenericContainer container) { - String host = container.getHost(); - int port = container.getMappedPort(7001); - String url = "http://" + host + ":" + port + "/app"; - log.info("container started, app url is : {}", url); - return url; - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.WebLogic, shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/weblogic/WebLogic14120ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/weblogic/WebLogic14120ContainerTest.java new file mode 100644 index 00000000..a899a404 --- /dev/null +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/weblogic/WebLogic14120ContainerTest.java @@ -0,0 +1,50 @@ +package com.reajason.javaweb.integration.memshell.weblogic; + +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; +import com.reajason.javaweb.memshell.ShellType; +import com.reajason.javaweb.packer.Packers; +import net.bytebuddy.jar.asm.Opcodes; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.Network; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import java.util.List; + +/** + * @author ReaJason + * @since 2024/12/24 + */ +@Testcontainers +public class WebLogic14120ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.webLogic( + "reajason/weblogic:14.1.2.0-jdk17", + "/u01/oracle/user_projects/domains/domain1/autodeploy/app.war") + .targetJdkVersion(Opcodes.V17) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.WEBLOGIC_AGENT_SERVLET_CONTEXT + )) + .testPackers(List.of(Packers.Base64)) + .probeShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER + )) + .build(); + + static Network network = newNetwork(); + @Container + public static final GenericContainer python = buildPythonContainer(network); + + @Container + public static final GenericContainer container = buildContainer(CONFIG, network); + + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; + } +} diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere/OpenLiberty18ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere/OpenLiberty18ContainerTest.java index 376975c6..181624ae 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere/OpenLiberty18ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere/OpenLiberty18ContainerTest.java @@ -1,96 +1,53 @@ package com.reajason.javaweb.integration.memshell.websphere; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.time.Duration; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/21 */ @Testcontainers -@Slf4j -public class OpenLiberty18ContainerTest { - public static final String imageName = "open-liberty:18.0.0.4-webProfile8"; - static Network network = Network.newNetwork(); +public class OpenLiberty18ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.webSphere( + "open-liberty:18.0.0.4-webProfile8", + "/config/dropins/app.war") + .targetJdkVersion(Opcodes.V1_6) + .waitStrategy(Wait.forHttp("/app/").forPort(9080).withStartupTimeout(Duration.ofMinutes(5))) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.WAS_AGENT_FILTER_MANAGER + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/config/dropins/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(webspherePid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app/").forPort(9080).withStartupTimeout(Duration.ofMinutes(5))) - .withExposedPorts(9080) - .withPrivilegedMode(true); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.WebSphere; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.WAS_AGENT_FILTER_MANAGER - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.WebSphere, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - public static String getUrl(GenericContainer container) { - String host = container.getHost(); - int port = container.getMappedPort(9080); - String url = "http://" + host + ":" + port + "/app"; - log.info("container started, app url is : {}", url); - return url; - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.WebSphere, shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere/OpenLiberty20ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere/OpenLiberty20ContainerTest.java index 13ab3478..08e70d19 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere/OpenLiberty20ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere/OpenLiberty20ContainerTest.java @@ -1,96 +1,53 @@ package com.reajason.javaweb.integration.memshell.websphere; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.time.Duration; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/21 */ @Testcontainers -@Slf4j -public class OpenLiberty20ContainerTest { - public static final String imageName = "open-liberty:20.0.0.12-full-java8-openj9"; - static Network network = Network.newNetwork(); +public class OpenLiberty20ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.webSphere( + "open-liberty:20.0.0.12-full-java8-openj9", + "/config/dropins/app.war") + .targetJdkVersion(Opcodes.V1_6) + .waitStrategy(Wait.forHttp("/app/").forPort(9080).withStartupTimeout(Duration.ofMinutes(5))) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.WAS_AGENT_FILTER_MANAGER + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/config/dropins/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(webspherePid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app/").forPort(9080).withStartupTimeout(Duration.ofMinutes(5))) - .withExposedPorts(9080) - .withPrivilegedMode(true); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.WebSphere; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.WAS_AGENT_FILTER_MANAGER - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.WebSphere, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - public static String getUrl(GenericContainer container) { - String host = container.getHost(); - int port = container.getMappedPort(9080); - String url = "http://" + host + ":" + port + "/app"; - log.info("container started, app url is : {}", url); - return url; - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.WebSphere, shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere/OpenLiberty22ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere/OpenLiberty22ContainerTest.java index 8dc36e2d..5409cea1 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere/OpenLiberty22ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere/OpenLiberty22ContainerTest.java @@ -1,96 +1,53 @@ package com.reajason.javaweb.integration.memshell.websphere; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.time.Duration; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/21 */ @Testcontainers -@Slf4j -public class OpenLiberty22ContainerTest { - public static final String imageName = "open-liberty:22.0.0.12-full-java11-openj9"; - static Network network = Network.newNetwork(); +public class OpenLiberty22ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.webSphere( + "open-liberty:22.0.0.12-full-java11-openj9", + "/config/dropins/app.war") + .targetJdkVersion(Opcodes.V11) + .waitStrategy(Wait.forHttp("/app/").forPort(9080).withStartupTimeout(Duration.ofMinutes(5))) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.WAS_AGENT_FILTER_MANAGER + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/config/dropins/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(webspherePid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app/").forPort(9080).withStartupTimeout(Duration.ofMinutes(5))) - .withExposedPorts(9080) - .withPrivilegedMode(true); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.WebSphere; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.WAS_AGENT_FILTER_MANAGER - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.WebSphere, shellType, shellTool, Opcodes.V11, packer, container, python); - } - - public static String getUrl(GenericContainer container) { - String host = container.getHost(); - int port = container.getMappedPort(9080); - String url = "http://" + host + ":" + port + "/app"; - log.info("container started, app url is : {}", url); - return url; - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.WebSphere, shellType, Opcodes.V11); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere/OpenLiberty25ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere/OpenLiberty25ContainerTest.java index 12a397d4..03076713 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere/OpenLiberty25ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere/OpenLiberty25ContainerTest.java @@ -1,96 +1,53 @@ package com.reajason.javaweb.integration.memshell.websphere; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.time.Duration; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/21 */ @Testcontainers -@Slf4j -public class OpenLiberty25ContainerTest { - public static final String imageName = "open-liberty:25.0.0.12-full-java17-openj9"; - static Network network = Network.newNetwork(); +public class OpenLiberty25ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.webSphere( + "open-liberty:25.0.0.12-full-java17-openj9", + "/config/dropins/app.war") + .targetJdkVersion(Opcodes.V17) + .waitStrategy(Wait.forHttp("/app/").forPort(9080).withStartupTimeout(Duration.ofMinutes(5))) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.WAS_AGENT_FILTER_MANAGER + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/config/dropins/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(webspherePid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app/").forPort(9080).withStartupTimeout(Duration.ofMinutes(5))) - .withExposedPorts(9080) - .withPrivilegedMode(true); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.WebSphere; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.WAS_AGENT_FILTER_MANAGER - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.WebSphere, shellType, shellTool, Opcodes.V17, packer, container, python); - } - - public static String getUrl(GenericContainer container) { - String host = container.getHost(); - int port = container.getMappedPort(9080); - String url = "http://" + host + ":" + port + "/app"; - log.info("container started, app url is : {}", url); - return url; - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.WebSphere, shellType, Opcodes.V17); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere/WebSphere855ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere/WebSphere855ContainerTest.java index bc03ac87..753d8297 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere/WebSphere855ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere/WebSphere855ContainerTest.java @@ -1,96 +1,53 @@ package com.reajason.javaweb.integration.memshell.websphere; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.time.Duration; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/21 */ @Testcontainers -@Slf4j -public class WebSphere855ContainerTest { - public static final String imageName = "reajason/websphere:8.5.5.24"; - static Network network = Network.newNetwork(); +public class WebSphere855ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.webSphere( + "reajason/websphere:8.5.5.24", + "/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/monitoredDeployableApps/servers/server1/app.war") + .targetJdkVersion(Opcodes.V1_6) + .waitStrategy(Wait.forHttp("/app/").forPort(9080).withStartupTimeout(Duration.ofMinutes(5))) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.WAS_AGENT_FILTER_MANAGER + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/monitoredDeployableApps/servers/server1/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(webspherePid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app/").forPort(9080).withStartupTimeout(Duration.ofMinutes(5))) - .withExposedPorts(9080) - .withPrivilegedMode(true); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.WebSphere; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.WAS_AGENT_FILTER_MANAGER - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.WebSphere, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - public static String getUrl(GenericContainer container) { - String host = container.getHost(); - int port = container.getMappedPort(9080); - String url = "http://" + host + ":" + port + "/app"; - log.info("container started, app url is : {}", url); - return url; - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.WebSphere, shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere/WebSphere905ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere/WebSphere905ContainerTest.java index e14031fd..855ec6db 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere/WebSphere905ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere/WebSphere905ContainerTest.java @@ -1,95 +1,53 @@ package com.reajason.javaweb.integration.memshell.websphere; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.time.Duration; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/21 */ @Testcontainers -@Slf4j -public class WebSphere905ContainerTest { - public static final String imageName = "reajason/websphere:9.0.5.17"; - static Network network = Network.newNetwork(); +public class WebSphere905ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.webSphere( + "reajason/websphere:9.0.5.17", + "/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/monitoredDeployableApps/servers/server1/app.war") + .targetJdkVersion(Opcodes.V1_6) + .waitStrategy(Wait.forHttp("/app/").forPort(9080).withStartupTimeout(Duration.ofMinutes(5))) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.WAS_AGENT_FILTER_MANAGER + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/monitoredDeployableApps/servers/server1/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(webspherePid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app/").forPort(9080).withStartupTimeout(Duration.ofMinutes(5))) - .withExposedPorts(9080) - .withPrivilegedMode(true); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.WebSphere; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.WAS_AGENT_FILTER_MANAGER - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.WebSphere, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - public static String getUrl(GenericContainer container) { - String host = container.getHost(); - int port = container.getMappedPort(9080); - String url = "http://" + host + ":" + port + "/app"; - log.info("container started, app url is : {}", url); - return url; - } - @ParameterizedTest - @ValueSource(strings = {ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.WebSphere, shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere7/WebSphere700ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere7/WebSphere700ContainerTest.java index c96a7651..2dcab4f5 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere7/WebSphere700ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/websphere7/WebSphere700ContainerTest.java @@ -1,85 +1,49 @@ package com.reajason.javaweb.integration.memshell.websphere7; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.time.Duration; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/21 */ @Testcontainers -@Slf4j -public class WebSphere700ContainerTest { - public static final String imageName = "reajason/websphere:7.0.0.21"; - static Network network = Network.newNetwork(); +public class WebSphere700ContainerTest extends AbstractContainerTest { + + private static final ContainerTestConfig CONFIG = ContainerTestConfig + .webSphere( + "reajason/websphere:7.0.0.21", + "/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/monitoredDeployableApps/servers/server1/app.war") + .targetJdkVersion(Opcodes.V1_6) + .waitStrategy(Wait.forHttp("/app/").forPort(9080).withStartupTimeout(Duration.ofMinutes(5))) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER + )) + .testPackers(List.of(Packers.JSP)) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public final static GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/monitoredDeployableApps/servers/server1/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(webspherePid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app/").forPort(9080).withStartupTimeout(Duration.ofMinutes(5))) - .withExposedPorts(9080) - .withPrivilegedMode(true); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.WebSphere; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER -// ShellType.WAS_AGENT_FILTER_MANAGER // fuck the env, java.lang.instrument.UnmodifiableClassException - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.WebSphere, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - public static String getUrl(GenericContainer container) { - String host = container.getHost(); - int port = container.getMappedPort(9080); - String url = "http://" + host + ":" + port + "/app"; - log.info("container started, app url is : {}", url); - return url; + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly18ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly18ContainerTest.java index 16c07386..ca2645ad 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly18ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly18ContainerTest.java @@ -1,85 +1,50 @@ package com.reajason.javaweb.integration.memshell.wildfly; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/10 */ -@Slf4j @Testcontainers -public class Wildfly18ContainerTest { - public static final String imageName = "jboss/wildfly:18.0.1.Final"; - static Network network = Network.newNetwork(); +public class Wildfly18ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.undertow( + "jboss/wildfly:18.0.1.Final", + "/opt/jboss/wildfly/standalone/deployments/app.war") + .targetJdkVersion(Opcodes.V1_6) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.UNDERTOW_AGENT_SERVLET_HANDLER + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public static final GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/opt/jboss/wildfly/standalone/deployments/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jbossPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Undertow; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.UNDERTOW_AGENT_SERVLET_HANDLER - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Undertow, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = { ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Undertow, shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly23ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly23ContainerTest.java index 7ad01b10..6e44c6fc 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly23ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly23ContainerTest.java @@ -1,85 +1,50 @@ package com.reajason.javaweb.integration.memshell.wildfly; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/10 */ -@Slf4j @Testcontainers -public class Wildfly23ContainerTest { - public static final String imageName = "jboss/wildfly:23.0.2.Final"; - static Network network = Network.newNetwork(); +public class Wildfly23ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.undertow( + "jboss/wildfly:23.0.2.Final", + "/opt/jboss/wildfly/standalone/deployments/app.war") + .targetJdkVersion(Opcodes.V1_6) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.UNDERTOW_AGENT_SERVLET_HANDLER + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public static final GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/opt/jboss/wildfly/standalone/deployments/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jbossPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Undertow; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.UNDERTOW_AGENT_SERVLET_HANDLER - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Undertow, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = { ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Undertow, shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly26ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly26ContainerTest.java index 699bf15d..b9fcccc7 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly26ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly26ContainerTest.java @@ -1,85 +1,50 @@ package com.reajason.javaweb.integration.memshell.wildfly; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * @author ReaJason * @since 2024/12/10 */ -@Slf4j @Testcontainers -public class Wildfly26ContainerTest { - public static final String imageName = "quay.io/wildfly/wildfly:26.1.3.Final-jdk11"; - static Network network = Network.newNetwork(); +public class Wildfly26ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.undertow( + "quay.io/wildfly/wildfly:26.1.3.Final-jdk11", + "/opt/jboss/wildfly/standalone/deployments/app.war") + .targetJdkVersion(Opcodes.V11) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.UNDERTOW_AGENT_SERVLET_HANDLER + )) + .testPackers(List.of(Packers.JSP)) + .probeShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public static final GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/opt/jboss/wildfly/standalone/deployments/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jbossPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Undertow; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.UNDERTOW_AGENT_SERVLET_HANDLER - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Undertow, shellType, shellTool, Opcodes.V11, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = { ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Undertow, shellType, Opcodes.V11); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly27ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly27ContainerTest.java index bc4d235e..d714e135 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly27ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly27ContainerTest.java @@ -1,88 +1,55 @@ package com.reajason.javaweb.integration.memshell.wildfly; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellTool; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; +import static com.reajason.javaweb.integration.ContainerTool.warJakartaFile; /** * @author ReaJason * @since 2024/12/10 */ -@Slf4j @Testcontainers -public class Wildfly27ContainerTest { - public static final String imageName = "quay.io/wildfly/wildfly:27.0.1.Final-jdk11"; - static Network network = Network.newNetwork(); +public class Wildfly27ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.undertow( + "quay.io/wildfly/wildfly:27.0.1.Final-jdk11", + "/opt/jboss/wildfly/standalone/deployments/app.war") + .warFile(warJakartaFile) + .targetJdkVersion(Opcodes.V11) + .supportedShellTypes(List.of( + ShellType.JAKARTA_SERVLET, + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_LISTENER, + ShellType.UNDERTOW_AGENT_SERVLET_HANDLER + )) + .testPackers(List.of(Packers.JSP)) + .unSupportedShellTools(List.of(ShellTool.AntSword)) + .probeShellTypes(List.of( + ShellType.JAKARTA_SERVLET, + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_LISTENER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public static final GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warJakartaFile, "/opt/jboss/wildfly/standalone/deployments/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jbossPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Undertow; - List supportedShellTypes = List.of( - ShellType.JAKARTA_SERVLET, - ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_LISTENER, - ShellType.UNDERTOW_AGENT_SERVLET_HANDLER - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers, - null, List.of(ShellTool.AntSword) // AntSword not support jakarta - ); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Undertow, shellType, shellTool, Opcodes.V11, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.JAKARTA_SERVLET, - ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_LISTENER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Undertow, shellType, Opcodes.V11); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly30ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly30ContainerTest.java index f1d4d7cf..0cd67ab8 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly30ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly30ContainerTest.java @@ -1,89 +1,55 @@ package com.reajason.javaweb.integration.memshell.wildfly; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellTool; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; +import static com.reajason.javaweb.integration.ContainerTool.warJakartaFile; /** * @author ReaJason * @since 2024/12/10 */ -@Slf4j @Testcontainers -public class Wildfly30ContainerTest { - public static final String imageName = "quay.io/wildfly/wildfly:30.0.1.Final-jdk17"; - static Network network = Network.newNetwork(); +public class Wildfly30ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.undertow( + "quay.io/wildfly/wildfly:30.0.1.Final-jdk17", + "/opt/jboss/wildfly/standalone/deployments/app.war") + .warFile(warJakartaFile) + .targetJdkVersion(Opcodes.V17) + .supportedShellTypes(List.of( + ShellType.JAKARTA_SERVLET, + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_LISTENER, + ShellType.UNDERTOW_AGENT_SERVLET_HANDLER + )) + .testPackers(List.of(Packers.JSP)) + .unSupportedShellTools(List.of(ShellTool.AntSword)) + .probeShellTypes(List.of( + ShellType.JAKARTA_SERVLET, + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_LISTENER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public static final GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warJakartaFile, "/opt/jboss/wildfly/standalone/deployments/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jbossPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Undertow; - List supportedShellTypes = List.of( - ShellType.JAKARTA_SERVLET, - ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_LISTENER, - ShellType.UNDERTOW_AGENT_SERVLET_HANDLER - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers, - null, List.of(ShellTool.AntSword) // AntSword not support jakarta - ); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Undertow, shellType, shellTool, Opcodes.V17, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.JAKARTA_SERVLET, - ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_LISTENER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Undertow, shellType, Opcodes.V17); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly36ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly36ContainerTest.java index 18e9f1cc..d55a4fc7 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly36ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly36ContainerTest.java @@ -1,89 +1,55 @@ package com.reajason.javaweb.integration.memshell.wildfly; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellTool; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; +import static com.reajason.javaweb.integration.ContainerTool.warJakartaFile; /** * @author ReaJason * @since 2024/12/10 */ -@Slf4j @Testcontainers -public class Wildfly36ContainerTest { - public static final String imageName = "quay.io/wildfly/wildfly:36.0.0.Final-jdk21"; - static Network network = Network.newNetwork(); +public class Wildfly36ContainerTest extends AbstractContainerTest { + private static final ContainerTestConfig CONFIG = ContainerTestConfig.undertow( + "quay.io/wildfly/wildfly:36.0.0.Final-jdk21", + "/opt/jboss/wildfly/standalone/deployments/app.war") + .warFile(warJakartaFile) + .targetJdkVersion(Opcodes.V21) + .supportedShellTypes(List.of( + ShellType.JAKARTA_SERVLET, + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_LISTENER, + ShellType.UNDERTOW_AGENT_SERVLET_HANDLER + )) + .testPackers(List.of(Packers.JSP)) + .unSupportedShellTools(List.of(ShellTool.AntSword)) + .probeShellTypes(List.of( + ShellType.JAKARTA_SERVLET, + ShellType.JAKARTA_FILTER, + ShellType.JAKARTA_LISTENER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public static final GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warJakartaFile, "/opt/jboss/wildfly/standalone/deployments/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jbossPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Undertow; - List supportedShellTypes = List.of( - ShellType.JAKARTA_SERVLET, - ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_LISTENER, - ShellType.UNDERTOW_AGENT_SERVLET_HANDLER - ); - List testPackers = List.of(Packers.JSP); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers, - null, List.of(ShellTool.AntSword) // AntSword not support jakarta - ); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Undertow, shellType, shellTool, Opcodes.V21, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = {ShellType.JAKARTA_SERVLET, - ShellType.JAKARTA_FILTER, - ShellType.JAKARTA_LISTENER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Undertow, shellType, Opcodes.V21); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } } diff --git a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly9ContainerTest.java b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly9ContainerTest.java index 7985d463..c21e736c 100644 --- a/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly9ContainerTest.java +++ b/integration-test/src/test/java/com/reajason/javaweb/integration/memshell/wildfly/Wildfly9ContainerTest.java @@ -1,33 +1,18 @@ package com.reajason.javaweb.integration.memshell.wildfly; -import com.reajason.javaweb.Server; -import com.reajason.javaweb.integration.ShellAssertion; -import com.reajason.javaweb.integration.TestCasesProvider; +import com.reajason.javaweb.integration.AbstractContainerTest; +import com.reajason.javaweb.integration.ContainerTestConfig; import com.reajason.javaweb.memshell.ShellTool; import com.reajason.javaweb.memshell.ShellType; import com.reajason.javaweb.packer.Packers; -import lombok.extern.slf4j.Slf4j; import net.bytebuddy.jar.asm.Opcodes; import org.apache.commons.lang3.tuple.Triple; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.Network; -import org.testcontainers.containers.wait.strategy.Wait; -import org.testcontainers.images.builder.ImageFromDockerfile; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; -import java.util.stream.Stream; - -import static com.reajason.javaweb.integration.ContainerTool.*; -import static com.reajason.javaweb.integration.DoesNotContainExceptionMatcher.doesNotContainException; -import static com.reajason.javaweb.integration.ShellAssertion.shellInjectIsOk; -import static org.hamcrest.MatcherAssert.assertThat; /** * Wildfly - DockerHub @@ -36,59 +21,40 @@ import static org.hamcrest.MatcherAssert.assertThat; * @author ReaJason * @since 2024/12/10 */ -@Slf4j @Testcontainers -public class Wildfly9ContainerTest { - public static final String imageName = "jboss/wildfly:9.0.1.Final"; - static Network network = Network.newNetwork(); +public class Wildfly9ContainerTest extends AbstractContainerTest { + + private static final ContainerTestConfig CONFIG = ContainerTestConfig + .undertow( + "jboss/wildfly:9.0.1.Final", + "/opt/jboss/wildfly/standalone/deployments/app.war") + .targetJdkVersion(Opcodes.V1_6) + .supportedShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER, + ShellType.UNDERTOW_AGENT_SERVLET_HANDLER + )) + .testPackers(List.of(Packers.JSP)) + .unSupportedCases(List.of( + Triple.of(ShellType.UNDERTOW_AGENT_SERVLET_HANDLER, ShellTool.AntSword, Packers.AgentJar) + )) + .probeShellTypes(List.of( + ShellType.SERVLET, + ShellType.FILTER, + ShellType.LISTENER + )) + .build(); + + static Network network = newNetwork(); @Container - public final static GenericContainer python = new GenericContainer<>(new ImageFromDockerfile() - .withDockerfile(neoGeorgDockerfile)) - .withNetwork(network); + public static final GenericContainer python = buildPythonContainer(network); + @Container - public static final GenericContainer container = new GenericContainer<>(imageName) - .withCopyToContainer(warFile, "/opt/jboss/wildfly/standalone/deployments/app.war") - .withCopyToContainer(jattachFile, "/jattach") - .withCopyToContainer(jbossPid, "/fetch_pid.sh") - .withNetwork(network) - .withNetworkAliases("app") - .waitingFor(Wait.forHttp("/app")) - .withExposedPorts(8080); + public static final GenericContainer container = buildContainer(CONFIG, network); - static Stream casesProvider() { - String server = Server.Undertow; - List supportedShellTypes = List.of( - ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER, - ShellType.UNDERTOW_AGENT_SERVLET_HANDLER - ); - List testPackers = List.of(Packers.JSP); - List> unSupportedCases = List.of( - Triple.of(ShellType.UNDERTOW_AGENT_SERVLET_HANDLER, ShellTool.AntSword, Packers.AgentJar) // Request ClassNotFound in module - ); - return TestCasesProvider.getTestCases(imageName, server, supportedShellTypes, testPackers, unSupportedCases); - } - - @AfterAll - static void tearDown() { - String logs = container.getLogs(); - log.info(logs); - assertThat("Logs should not contain any exceptions", logs, doesNotContainException()); - } - - @ParameterizedTest(name = "{0}|{1}{2}|{3}") - @MethodSource("casesProvider") - void test(String imageName, String shellType, String shellTool, Packers packer) { - shellInjectIsOk(getUrl(container), Server.Undertow, shellType, shellTool, Opcodes.V1_6, packer, container, python); - } - - @ParameterizedTest - @ValueSource(strings = { ShellType.SERVLET, - ShellType.FILTER, - ShellType.LISTENER,}) - void testProbeInject(String shellType) { - String url = getUrl(container); - ShellAssertion.testProbeInject(url, Server.Undertow, shellType, Opcodes.V1_6); + @Override + protected ContainerTestConfig getConfig() { + return CONFIG; } }