Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Setting] backend server에서 testcode 작성할때 security설정 #41

Open
minseo9974 opened this issue Feb 16, 2024 · 0 comments
Open
Labels
documentation 문서화가 필요할거 같습니다.

Comments

@minseo9974
Copy link
Contributor

minseo9974 commented Feb 16, 2024

📄 필수 사항

test환경에서는 인증 권한을 받기위해 pom.xml에서 security설정을 끄거나 @WIthMockUser를 써야하는데(401 에러 피하기위함)
저희는 @test 과함께 @WithMockUser를 사용하는것으로 하겠습니다

또한 controller 테스트에서 perform 부분에서

mockMvc.perform(post("/api/v1/users/join")
                        .with(csrf())

이런식으로 with(csrf())를 쓰시면 403 에러가 해결됩니다.

참고 사이트
@WebMvcTest 에서 Spring Security 적용했을때 401/403 에러 발생

다른 의견이 있으시면 댓글 부탁드립니다!

@minseo9974 minseo9974 added the documentation 문서화가 필요할거 같습니다. label Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation 문서화가 필요할거 같습니다.
Projects
None yet
Development

No branches or pull requests

1 participant