-
카테고리
-
세부 분야
백엔드
-
해결 여부
미해결
Spring security test 수행시 @AuthenticationPrincipal 가 null 로 세팅됨
21.07.27 15:45 작성 조회수 364
0
안녕하세요
아래와 같이 Controller, 테스트 코드를 작성했습니다.
어플리케이션을 수행하고 로그인했을때는 정상적으로 사용자 정보가 출력이 되는데요
아래와 같이 테스트 코드를 수행했을때는 @AuthenticationPrincipal user 가 null 로 매핑이 됩니다.
해결 방법이 있을까요?
@GetMapping(path="test")
public String index(@AuthenticationPrincipal UserAccount user) {
log.info(user.getUser());
return "/index";
}
@Test
public void index() throws Exception {
// Given, When, Then
mockMvc.perform(get("/test")
.with(user("user").password("pwd").roles("USER")))
.andExpect(status().isOk())
.andExpect(authenticated())
;
}
답변을 작성해보세요.
1
답변 1