#1396 Fix templates path for views
This commit is contained in:
@ -18,7 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
@ -0,0 +1,103 @@
|
||||
package org.owasp.webgoat.lessons.passwordreset;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.owasp.webgoat.lessons.passwordreset.ResetLinkAssignment.TOM_EMAIL;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.owasp.webgoat.container.plugins.LessonTest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.test.web.servlet.MvcResult;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
class ResetLinkAssignmentTest extends LessonTest {
|
||||
|
||||
@Value("${webwolf.host}")
|
||||
private String webWolfHost;
|
||||
|
||||
@Value("${webwolf.port}")
|
||||
private String webWolfPort;
|
||||
|
||||
@Autowired private ResourceLoader resourceLoader;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
when(webSession.getCurrentLesson()).thenReturn(new PasswordReset());
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void wrongResetLink() throws Exception {
|
||||
MvcResult mvcResult =
|
||||
mockMvc
|
||||
.perform(
|
||||
MockMvcRequestBuilders.get("/PasswordReset/reset/reset-password/{link}", "test"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(view().name("lessons/passwordreset/templates/password_link_not_found.html"))
|
||||
.andReturn();
|
||||
Assertions.assertThat(resourceLoader.getResource(mvcResult.getModelAndView().getViewName()))
|
||||
.isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void changePasswordWithoutPasswordShouldReturnPasswordForm() throws Exception {
|
||||
MvcResult mvcResult =
|
||||
mockMvc
|
||||
.perform(MockMvcRequestBuilders.post("/PasswordReset/reset/change-password"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(view().name("lessons/passwordreset/templates/password_reset.html"))
|
||||
.andReturn();
|
||||
Assertions.assertThat(resourceLoader.getResource(mvcResult.getModelAndView().getViewName()))
|
||||
.isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void changePasswordWithoutLinkShouldReturnPasswordLinkNotFound() throws Exception {
|
||||
MvcResult mvcResult =
|
||||
mockMvc
|
||||
.perform(
|
||||
MockMvcRequestBuilders.post("/PasswordReset/reset/change-password")
|
||||
.param("password", "new_password"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(view().name("lessons/passwordreset/templates/password_link_not_found.html"))
|
||||
.andReturn();
|
||||
Assertions.assertThat(resourceLoader.getResource(mvcResult.getModelAndView().getViewName()))
|
||||
.isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void knownLinkShouldReturnPasswordResetPage() throws Exception {
|
||||
// Create a reset link
|
||||
mockMvc
|
||||
.perform(
|
||||
MockMvcRequestBuilders.post("/PasswordReset/ForgotPassword/create-password-reset-link")
|
||||
.param("email", TOM_EMAIL)
|
||||
.header(HttpHeaders.HOST, webWolfHost + ":" + webWolfPort))
|
||||
.andExpect(status().isOk());
|
||||
Assertions.assertThat(ResetLinkAssignment.resetLinks).isNotEmpty();
|
||||
|
||||
// With a known link you should be
|
||||
MvcResult mvcResult =
|
||||
mockMvc
|
||||
.perform(
|
||||
MockMvcRequestBuilders.get(
|
||||
"/PasswordReset/reset/reset-password/{link}",
|
||||
ResetLinkAssignment.resetLinks.get(0)))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(view().name("lessons/passwordreset/templates/password_reset.html"))
|
||||
.andReturn();
|
||||
|
||||
Assertions.assertThat(resourceLoader.getResource(mvcResult.getModelAndView().getViewName()))
|
||||
.isNotNull();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user