Skip to content

Commit 307a454

Browse files
committed
refactor: use commonUtil for packageName
1 parent 7fbe855 commit 307a454

22 files changed

Lines changed: 60 additions & 43 deletions

generator/src/main/java/com/reajason/javaweb/utils/CommonUtil.java

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -111,38 +111,35 @@ public static String appendLambdaSuffix(String className) {
111111
return className + "$Proxy0$$Lambda$1";
112112
}
113113

114-
public static String generateShellClassName(String server, String shellType) {
115-
String packageName;
114+
public static String getWebPackageNameForServer(String server) {
116115
switch (server) {
117116
case Jetty:
118-
packageName = "org.eclipse.jetty.servlet.handlers";
119-
break;
117+
return "org.eclipse.jetty.servlet.handlers";
120118
case Undertow:
121-
packageName = "io.undertow.servlet.handlers";
122-
break;
119+
return "io.undertow.servlet.handlers";
123120
case SpringWebMvc:
124-
packageName = "org.springframework.boot.mvc.handlers";
125-
break;
121+
return "org.springframework.boot.mvc.handlers";
126122
case SpringWebFlux:
127-
packageName = "org.springframework.boot.webflux.handlers";
128-
break;
123+
return "org.springframework.boot.webflux.handlers";
129124
case WebSphere:
130-
packageName = "com.ibm.ws.webcontainer.handlers";
131-
break;
125+
return "com.ibm.ws.webcontainer.handlers";
132126
case WebLogic:
133-
packageName = "weblogic.servlet.internal.handlers";
134-
break;
127+
return "weblogic.servlet.internal.handlers";
135128
case Resin:
136-
packageName = "com.caucho.server.dispatch.handlers";
137-
break;
129+
return "com.caucho.server.dispatch.handlers";
138130
case BES:
139-
packageName = "com.bes.enterprise.webtier.web.handlers";
140-
break;
131+
return "com.bes.enterprise.webtier.web.handlers";
132+
case Apusic:
133+
return "com.apusic.web.handlers";
134+
case InforSuite:
135+
return "com.cvicse.inforsuite.web.handlers";
141136
default:
142-
packageName = "org.apache.http.web.handlers";
143-
break;
137+
return "org.apache.http.web.handlers";
144138
}
145-
return packageName
139+
}
140+
141+
public static String generateShellClassName(String server, String shellType) {
142+
return getWebPackageNameForServer(server)
146143
+ "." + getRandomString(5)
147144
+ "." + MIDDLEWARE_NAMES[new Random().nextInt(MIDDLEWARE_NAMES.length)] + shellType;
148145
}

integration-test/src/test/java/com/reajason/javaweb/integration/probe/glassfish/GlassFish3ContainerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.reajason.javaweb.memshell.ShellTool;
88
import com.reajason.javaweb.memshell.ShellType;
99
import com.reajason.javaweb.packer.Packers;
10+
import com.reajason.javaweb.utils.CommonUtil;
1011
import lombok.SneakyThrows;
1112
import lombok.extern.slf4j.Slf4j;
1213
import org.junit.jupiter.api.AfterAll;
@@ -107,6 +108,6 @@ void testFilterFirstInject() {
107108
String data = VulTool.post(url + "/b64", DetectionTool.getGlassFishFilterProbe());
108109
List<String> filter = ProbeAssertion.getFiltersForContext(data, "/app");
109110
String filterName = ProbeAssertion.extractFilterName(filter.get(0));
110-
assertThat(filterName, anyOf(startsWith("org.apache.http.web.handlers")));
111+
assertThat(filterName, anyOf(startsWith(CommonUtil.getWebPackageNameForServer(Server.GlassFish))));
111112
}
112113
}

integration-test/src/test/java/com/reajason/javaweb/integration/probe/glassfish/GlassFish4ContainerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.reajason.javaweb.memshell.ShellTool;
88
import com.reajason.javaweb.memshell.ShellType;
99
import com.reajason.javaweb.packer.Packers;
10+
import com.reajason.javaweb.utils.CommonUtil;
1011
import lombok.SneakyThrows;
1112
import lombok.extern.slf4j.Slf4j;
1213
import org.junit.jupiter.api.AfterAll;
@@ -20,7 +21,6 @@
2021

