Skip to content

Commit 8bf486b

Browse files
committed
Adding two vulnerabilities
1 parent 7be2968 commit 8bf486b

File tree

4 files changed

+40
-36
lines changed

4 files changed

+40
-36
lines changed

src/main/java/com/example/app/controller/GreetEndpointController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public String greet(@RequestParam(required = false, defaultValue = "World") Stri
2020
conn.createStatement().execute(query);
2121
conn.close();
2222
}
23-
} catch (SQLException ignored) {}
23+
} catch (SQLException ignored) {
24+
}
2425
}
2526

2627
return "Greetings " + name + "!";

src/main/java/com/example/app/controller/HelloEndpointController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public String hello(@RequestParam(required = false, defaultValue = "World") Stri
1414
String className = name.substring(8);
1515
try {
1616
Class.forName(className).getConstructor().newInstance();
17-
} catch (Exception ignored){}
17+
} catch (Exception ignored) {
18+
}
1819
}
1920
return "Hello " + name + "!";
2021
}

src/test/java/com/example/app/GreetEndpointTests.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,23 @@
2727

2828
@WebMvcTest()
2929
public class GreetEndpointTests {
30-
@Autowired private MockMvc mockMvc;
31-
32-
@Test
33-
public void unitTestGreetDeveloper() throws Exception {
34-
mockMvc.perform(get("/greet").param("name", "Developer"));
35-
}
36-
37-
@Test
38-
public void unitTestGreetContributor() throws Exception {
39-
mockMvc.perform(get("/greet").param("name", "Contributor"));
40-
}
41-
42-
@FuzzTest
43-
public void fuzzTestGreet(FuzzedDataProvider data) throws Exception {
44-
String name = data.consumeRemainingAsString();
45-
mockMvc.perform(get("/greet").param("name", name));
46-
}
30+
@Autowired
31+
private MockMvc mockMvc;
32+
33+
@Test
34+
public void unitTestGreetDeveloper() throws Exception {
35+
mockMvc.perform(get("/greet").param("name", "Developer"));
36+
}
37+
38+
@Test
39+
public void unitTestGreetContributor() throws Exception {
40+
mockMvc.perform(get("/greet").param("name", "Contributor"));
41+
}
42+
43+
@FuzzTest
44+
public void fuzzTestGreet(FuzzedDataProvider data) throws Exception {
45+
String name = data.consumeRemainingAsString();
46+
mockMvc.perform(get("/greet").param("name", name));
47+
}
4748

4849
}

src/test/java/com/example/app/HelloEndpointTests.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,23 @@
2727

2828
@WebMvcTest()
2929
public class HelloEndpointTests {
30-
@Autowired private MockMvc mockMvc;
31-
32-
@Test
33-
public void unitTestHelloDeveloper() throws Exception {
34-
mockMvc.perform(get("/hello").param("name", "Developer"));
35-
}
36-
37-
@Test
38-
public void unitTestHelloContributor() throws Exception {
39-
mockMvc.perform(get("/hello").param("name", "Contributor"));
40-
}
41-
42-
@FuzzTest
43-
public void fuzzTestHello(FuzzedDataProvider data) throws Exception {
44-
String name = data.consumeRemainingAsString();
45-
mockMvc.perform(get("/hello").param("name", name));
46-
}
30+
@Autowired
31+
private MockMvc mockMvc;
32+
33+
@Test
34+
public void unitTestHelloDeveloper() throws Exception {
35+
mockMvc.perform(get("/hello").param("name", "Developer"));
36+
}
37+
38+
@Test
39+
public void unitTestHelloContributor() throws Exception {
40+
mockMvc.perform(get("/hello").param("name", "Contributor"));
41+
}
42+
43+
@FuzzTest
44+
public void fuzzTestHello(FuzzedDataProvider data) throws Exception {
45+
String name = data.consumeRemainingAsString();
46+
mockMvc.perform(get("/hello").param("name", name));
47+
}
4748

4849
}

0 commit comments

Comments
 (0)