aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2023-01-04 03:38:19 +0300
committerGravatar Vitaly Takmazov2023-01-04 05:46:16 +0300
commitc471503ede9aad91193ff6f93966196e6aff15d6 (patch)
tree8c70c8f58b140465be651cd019f26eadd476711f /src/test/java/com
parent086d9a7625bfc5a386f5b1028d364fb546c2fa9d (diff)
OAuth authentication for Mastodon and ActivityPub C2S
Diffstat (limited to 'src/test/java/com')
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java17
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());
}
+
+ */
}