2122
import java.nio.file.Files;
2223
import java.nio.file.Paths;
23-
import java.time.Duration;
2424
import java.util.List;
2525

2626
import static com.reajason.javaweb.integration.ContainerTool.getUrl;
@@ -108,6 +108,6 @@ void testFilterFirstInject() {
108108
String data = VulTool.post(url + "/b64", DetectionTool.getGlassFishFilterProbe());
109109
List<String> filter = ProbeAssertion.getFiltersForContext(data, "/app");
110110
String filterName = ProbeAssertion.extractFilterName(filter.get(0));
111-
assertThat(filterName, anyOf(startsWith("org.apache.http.web.handlers")));
111+
assertThat(filterName, anyOf(startsWith(CommonUtil.getWebPackageNameForServer(Server.GlassFish))));
112112
}
113113
}

integration-test/src/test/java/com/reajason/javaweb/integration/probe/glassfish/GlassFish501ContainerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.reajason.javaweb.memshell.ShellTool;
88
import com.reajason.javaweb.memshell.ShellType;
99
import com.reajason.javaweb.packer.Packers;
10+
import com.reajason.javaweb.utils.CommonUtil;
1011
import lombok.SneakyThrows;
1112
import lombok.extern.slf4j.Slf4j;
1213
import org.junit.jupiter.api.BeforeAll;
@@ -100,6 +101,6 @@ void testFilterFirstInject() {
100101
String data = VulTool.post(url + "/b64", DetectionTool.getGlassFishFilterProbe());
101102
List<String> filter = ProbeAssertion.getFiltersForContext(data, "/app");
102103
String filterName = ProbeAssertion.extractFilterName(filter.get(0));
103-
assertThat(filterName, anyOf(startsWith("org.apache.http.web.handlers")));
104+
assertThat(filterName, anyOf(startsWith(CommonUtil.getWebPackageNameForServer(Server.GlassFish))));
104105
}
105106
}

integration-test/src/test/java/com/reajason/javaweb/integration/probe/glassfish/GlassFish510ContainerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.reajason.javaweb.memshell.ShellTool;
88
import com.reajason.javaweb.memshell.ShellType;
99
import com.reajason.javaweb.packer.Packers;
10+
import com.reajason.javaweb.utils.CommonUtil;
1011
import lombok.SneakyThrows;
1112
import lombok.extern.slf4j.Slf4j;
1213
import org.junit.jupiter.api.BeforeAll;
@@ -101,6 +102,6 @@ void testFilterFirstInject() {
101102
String data = VulTool.post(url + "/b64", DetectionTool.getGlassFishFilterProbe());
102103
List<String> filter = ProbeAssertion.getFiltersForContext(data, "/app");
103104
String filterName = ProbeAssertion.extractFilterName(filter.get(0));
104-
assertThat(filterName, anyOf(startsWith("org.apache.http.web.handlers")));
105+
assertThat(filterName, anyOf(startsWith(CommonUtil.getWebPackageNameForServer(Server.GlassFish))));
105106
}
106107
}

integration-test/src/test/java/com/reajason/javaweb/integration/probe/glassfish/GlassFish6ContainerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.reajason.javaweb.memshell.ShellTool;
88
import com.reajason.javaweb.memshell.ShellType;
99
import com.reajason.javaweb.packer.Packers;
10+
import com.reajason.javaweb.utils.CommonUtil;
1011
import lombok.SneakyThrows;
1112
import lombok.extern.slf4j.Slf4j;
1213
import org.junit.jupiter.api.BeforeAll;
@@ -101,6 +102,6 @@ void testFilterFirstInject() {
101102
String data = VulTool.post(url + "/b64", DetectionTool.getGlassFishFilterProbe());
102103
List<String> filter = ProbeAssertion.getFiltersForContext(data, "/app");
103104
String filterName = ProbeAssertion.extractFilterName(filter.get(0));
104-
assertThat(filterName, anyOf(startsWith("org.apache.http.web.handlers")));
105+
assertThat(filterName, anyOf(startsWith(CommonUtil.getWebPackageNameForServer(Server.GlassFish))));
105106
}
106107
}

