11package com .Rootin .global .config ;
22
3+ import com .Rootin .global .filter .RateLimitFilter ;
4+ import com .fasterxml .jackson .databind .ObjectMapper ;
5+ import jakarta .servlet .http .HttpServletRequest ;
36import org .springframework .boot .test .context .TestConfiguration ;
47import org .springframework .context .annotation .Bean ;
8+ import org .springframework .context .annotation .Import ;
9+ import org .springframework .context .annotation .Primary ;
510import org .springframework .core .annotation .Order ;
611import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
712import org .springframework .security .config .annotation .web .configurers .AbstractHttpConfigurer ;
813import org .springframework .security .web .SecurityFilterChain ;
914
10- /**
11- * 테스트 전용 Security 설정
12- *
13- * 테스트 환경에서는 인증/인가를 검사하지 않도록 모든 요청을 permitAll 처리한다.
14- * @WebMvcTest 사용 시 @Import(TestSecurityConfig.class)로 가져와서 사용한다.
15- *
16- * 사용 예시:
17- * @WebMvcTest(controllers = SomeController.class)
18- * @Import(TestSecurityConfig.class)
19- * class SomeControllerTest { ... }
20- */
15+ @ Import (RateLimitConfig .class )
2116@ TestConfiguration
2217public class TestSecurityConfig {
18+
2319 @ Bean
24- @ Order (0 ) // 실제 SecurityConfig보다 우선 적용
20+ @ Order (0 )
2521 public SecurityFilterChain testFilterChain (HttpSecurity http ) throws Exception {
2622 http
2723 .csrf (AbstractHttpConfigurer ::disable )
2824 .authorizeHttpRequests (auth -> auth .anyRequest ().permitAll ());
2925 return http .build ();
3026 }
27+
28+ @ Bean
29+ @ Primary
30+ public RateLimitFilter rateLimitFilter (RateLimitConfig rateLimitConfig , ObjectMapper objectMapper ) {
31+ return new RateLimitFilter (rateLimitConfig , objectMapper ) {
32+ @ Override
33+ protected boolean shouldNotFilter (HttpServletRequest request ) {
34+ return true ;
35+ }
36+ };
37+ }
3138}
0 commit comments