fix: Success if only Smith earn most salary (#1744)
* Update labels * Update Java * Update Test --------- Co-authored-by: René Zubcevic <rene@zubcevic.com>
This commit is contained in:
@ -37,123 +37,7 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
*/
|
||||
public class SqlInjectionLesson9Test extends SqlLessonTest {
|
||||
|
||||
private String completedError = "JSON path \"lessonCompleted\"";
|
||||
|
||||
@Test
|
||||
public void oneAccount() throws Exception {
|
||||
try {
|
||||
mockMvc
|
||||
.perform(
|
||||
MockMvcRequestBuilders.post("/SqlInjection/attack9")
|
||||
.param("name", "Smith")
|
||||
.param("auth_tan", "3SL99A"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("lessonCompleted", is(false)))
|
||||
.andExpect(jsonPath("$.feedback", is(messages.getMessage("sql-injection.9.one"))))
|
||||
.andExpect(jsonPath("$.output", containsString("<table><tr><th>")));
|
||||
} catch (AssertionError e) {
|
||||
if (!e.getMessage().contains(completedError)) throw e;
|
||||
|
||||
mockMvc
|
||||
.perform(
|
||||
MockMvcRequestBuilders.post("/SqlInjection/attack9")
|
||||
.param("name", "Smith")
|
||||
.param("auth_tan", "3SL99A"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("lessonCompleted", is(true)))
|
||||
.andExpect(jsonPath("$.feedback", is(messages.getMessage("sql-injection.9.success"))))
|
||||
.andExpect(jsonPath("$.output", containsString("<table><tr><th>")));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleAccounts() throws Exception {
|
||||
try {
|
||||
mockMvc
|
||||
.perform(
|
||||
MockMvcRequestBuilders.post("/SqlInjection/attack9")
|
||||
.param("name", "Smith")
|
||||
.param("auth_tan", "3SL99A' OR '1' = '1"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("lessonCompleted", is(false)))
|
||||
.andExpect(jsonPath("$.feedback", is(messages.getMessage("sql-injection.9.one"))))
|
||||
.andExpect(
|
||||
jsonPath(
|
||||
"$.output",
|
||||
containsString(
|
||||
"<tr><td>96134<\\/td><td>Bob<\\/td><td>Franco<\\/td><td>Marketing<\\/td><td>83700<\\/td><td>LO9S2V<\\/td><\\/tr>")));
|
||||
} catch (AssertionError e) {
|
||||
if (!e.getMessage().contains(completedError)) throw e;
|
||||
|
||||
mockMvc
|
||||
.perform(
|
||||
MockMvcRequestBuilders.post("/SqlInjection/attack9")
|
||||
.param("name", "Smith")
|
||||
.param("auth_tan", "3SL99A' OR '1' = '1"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("lessonCompleted", is(true)))
|
||||
.andExpect(jsonPath("$.feedback", is(messages.getMessage("sql-injection.9.success"))))
|
||||
.andExpect(
|
||||
jsonPath(
|
||||
"$.output",
|
||||
containsString(
|
||||
"<tr><td>96134<\\/td><td>Bob<\\/td><td>Franco<\\/td><td>Marketing<\\/td><td>83700<\\/td><td>LO9S2V<\\/td><\\/tr>")));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wrongNameReturnsNoAccounts() throws Exception {
|
||||
try {
|
||||
mockMvc
|
||||
.perform(
|
||||
MockMvcRequestBuilders.post("/SqlInjection/attack9")
|
||||
.param("name", "Smithh")
|
||||
.param("auth_tan", "3SL99A"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("lessonCompleted", is(false)))
|
||||
.andExpect(jsonPath("$.feedback", is(messages.getMessage("sql-injection.8.no.results"))))
|
||||
.andExpect(jsonPath("$.output").doesNotExist());
|
||||
} catch (AssertionError e) {
|
||||
if (!e.getMessage().contains(completedError)) throw e;
|
||||
|
||||
mockMvc
|
||||
.perform(
|
||||
MockMvcRequestBuilders.post("/SqlInjection/attack9")
|
||||
.param("name", "Smithh")
|
||||
.param("auth_tan", "3SL99A"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("lessonCompleted", is(true)))
|
||||
.andExpect(jsonPath("$.feedback", is(messages.getMessage("sql-injection.8.no.success"))))
|
||||
.andExpect(jsonPath("$.output").doesNotExist());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wrongTANReturnsNoAccounts() throws Exception {
|
||||
try {
|
||||
mockMvc
|
||||
.perform(
|
||||
MockMvcRequestBuilders.post("/SqlInjection/attack9")
|
||||
.param("name", "Smithh")
|
||||
.param("auth_tan", ""))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("lessonCompleted", is(false)))
|
||||
.andExpect(jsonPath("$.feedback", is(messages.getMessage("sql-injection.8.no.results"))))
|
||||
.andExpect(jsonPath("$.output").doesNotExist());
|
||||
} catch (AssertionError e) {
|
||||
if (!e.getMessage().contains(completedError)) throw e;
|
||||
|
||||
mockMvc
|
||||
.perform(
|
||||
MockMvcRequestBuilders.post("/SqlInjection/attack9")
|
||||
.param("name", "Smithh")
|
||||
.param("auth_tan", ""))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("lessonCompleted", is(true)))
|
||||
.andExpect(jsonPath("$.feedback", is(messages.getMessage("sql-injection.9.success"))))
|
||||
.andExpect(jsonPath("$.output").doesNotExist());
|
||||
}
|
||||
}
|
||||
private final String completedError = "JSON path \"lessonCompleted\"";
|
||||
|
||||
@Test
|
||||
public void malformedQueryReturnsError() throws Exception {
|
||||
@ -181,6 +65,44 @@ public class SqlInjectionLesson9Test extends SqlLessonTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void SmithIsNotMostEarning() throws Exception {
|
||||
mockMvc
|
||||
.perform(
|
||||
MockMvcRequestBuilders.post("/SqlInjection/attack9")
|
||||
.param("name", "Smith")
|
||||
.param(
|
||||
"auth_tan",
|
||||
"3SL99A'; UPDATE employees SET salary = 9999 WHERE last_name = 'Smith"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("lessonCompleted", is(false)))
|
||||
.andExpect(jsonPath("$.feedback", is(messages.getMessage("sql-injection.9.one"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void OnlySmithSalaryMustBeUpdated() throws Exception {
|
||||
mockMvc
|
||||
.perform(
|
||||
MockMvcRequestBuilders.post("/SqlInjection/attack9")
|
||||
.param("name", "Smith")
|
||||
.param("auth_tan", "3SL99A'; UPDATE employees SET salary = 9999 -- "))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("lessonCompleted", is(false)))
|
||||
.andExpect(jsonPath("$.feedback", is(messages.getMessage("sql-injection.9.one"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void OnlySmithMustMostEarning() throws Exception {
|
||||
mockMvc
|
||||
.perform(
|
||||
MockMvcRequestBuilders.post("/SqlInjection/attack9")
|
||||
.param("name", "'; UPDATE employees SET salary = 999999 -- ")
|
||||
.param("auth_tan", ""))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("lessonCompleted", is(false)))
|
||||
.andExpect(jsonPath("$.feedback", is(messages.getMessage("sql-injection.9.one"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void SmithIsMostEarningCompletesAssignment() throws Exception {
|
||||
mockMvc
|
||||
|
Reference in New Issue
Block a user