woowacourse / tecoble-comments

0 stars 0 forks source link

post/2020-09-30-spring-security-test/ #42

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

Spring Security가 적용된 곳을 효율적으로 테스트하자.

Spring Security와 관련된 기능을 테스트하다보면 인증 정보를 미리 주입해야 하는 경우가 종종 발생한다. 기본적으로 생각할 수 있는 가장 간단한 방법은 테스트 전에 SecurityContext에 직접 Authentication…

https://tecoble.techcourse.co.kr/post/2020-09-30-spring-security-test/?utterances=6185669e0907230928ab0ec48Q37Stq4dGQwmPBl4jUwKRf9Qjc1EsagJzV%2BnhJK%2Fjnn%2FL1fMwpfbwKApVZTqSRXW258CXshrDPW%2BPqz8V8LjmDdbKrxa5qmfoFG2i4kt2WsBUUlVkBSsSRGVgE%3D

aliwo commented 2 years ago

잘 봤습니다! @WithUserDetails 를 사용하려구 하는데

@BeforeTransaction 을 사용해서 미리 찾고자 하는 유저를 넣어주어야 하는 군요! (추가적으로 찾아봐서 알았습니다~)

aliwo commented 2 years ago

앗.. @BeforeTransaction 을 써서 넣어버리면.. 트랜젝션 바깥에서 user 를 추가하게 되어서 디비에 user 가 남아있게 되네요 ㅠㅠ

minsoozz commented 2 years ago

@BeforEach => @BeforeEach 오타가 있어요~ 좋은 글 감사합니다😀

JmKanmo commented 2 years ago

개인적으로 코드가 좀 부실하네요;