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.
Signed-off-by: Àngel Ollé Blázquez <[email protected]>
- Loading branch information
Showing
6 changed files
with
84 additions
and
8 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
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
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
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
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
76 changes: 76 additions & 0 deletions
76
...oss-site-scripting/src/test/java/org/owasp/webgoat/xss/CrossSiteScriptingLesson1Test.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,76 @@ | ||
/* | ||
* This file is part of WebGoat, an Open Web Application Security Project utility. For details, please see http://www.owasp.org/ | ||
* | ||
* Copyright (c) 2002 - 2021 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.xss; | ||
|
||
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; | ||
|
||
import org.hamcrest.CoreMatchers; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.owasp.webgoat.assignments.AssignmentEndpointTest; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
|
||
/** | ||
* | ||
* @author Angel Olle Blazquez | ||
* | ||
*/ | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class CrossSiteScriptingLesson1Test extends AssignmentEndpointTest { | ||
|
||
private static final String CONTEXT_PATH = "/CrossSiteScripting/attack1"; | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
CrossSiteScriptingLesson1 crossSiteScriptingLesson1 = new CrossSiteScriptingLesson1(); | ||
init(crossSiteScriptingLesson1); | ||
mockMvc = standaloneSetup(crossSiteScriptingLesson1).build(); | ||
} | ||
|
||
@Test | ||
void success() throws Exception { | ||
mockMvc.perform(MockMvcRequestBuilders.post(CONTEXT_PATH) | ||
.param("checkboxAttack1", "value")) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.lessonCompleted", CoreMatchers.is(true))); | ||
} | ||
|
||
@Test | ||
void failure() throws Exception { | ||
mockMvc.perform(MockMvcRequestBuilders.post(CONTEXT_PATH)) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.lessonCompleted", CoreMatchers.is(false))); | ||
} | ||
|
||
} |