Skip to content

Commit

Permalink
[CHORE] 테스트 코드 환경 설정 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekks committed Mar 18, 2024
1 parent d86bbda commit 329d30b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
Expand Down Expand Up @@ -51,8 +52,8 @@ SecurityFilterChain devSecurityFilterChain(HttpSecurity http) throws Exception {
(sessionManagement) -> sessionManagement.sessionCreationPolicy(
SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(
authorize -> authorize.requestMatchers(AUTH_WHITELIST).permitAll()
.requestMatchers(SWAGGER_URL).permitAll()
authorize -> authorize.requestMatchers(new AntPathRequestMatcher("/health/v2")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/docs/**")).permitAll()
.anyRequest().authenticated())
.addFilterBefore(
new JwtAuthenticationFilter(this.jwtTokenProvider, this.jwtAuthenticationEntryPoint),
Expand All @@ -62,6 +63,26 @@ SecurityFilterChain devSecurityFilterChain(HttpSecurity http) throws Exception {
return http.build();
}

@Bean
@Profile("test")
SecurityFilterChain testSecurityFilterChain(HttpSecurity http) throws Exception {
http.csrf((csrfConfig) -> csrfConfig.disable())
.cors(Customizer.withDefaults())
.sessionManagement(
(sessionManagement) -> sessionManagement.sessionCreationPolicy(
SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(
authorize -> authorize.requestMatchers(new AntPathRequestMatcher("/h2-console")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/docs/**")).permitAll()
.anyRequest().authenticated())
.addFilterBefore(
new JwtAuthenticationFilter(this.jwtTokenProvider, this.jwtAuthenticationEntryPoint),
UsernamePasswordAuthenticationFilter.class)
.exceptionHandling(exceptionHandling -> exceptionHandling
.authenticationEntryPoint(this.jwtAuthenticationEntryPoint));
return http.build();
}

@Bean
@Profile("prod")
SecurityFilterChain prodSecurityFilterChain(HttpSecurity http) throws Exception {
Expand Down
2 changes: 1 addition & 1 deletion main/src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
server:
port: 4000
port: 4000

spring:
config:
Expand Down

0 comments on commit 329d30b

Please sign in to comment.