diff options
Diffstat (limited to 'src/test/java/com/juick')
-rw-r--r-- | src/test/java/com/juick/server/tests/ServerTests.java | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java index 957da377..5eeeab3d 100644 --- a/src/test/java/com/juick/server/tests/ServerTests.java +++ b/src/test/java/com/juick/server/tests/ServerTests.java @@ -90,11 +90,13 @@ import org.springframework.core.io.Resource; import org.springframework.http.*; import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.mock.web.MockHttpSession; import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.context.TestPropertySource; import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.DigestUtils; @@ -2718,6 +2720,19 @@ public class ServerTests { } @Test + public void givenAccessSecuredResource_whenAuthenticated_thenRedirectedBack() throws Exception { + MockHttpServletRequestBuilder securedResourceAccess = get("/settings"); + MvcResult unauthenticatedResult = mockMvc.perform(securedResourceAccess).andExpect(status().is3xxRedirection()) + .andReturn(); + MockHttpSession session = (MockHttpSession) unauthenticatedResult.getRequest().getSession(); + String loginUrl = unauthenticatedResult.getResponse().getRedirectedUrl(); + mockMvc.perform(post(loginUrl).param("username", ugnichName).param("password", ugnichPassword) + .session(session).with(csrf())).andExpect(status().is3xxRedirection()) + .andExpect(redirectedUrlPattern("**/settings?continue")).andReturn(); + mockMvc.perform(securedResourceAccess.session(session)).andExpect(status().isOk()); + } +/* + @Test public void tokenAuth() throws Exception { var token = keystoreManager.generateToken(ugnich); mockMvc.perform(get("/api/me") @@ -2732,4 +2747,6 @@ public class ServerTests { .header("Authorization", "Bearer " + token)) .andExpect(status().isUnauthorized()); } + + */ } |