SpringSecurity MockMvc테스트시 발생

MockMvc 설정

//            val delegatingFilterProxy = DelegatingFilterProxy()
//            delegatingFilterProxy.init(MockFilterConfig(context.servletContext, BeanIds.SPRING_SECURITY_FILTER_CHAIN))
            this.mockMvc = MockMvcBuilders
                .webAppContextSetup(context)
//                .apply<DefaultMockMvcBuilder>(springSecurity())
//                .addFilters<DefaultMockMvcBuilder>(delegatingFilterProxy)
                .addFilters<DefaultMockMvcBuilder>(CharacterEncodingFilter("UTF-8", true))
                .alwaysDo<DefaultMockMvcBuilder>(MockMvcResultHandlers.print())
                .build()

test 설정

@WithMockKeycloakAuth(~~~)
@WithUserDetails("user1")
@Test
fun test() {
}

상태? 문제?

  1. Header인증을 사용하는 경우 no header -> jwt같은건 직접 header에 넣어줘야한다
    그렇다면 @Withannotation을 사용하기 힘들다는 뜻
  2. controller에 parameter로 Authentication을 받는경우 null – null… 어떻게 하지?
    SecurityContextHolder, TestSecurityContextHolder엔 들어있다
    WithSecurityContextTestExecutionListener: TestExecutionListener은 동작된다.
    principal = TestSecurityContextHolder.getContext()
  3. ???또 뭐가 있었던가

Leave a Reply

Your email address will not be published. Required fields are marked *

 characters available