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.
SQL: Cannot use apostrophe/quotes on string literals WebGoat#662
- Loading branch information
Showing
3 changed files
with
136 additions
and
70 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
87 changes: 87 additions & 0 deletions
87
...n/src/test/java/org/owasp/webgoat/sql_injection/introduction/SqlInjectionLesson5Test.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,87 @@ | ||
/* | ||
* This file is part of WebGoat, an Open Web Application Security Project utility. For details, please see http://www.owasp.org/ | ||
* | ||
* Copyright (c) 2002 - 2019 Bruce Mayhew | ||
* | ||
* This program is free software; you can redistribute it and/or modify it under the terms of the | ||
* GNU General Public License as published by the Free Software Foundation; either version 2 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without | ||
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with this program; if | ||
* not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | ||
* 02111-1307, USA. | ||
* | ||
* Getting Source ============== | ||
* | ||
* Source for this application is maintained at https://github.com/WebGoat/WebGoat, a repository for free software projects. | ||
*/ | ||
|
||
package org.owasp.webgoat.sql_injection.introduction; | ||
|
||
import org.hamcrest.CoreMatchers; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.owasp.webgoat.assignments.AssignmentEndpointTest; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
|
||
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; | ||
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class SqlInjectionLesson5Test extends AssignmentEndpointTest { | ||
|
||
private MockMvc mockMvc; | ||
|
||
@Before | ||
public void setup() { | ||
SqlInjectionLesson5 sql = new SqlInjectionLesson5(); | ||
init(sql); | ||
this.mockMvc = standaloneSetup(sql).build(); | ||
when(webSession.getCurrentLesson()).thenReturn(new SqlInjection()); | ||
|
||
} | ||
|
||
@Test | ||
public void grantSolution() throws Exception { | ||
mockMvc.perform(MockMvcRequestBuilders.post("/SqlInjection/attack5") | ||
.param("_query","grant alter table to unauthorizedUser")) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.output", CoreMatchers.containsString("grant"))) | ||
.andExpect(jsonPath("$.lessonCompleted", CoreMatchers.is(true))); | ||
} | ||
|
||
@Test | ||
public void grantSolutionWithQuotes() throws Exception { | ||
mockMvc.perform(MockMvcRequestBuilders.post("/SqlInjection/attack5") | ||
.param("_query","grant alter table to \"unauthorizedUser\"")) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.output", CoreMatchers.containsString("grant"))) | ||
.andExpect(jsonPath("$.lessonCompleted", CoreMatchers.is(true))); | ||
} | ||
|
||
@Test | ||
public void grantSolutionWithSingleQuotes() throws Exception { | ||
mockMvc.perform(MockMvcRequestBuilders.post("/SqlInjection/attack5") | ||
.param("_query","grant alter table to 'unauthorizedUser';")) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.output", CoreMatchers.containsString("grant"))) | ||
.andExpect(jsonPath("$.lessonCompleted", CoreMatchers.is(true))); | ||
} | ||
|
||
@Test | ||
public void grantSolutionWrong() throws Exception { | ||
mockMvc.perform(MockMvcRequestBuilders.post("/SqlInjection/attack5") | ||
.param("_query","grant alter table to me")) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.lessonCompleted", CoreMatchers.is(false))); | ||
} | ||
} |
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