Skip to content

Commit

Permalink
test: apply csrf changes
Browse files Browse the repository at this point in the history
  • Loading branch information
laigasus committed May 6, 2024
1 parent 2342806 commit 7e4a330
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void setUp(WebApplicationContext webApplicationContext) {
@Test
@DisplayName("파일 업로드")
void upload() throws Exception {
URI uri = URI.create(fixtureMonkey.giveMeOne(String.class));
URI uri = URI.create("http://example.com");
given(fileUploadInputPort.upload(any())).willReturn(uri);

MockMultipartFile file =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package blisgo.infrastructure.internal.ui.view;

import static org.junit.jupiter.api.Assertions.*;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
Expand Down Expand Up @@ -38,7 +39,7 @@ public void setUp(WebApplicationContext webApplicationContext) {
@Test
@DisplayName("community board 페이지 호출")
void board() throws Exception {
mvc.perform(get("/community"))
mvc.perform(get("/community").with(csrf()))
.andExpect(status().isOk())
.andExpect(view().name(routes(Folder.COMMUNITY, Page.BOARD)));
}
Expand All @@ -48,7 +49,7 @@ void board() throws Exception {
void content() throws Exception {
var postId = randomGenerator.nextLong(1, Long.MAX_VALUE);

mvc.perform(get("/community/" + postId))
mvc.perform(get("/community/" + postId).with(csrf()))
.andExpect(status().isOk())
.andExpect(view().name(routes(Folder.COMMUNITY, Page.CONTENT)))
.andExpect(model().attribute("postId", postId));
Expand All @@ -59,7 +60,9 @@ void content() throws Exception {
void write() throws Exception {
var postId = randomGenerator.nextLong(1, Long.MAX_VALUE);

mvc.perform(get("/community/write").param("postId", Long.toString(postId)))
mvc.perform(get("/community/write")
.param("postId", Long.toString(postId))
.with(csrf()))
.andExpect(status().isOk())
.andExpect(view().name(routes(Folder.COMMUNITY, Page.WRITE)))
.andExpect(model().attribute("postId", postId));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package blisgo.infrastructure.internal.ui.view;

import static org.junit.jupiter.api.Assertions.*;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
Expand Down Expand Up @@ -38,7 +39,7 @@ public void setUp(WebApplicationContext webApplicationContext) {
@Test
@DisplayName("dictionary 페이지 호출")
void dictionary() throws Exception {
mvc.perform(get("/dictionary"))
mvc.perform(get("/dictionary").with(csrf()))
.andExpect(status().isOk())
.andExpect(view().name(routes(Folder.DICTIONARY, Page.CATALOGUE)));
}
Expand All @@ -48,7 +49,7 @@ void dictionary() throws Exception {
void product() throws Exception {
var wasteId = randomGenerator.nextLong(1, Long.MAX_VALUE);

mvc.perform(get("/dictionary/" + wasteId))
mvc.perform(get("/dictionary/" + wasteId).with(csrf()))
.andExpect(status().isOk())
.andExpect(view().name(routes(Folder.DICTIONARY, Page.INFO)))
.andExpect(model().attribute("wasteId", wasteId));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package blisgo.infrastructure.internal.ui.view;

import static org.junit.jupiter.api.Assertions.*;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
Expand Down Expand Up @@ -34,14 +35,15 @@ public void setUp(WebApplicationContext webApplicationContext) {
@Test
@DisplayName("index 페이지 호출")
void index() throws Exception {
mvc.perform(get("/"))
mvc.perform(get("/").with(csrf()))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(view().name(routes(Page.INDEX)));
}

@Test
@DisplayName("auth0 redirect")
void login() throws Exception {
mvc.perform(get("/login")).andExpect(MockMvcResultMatchers.status().is3xxRedirection());
mvc.perform(get("/login").with(csrf()))
.andExpect(MockMvcResultMatchers.status().is3xxRedirection());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package blisgo.infrastructure.internal.ui.view;

import static org.junit.jupiter.api.Assertions.*;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.oidcLogin;
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
Expand Down Expand Up @@ -44,7 +45,7 @@ public void setUp(WebApplicationContext webApplicationContext) {
@Test
@DisplayName("member login 페이지 호출")
void profile() throws Exception {
mvc.perform(get("/profile").with(oidcLogin()))
mvc.perform(get("/profile").with(oidcLogin()).with(csrf()))
.andExpect(status().isOk())
.andExpect(view().name(routes(Folder.MEMBER, Page.PROFILE)));
}
Expand Down

0 comments on commit 7e4a330

Please sign in to comment.