From c471503ede9aad91193ff6f93966196e6aff15d6 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 4 Jan 2023 03:38:19 +0300 Subject: OAuth authentication for Mastodon and ActivityPub C2S --- src/test/java/com/juick/server/tests/ServerTests.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/test/java/com/juick/server/tests') 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; @@ -2717,6 +2719,19 @@ public class ServerTests { assertThat(descr.getDescription(), equalTo("Test")); } + @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); @@ -2732,4 +2747,6 @@ public class ServerTests { .header("Authorization", "Bearer " + token)) .andExpect(status().isUnauthorized()); } + + */ } -- cgit v1.2.3