This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added CORS filter * Allow OPTIONS without auth * Broadened CORS pattern * Removed default CORS allow * Added some tests for WebSecurityConfiguration * Fixed spotbugs error * Closed more things down in CORS if no pattern is set --------- Co-authored-by: Shawn Sherwood <[email protected]>
- Loading branch information
1 parent
e0225ee
commit 9ba7647
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
cerberus-web/src/test/java/com/nike/cerberus/security/WebSecurityConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.nike.cerberus.security; | ||
|
||
import java.util.List; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.springframework.web.cors.CorsConfiguration; | ||
|
||
public class WebSecurityConfigurationTest { | ||
|
||
@Test | ||
public void testNoAllowedOriginPattern() { | ||
WebSecurityConfiguration wsc = new WebSecurityConfiguration(); | ||
CorsConfiguration config = new CorsConfiguration(); | ||
wsc.getConfigurationSource(config); | ||
Assert.assertEquals(config.getAllowedOriginPatterns(), null); | ||
Assert.assertEquals(config.getAllowedOrigins(), null); | ||
Assert.assertEquals(config.getAllowedHeaders(), null); | ||
Assert.assertEquals(config.getAllowedMethods(), null); | ||
Assert.assertFalse(config.getAllowCredentials()); | ||
} | ||
|
||
@Test | ||
public void testCustomAllowedOriginPattern() { | ||
WebSecurityConfiguration wsc = new WebSecurityConfiguration(); | ||
wsc.setAllowedOriginPattern("https://*.testdomain.com"); | ||
CorsConfiguration config = new CorsConfiguration(); | ||
wsc.getConfigurationSource(config); | ||
Assert.assertEquals(config.getAllowedOriginPatterns(), List.of("https://*.testdomain.com")); | ||
Assert.assertEquals(config.getAllowedOrigins(), null); | ||
Assert.assertEquals(config.getAllowedHeaders(), List.of("*")); | ||
Assert.assertEquals(config.getAllowedMethods(), List.of("*")); | ||
Assert.assertFalse(config.getAllowCredentials()); | ||
} | ||
} |