Security_test

🔥 Projects 🔥

[Security] @WithSecurityContext를 이용해 커스텀 UserDetails SecurityContext Test 코드 작성하기

선요약 커스텀하게 UserDetails를 구현해서 사용중이라면, SecurityContext의 인증된 유저 관련 테스트를 진행할 때 @WithMockUser를 사용할 수 없다. 컨텍스트에 인증된 유저를 배치하는 여러 방법 중 이런 상황에서 편리하고, 아주 유연한 처리가 가능한 @WithSecurityContext를 이용해 테스트 코드를 작성하는 법을 소개해본다. 1. @WithMockUser 사용하기 보통 Spring Security의 Security Context에 로그인된 유저 정보를 이용한 테스트를 진행할 때, 간편하게 `@WithMockUser` 어노테이션을 이용할 수 있다. 내 프로젝트의 Authentication Helper 클래스는 아래와 같이 현재 로그인한 유저를 Security Conte..

진호우!
'Security_test' 태그의 글 목록