Skip to content

Commit 7bb560a

Browse files
committed
test: add generate controller test case
1 parent 590cb7d commit 7bb560a

File tree

3 files changed

+62
-15
lines changed

3 files changed

+62
-15
lines changed

boot/src/main/java/com/reajason/javaweb/boot/dto/MemShellGenerateRequest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import com.reajason.javaweb.memshell.config.*;
44
import com.reajason.javaweb.packer.Packers;
5-
import com.reajason.javaweb.utils.CommonUtil;
65
import lombok.Data;
7-
import org.apache.commons.lang3.StringUtils;
86

97
import static com.reajason.javaweb.memshell.ShellTool.*;
108

@@ -20,7 +18,7 @@ public class MemShellGenerateRequest {
2018
private Packers packer;
2119

2220
@Data
23-
static class ShellToolConfigDTO {
21+
public static class ShellToolConfigDTO {
2422
private String shellClassName;
2523
private String godzillaPass;
2624
private String godzillaKey;

boot/src/test/java/com/reajason/javaweb/boot/controller/ConfigControllerIntegrationTest.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,21 @@ public class ConfigControllerIntegrationTest {
2727
@Test
2828
public void testConfigEndpoint() {
2929
ResponseEntity<Map> response = restTemplate.getForEntity("/config", Map.class);
30-
3130
assertEquals(HttpStatus.OK, response.getStatusCode());
32-
33-
Map body = response.getBody();
34-
assertNotNull(body);
31+
assertNotNull(response.getBody());
3532
}
3633

3734
@Test
3835
public void testConfigServersEndpoint() {
3936
ResponseEntity<Map> response = restTemplate.getForEntity("/config/servers", Map.class);
40-
4137
assertEquals(HttpStatus.OK, response.getStatusCode());
42-
43-
Map body = response.getBody();
44-
assertNotNull(body);
38+
assertNotNull(response.getBody());
4539
}
4640

4741
@Test
4842
public void testConfigPackersEndpoint() {
4943
ResponseEntity<List> response = restTemplate.getForEntity("/config/packers", List.class);
50-
5144
assertEquals(HttpStatus.OK, response.getStatusCode());
52-
53-
List<String> body = response.getBody();
54-
assertNotNull(body);
45+
assertNotNull(response.getBody());
5546
}
5647
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.reajason.javaweb.boot.controller;
2+
3+
import com.reajason.javaweb.Server;
4+
import com.reajason.javaweb.boot.dto.MemShellGenerateRequest;
5+
import com.reajason.javaweb.boot.dto.MemShellGenerateResponse;
6+
import com.reajason.javaweb.memshell.ShellTool;
7+
import com.reajason.javaweb.memshell.ShellType;
8+
import com.reajason.javaweb.memshell.config.InjectorConfig;
9+
import com.reajason.javaweb.memshell.config.ShellConfig;
10+
import com.reajason.javaweb.packer.Packers;
11+
import org.junit.jupiter.api.Test;
12+
import org.springframework.beans.factory.annotation.Autowired;
13+
import org.springframework.boot.test.context.SpringBootTest;
14+
import org.springframework.boot.test.web.client.TestRestTemplate;
15+
import org.springframework.http.HttpStatus;
16+
import org.springframework.http.ResponseEntity;
17+
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertNotNull;
20+
21+
/**
22+
* @author ReaJason
23+
* @since 2025/9/16
24+
*/
25+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
26+
class MemShellGeneratorControllerTest {
27+
28+
@Autowired
29+
TestRestTemplate restTemplate;
30+
31+
@Test
32+
void generateShell() {
33+
MemShellGenerateRequest request = new MemShellGenerateRequest();
34+
request.setShellConfig(ShellConfig.builder()
35+
.server(Server.Tomcat)
36+
.shellType(ShellType.FILTER)
37+
.shellTool(ShellTool.Godzilla)
38+
.shrink(true)
39+
.debug(true)
40+
.serverVersion("Unknown")
41+
.targetJreVersion(50)
42+
.build());
43+
request.setInjectorConfig(InjectorConfig.builder()
44+
.urlPattern("/*")
45+
.build());
46+
request.setPacker(Packers.ScriptEngine);
47+
MemShellGenerateRequest.ShellToolConfigDTO shellToolConfigDTO = new MemShellGenerateRequest.ShellToolConfigDTO();
48+
shellToolConfigDTO.setGodzillaKey("key");
49+
shellToolConfigDTO.setGodzillaPass("pass");
50+
shellToolConfigDTO.setHeaderName("User-Agent");
51+
shellToolConfigDTO.setHeaderValue("hello");
52+
request.setShellToolConfig(shellToolConfigDTO);
53+
ResponseEntity<MemShellGenerateResponse> response = restTemplate.postForEntity(
54+
"/memshell/generate", request, MemShellGenerateResponse.class);
55+
assertEquals(HttpStatus.OK, response.getStatusCode());
56+
assertNotNull(response.getBody());
57+
}
58+
}

0 commit comments

Comments
 (0)