integration-test/src/test/java/com/reajason/javaweb/integration/probe/glassfish/GlassFish7ContainerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.reajason.javaweb.memshell.ShellTool;
88
import com.reajason.javaweb.memshell.ShellType;
99
import com.reajason.javaweb.packer.Packers;
10+
import com.reajason.javaweb.utils.CommonUtil;
1011
import lombok.SneakyThrows;
1112
import lombok.extern.slf4j.Slf4j;
1213
import org.junit.jupiter.api.AfterAll;
@@ -107,6 +108,6 @@ void testFilterFirstInject() {
107108
String data = VulTool.post(url + "/b64", DetectionTool.getGlassFishFilterProbe());
108109
List<String> filter = ProbeAssertion.getFiltersForContext(data, "/app");
109110
String filterName = ProbeAssertion.extractFilterName(filter.get(0));
110-
assertThat(filterName, anyOf(startsWith("org.apache.http.web.handlers")));
111+
assertThat(filterName, anyOf(startsWith(CommonUtil.getWebPackageNameForServer(Server.GlassFish))));
111112
}
112113
}

integration-test/src/test/java/com/reajason/javaweb/integration/probe/jbossas/Jboss423ContainerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.reajason.javaweb.memshell.ShellTool;
88
import com.reajason.javaweb.memshell.ShellType;
99
import com.reajason.javaweb.packer.Packers;
10+
import com.reajason.javaweb.utils.CommonUtil;
1011
import lombok.SneakyThrows;
1112
import lombok.extern.slf4j.Slf4j;
1213
import org.junit.jupiter.api.Test;
@@ -96,6 +97,6 @@ void testFilterFirstInject() {
9697
String data = VulTool.post(url + "/b64", DetectionTool.getTomcatFilterProbe());
9798
List<String> filter = ProbeAssertion.getFiltersForContext(data, "/app");
9899
String filterName = ProbeAssertion.extractFilterName(filter.get(0));
99-
assertThat(filterName, anyOf(startsWith("org.apache.http.web.handlers")));
100+
assertThat(filterName, anyOf(startsWith(CommonUtil.getWebPackageNameForServer(Server.GlassFish))));
100101
}
101102
}

integration-test/src/test/java/com/reajason/javaweb/integration/probe/jbossas/Jboss510ContainerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.reajason.javaweb.memshell.ShellTool;
88
import com.reajason.javaweb.memshell.ShellType;
99
import com.reajason.javaweb.packer.Packers;
10+
import com.reajason.javaweb.utils.CommonUtil;
1011
import lombok.SneakyThrows;
1112
import lombok.extern.slf4j.Slf4j;
1213
import org.junit.jupiter.api.Test;
@@ -94,6 +95,6 @@ void testFilterFirstInject() {
9495
String data = VulTool.post(url + "/b64", DetectionTool.getTomcatFilterProbe());
9596
List<String> filter = ProbeAssertion.getFiltersForContext(data, "/app");
9697
String filterName = ProbeAssertion.extractFilterName(filter.get(0));
97-
assertThat(filterName, anyOf(startsWith("org.apache.http.web.handlers")));
98+
assertThat(filterName, anyOf(startsWith(CommonUtil.getWebPackageNameForServer(Server.GlassFish))));
9899
}
99100
}

integration-test/src/test/java/com/reajason/javaweb/integration/probe/jbossas/Jboss610ContainerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.reajason.javaweb.memshell.ShellTool;
88
import com.reajason.javaweb.memshell.ShellType;
99
import com.reajason.javaweb.packer.Packers;
10+
import com.reajason.javaweb.utils.CommonUtil;
1011
import lombok.SneakyThrows;
1112
import lombok.extern.slf4j.Slf4j;
1213
import org.junit.jupiter.api.Test;
@@ -94,6 +95,6 @@ void testFilterFirstInject() {
9495
String data = VulTool.post(url + "/b64", DetectionTool.getTomcatFilterProbe());
9596
List<String> filter = ProbeAssertion.getFiltersForContext(data, "/app");
9697
String filterName = ProbeAssertion.extractFilterName(filter.get(0));
97-
assertThat(filterName, anyOf(startsWith("org.apache.http.web.handlers")));
98+
assertThat(filterName, anyOf(startsWith(CommonUtil.getWebPackageNameForServer(Server.GlassFish))));
9899
}
99100
}

0 commit comments

Comments
 (0)