forked from WebGoat/WebGoat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...jection/src/test/java/org/owasp/webgoat/plugin/introduction/SqlInjectionLesson6aTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.owasp.webgoat.plugin.introduction; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.owasp.webgoat.plugins.LessonTest; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
import org.springframework.test.web.servlet.result.MockMvcResultHandlers; | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.mockito.Mockito.when; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
/** | ||
* @author nbaars | ||
* @since 6/15/17. | ||
*/ | ||
@RunWith(SpringJUnit4ClassRunner.class) | ||
public class SqlInjectionLesson6aTest extends LessonTest { | ||
|
||
@Before | ||
public void setup() throws Exception { | ||
when(webSession.getCurrentLesson()).thenReturn(new SqlInjection()); | ||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); | ||
} | ||
|
||
@Test | ||
public void wrongSolution() throws Exception { | ||
mockMvc.perform(MockMvcRequestBuilders.post("/SqlInjection/attack6a") | ||
.param("userid_6a", "John")) | ||
.andDo(MockMvcResultHandlers.print()) | ||
.andExpect(status().isOk()) | ||
.andExpect(status().isOk()).andExpect(jsonPath("$.lessonCompleted", is(false))); | ||
} | ||
|
||
@Test | ||
public void wrongNumberOfColumns() throws Exception { | ||
mockMvc.perform(MockMvcRequestBuilders.post("/SqlInjection/attack6a") | ||
.param("userid_6a", "Smith' union select userid,user_name, password,cookie from user_system_data --")) | ||
.andDo(MockMvcResultHandlers.print()) | ||
.andExpect(status().isOk()) | ||
.andExpect(status().isOk()).andExpect(jsonPath("$.lessonCompleted", is(false))) | ||
.andExpect(jsonPath("$.output", is("column number mismatch detected in rows of UNION, INTERSECT, EXCEPT, or VALUES operation"))); | ||
} | ||
|
||
@Test | ||
public void wrongDataTypeOfColumns() throws Exception { | ||
mockMvc.perform(MockMvcRequestBuilders.post("/SqlInjection/attack6a") | ||
.param("userid_6a", "Smith' union select 1,password, 1,'2','3', '4',1 from user_system_data --")) | ||
.andDo(MockMvcResultHandlers.print()) | ||
.andExpect(status().isOk()) | ||
.andExpect(status().isOk()).andExpect(jsonPath("$.lessonCompleted", is(false))) | ||
.andExpect(jsonPath("$.output", containsString("incompatible data types in combination"))); | ||
} | ||
|
||
@Test | ||
public void correctSolution() throws Exception { | ||
mockMvc.perform(MockMvcRequestBuilders.post("/SqlInjection/attack6a") | ||
.param("userid_6a", "Smith' union select 1,password, '1','2','3', '4',1 from user_system_data --")) | ||
.andDo(MockMvcResultHandlers.print()) | ||
.andExpect(status().isOk()) | ||
.andExpect(status().isOk()).andExpect(jsonPath("$.lessonCompleted", is(true))) | ||
.andExpect(jsonPath("$.feedback", containsString("dave"))); | ||
} | ||
|
||
@Test | ||
public void noResultsReturned() throws Exception { | ||
mockMvc.perform(MockMvcRequestBuilders.post("/SqlInjection/attack6a") | ||
.param("userid_6a", "Smith' and 1 = 2 --")) | ||
.andDo(MockMvcResultHandlers.print()) | ||
.andExpect(status().isOk()) | ||
.andExpect(status().isOk()).andExpect(jsonPath("$.lessonCompleted", is(false))) | ||
.andExpect(jsonPath("$.feedback", is(messages.getMessage("sql-injection.6a.no.results")))); | ||
} | ||
|
||
|
||
} |