@WebMvcTest 에서의 Authorization Header 및 jwt 추출 후 Authentication 세팅


@WebMvcTest 에서의 Authorization Header 및 jwt 추출 후 Authentication 세팅

요청이 오면 jwtFilter 에서 jwtProvider.getAuthentication(추출한 토큰 값) 을 통해서 토큰에 있는 필요한 값들을 추출해서 Authentication 객체에 담은 후 SecurityContextHolder 에 있는 context 에 세팅해서 사용하고 있다. @WebMvcTest 를 이용할 때 post("/stores").header("Authorization","Bearer (accessToken)") 이부분의 Authorization header 테스트 로직에서 유효시간이 있는 jwt 를 직접 넣어줄 수 없었기에 Bearer (accessToken) 로 restDocs 문서에 적히도록 해주었더니 jwtProvider.getAuthentication(추출한 토큰 값) 이 부분에서 null 이 들어와서 Authentication 에도 null 이 담겨서 테스트..........



원문링크 : @WebMvcTest 에서의 Authorization Header 및 jwt 추출 후 Authentication 세팅