File tree Expand file tree Collapse file tree 8 files changed +83
-4
lines changed Expand file tree Collapse file tree 8 files changed +83
-4
lines changed Original file line number Diff line number Diff line change 17
17
uses : actions/checkout@v4
18
18
19
19
- name : gradle 캐싱
20
- uses : gradle/actions/setup-gradle@v3
20
+ uses : gradle/actions/setup-gradle@v4
21
21
22
22
- name : bootJar로 jar 파일 생성
23
23
run : |
Original file line number Diff line number Diff line change 27
27
working-directory : ./backend/src/main/resources
28
28
run : echo "${{ secrets.APPLICATION_DB_YAML }}" > application-db.yml
29
29
30
+ - name : gradle 캐싱
31
+ uses : gradle/actions/setup-gradle@v4
32
+
30
33
- name : JDK 17 설정
31
34
uses : actions/setup-java@v4
32
35
with :
Original file line number Diff line number Diff line change
1
+ package codezap .global .cors ;
2
+
3
+
4
+ import org .springframework .boot .context .properties .ConfigurationProperties ;
5
+ import org .springframework .boot .context .properties .bind .DefaultValue ;
6
+
7
+ @ ConfigurationProperties (prefix = "cors" )
8
+ public class CorsProperties {
9
+ private final String [] allowedOrigins ;
10
+ private final String [] allowedOriginsPatterns ;
11
+
12
+ public CorsProperties (
13
+ @ DefaultValue (value = "" ) String [] allowedOrigins ,
14
+ @ DefaultValue (value = "" ) String [] allowedOriginsPatterns
15
+ ) {
16
+ this .allowedOrigins = allowedOrigins ;
17
+ this .allowedOriginsPatterns = allowedOriginsPatterns ;
18
+ }
19
+
20
+ public String [] getAllowedOrigins () {
21
+ return allowedOrigins ;
22
+ }
23
+
24
+ public String [] getAllowedOriginsPatterns () {
25
+ return allowedOriginsPatterns ;
26
+ }
27
+ }
Original file line number Diff line number Diff line change 1
1
package codezap .global .cors ;
2
2
3
+ import org .springframework .boot .context .properties .ConfigurationPropertiesScan ;
3
4
import org .springframework .context .annotation .Configuration ;
4
5
import org .springframework .web .servlet .config .annotation .CorsRegistry ;
5
6
import org .springframework .web .servlet .config .annotation .WebMvcConfigurer ;
6
7
7
8
@ Configuration
9
+ @ ConfigurationPropertiesScan
8
10
public class WebCorsConfiguration implements WebMvcConfigurer {
9
11
12
+ private final CorsProperties corsProperties ;
13
+
14
+ public WebCorsConfiguration (CorsProperties corsProperties ) {
15
+ this .corsProperties = corsProperties ;
16
+ }
17
+
10
18
@ Override
11
19
public void addCorsMappings (CorsRegistry registry ) {
12
20
registry .addMapping ("/**" )
13
21
.allowCredentials (true )
14
- .allowedOriginPatterns ("https://*.code-zap.com" )
15
- .allowedOrigins ("https://code-zap.com" )
16
- .allowedOrigins ("chrome-extension://bmlonhfgleihfabinjbhgefojkfpmlaf" )
22
+ .allowedOriginPatterns (corsProperties .getAllowedOriginsPatterns ())
23
+ .allowedOrigins (corsProperties .getAllowedOrigins ())
17
24
.allowedMethods ("*" )
18
25
.exposedHeaders ("*" );
19
26
}
Original file line number Diff line number Diff line change 2
2
output :
3
3
ansi :
4
4
enabled : always
5
+ cors :
6
+ allowed-origins : http://localhost:3000
Original file line number Diff line number Diff line change 6
6
7
7
import org .junit .jupiter .api .BeforeEach ;
8
8
import org .springframework .beans .factory .annotation .Autowired ;
9
+ import org .springframework .boot .context .properties .EnableConfigurationProperties ;
9
10
import org .springframework .boot .test .autoconfigure .web .servlet .WebMvcTest ;
10
11
import org .springframework .boot .test .mock .mockito .MockBean ;
12
+ import org .springframework .context .annotation .Import ;
11
13
import org .springframework .test .context .junit .jupiter .SpringExtension ;
12
14
import org .springframework .test .web .servlet .MockMvc ;
13
15
import org .springframework .test .web .servlet .setup .MockMvcBuilders ;
19
21
import codezap .auth .provider .CredentialProvider ;
20
22
import codezap .category .service .facade .MemberCategoryApplicationService ;
21
23
import codezap .category .service .facade .MemberCategoryTemplateApplicationService ;
24
+ import codezap .global .cors .CorsProperties ;
22
25
import codezap .member .fixture .MemberFixture ;
23
26
import codezap .member .service .MemberService ;
24
27
import codezap .template .service .TemplateService ;
25
28
26
29
@ WebMvcTest (SpringExtension .class )
30
+ @ EnableConfigurationProperties (CorsProperties .class )
27
31
public abstract class MockMvcTest {
28
32
29
33
@ Autowired
Original file line number Diff line number Diff line change
1
+ package codezap .global .cors ;
2
+
3
+ import static org .assertj .core .api .AssertionsForClassTypes .assertThat ;
4
+ import static org .junit .jupiter .api .Assertions .*;
5
+
6
+ import org .junit .jupiter .api .DisplayName ;
7
+ import org .junit .jupiter .api .Test ;
8
+ import org .junit .jupiter .api .extension .ExtendWith ;
9
+ import org .springframework .beans .factory .annotation .Autowired ;
10
+ import org .springframework .boot .context .properties .EnableConfigurationProperties ;
11
+ import org .springframework .boot .test .context .ConfigDataApplicationContextInitializer ;
12
+ import org .springframework .boot .test .context .SpringBootTest ;
13
+ import org .springframework .test .context .ContextConfiguration ;
14
+ import org .springframework .test .context .TestPropertySource ;
15
+ import org .springframework .test .context .junit .jupiter .SpringExtension ;
16
+
17
+ @ SpringBootTest
18
+ class CorsPropertiesTest {
19
+
20
+ @ Autowired
21
+ private CorsProperties corsProperties ;
22
+
23
+ @ Test
24
+ @ DisplayName ("yml 파일로부터 allowed-origins 값을 가져오는지 확인" )
25
+ void getAllowedOrigins () {
26
+ assertThat (corsProperties .getAllowedOrigins ()).isEqualTo (new String []{"http://localhost:3000" });
27
+ }
28
+
29
+ @ Test
30
+ @ DisplayName ("yml 파일로부터 allowed-origins-patterns 값을 가져오는지 확인" )
31
+ void getAllowedOriginsPatterns () {
32
+ assertThat (corsProperties .getAllowedOriginsPatterns ()).isEqualTo (new String []{"" });
33
+ }
34
+ }
Original file line number Diff line number Diff line change 2
2
output :
3
3
ansi :
4
4
enabled : always
5
+ cors :
6
+ allowed-origins : http://localhost:3000
You can’t perform that action at this time.
0 commit comments