|
|
|
@ -34,10 +34,9 @@ import static org.junit.Assert.*; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class CorsConfigurationTests { |
|
|
|
public class CorsConfigurationTests { |
|
|
|
|
|
|
|
|
|
|
|
private CorsConfiguration config = new CorsConfiguration(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void setNullValues() { |
|
|
|
public void setNullValues() { |
|
|
|
|
|
|
|
CorsConfiguration config = new CorsConfiguration(); |
|
|
|
config.setAllowedOrigins(null); |
|
|
|
config.setAllowedOrigins(null); |
|
|
|
assertNull(config.getAllowedOrigins()); |
|
|
|
assertNull(config.getAllowedOrigins()); |
|
|
|
config.setAllowedHeaders(null); |
|
|
|
config.setAllowedHeaders(null); |
|
|
|
@ -54,6 +53,7 @@ public class CorsConfigurationTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void setValues() { |
|
|
|
public void setValues() { |
|
|
|
|
|
|
|
CorsConfiguration config = new CorsConfiguration(); |
|
|
|
config.addAllowedOrigin("*"); |
|
|
|
config.addAllowedOrigin("*"); |
|
|
|
assertEquals(Arrays.asList("*"), config.getAllowedOrigins()); |
|
|
|
assertEquals(Arrays.asList("*"), config.getAllowedOrigins()); |
|
|
|
config.addAllowedHeader("*"); |
|
|
|
config.addAllowedHeader("*"); |
|
|
|
@ -71,16 +71,19 @@ public class CorsConfigurationTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test(expected = IllegalArgumentException.class) |
|
|
|
@Test(expected = IllegalArgumentException.class) |
|
|
|
public void asteriskWildCardOnAddExposedHeader() { |
|
|
|
public void asteriskWildCardOnAddExposedHeader() { |
|
|
|
|
|
|
|
CorsConfiguration config = new CorsConfiguration(); |
|
|
|
config.addExposedHeader("*"); |
|
|
|
config.addExposedHeader("*"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test(expected = IllegalArgumentException.class) |
|
|
|
@Test(expected = IllegalArgumentException.class) |
|
|
|
public void asteriskWildCardOnSetExposedHeaders() { |
|
|
|
public void asteriskWildCardOnSetExposedHeaders() { |
|
|
|
|
|
|
|
CorsConfiguration config = new CorsConfiguration(); |
|
|
|
config.setExposedHeaders(Arrays.asList("*")); |
|
|
|
config.setExposedHeaders(Arrays.asList("*")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void combineWithNull() { |
|
|
|
public void combineWithNull() { |
|
|
|
|
|
|
|
CorsConfiguration config = new CorsConfiguration(); |
|
|
|
config.setAllowedOrigins(Arrays.asList("*")); |
|
|
|
config.setAllowedOrigins(Arrays.asList("*")); |
|
|
|
config.combine(null); |
|
|
|
config.combine(null); |
|
|
|
assertEquals(Arrays.asList("*"), config.getAllowedOrigins()); |
|
|
|
assertEquals(Arrays.asList("*"), config.getAllowedOrigins()); |
|
|
|
@ -88,6 +91,7 @@ public class CorsConfigurationTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void combineWithNullProperties() { |
|
|
|
public void combineWithNullProperties() { |
|
|
|
|
|
|
|
CorsConfiguration config = new CorsConfiguration(); |
|
|
|
config.addAllowedOrigin("*"); |
|
|
|
config.addAllowedOrigin("*"); |
|
|
|
config.addAllowedHeader("header1"); |
|
|
|
config.addAllowedHeader("header1"); |
|
|
|
config.addExposedHeader("header3"); |
|
|
|
config.addExposedHeader("header3"); |
|
|
|
@ -106,6 +110,7 @@ public class CorsConfigurationTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void combineWithAsteriskWildCard() { |
|
|
|
public void combineWithAsteriskWildCard() { |
|
|
|
|
|
|
|
CorsConfiguration config = new CorsConfiguration(); |
|
|
|
config.addAllowedOrigin("*"); |
|
|
|
config.addAllowedOrigin("*"); |
|
|
|
config.addAllowedHeader("*"); |
|
|
|
config.addAllowedHeader("*"); |
|
|
|
config.addAllowedMethod("*"); |
|
|
|
config.addAllowedMethod("*"); |
|
|
|
@ -128,6 +133,7 @@ public class CorsConfigurationTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void combine() { |
|
|
|
public void combine() { |
|
|
|
|
|
|
|
CorsConfiguration config = new CorsConfiguration(); |
|
|
|
config.addAllowedOrigin("http://domain1.com"); |
|
|
|
config.addAllowedOrigin("http://domain1.com"); |
|
|
|
config.addAllowedHeader("header1"); |
|
|
|
config.addAllowedHeader("header1"); |
|
|
|
config.addExposedHeader("header3"); |
|
|
|
config.addExposedHeader("header3"); |
|
|
|
@ -152,6 +158,7 @@ public class CorsConfigurationTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void checkOriginAllowed() { |
|
|
|
public void checkOriginAllowed() { |
|
|
|
|
|
|
|
CorsConfiguration config = new CorsConfiguration(); |
|
|
|
config.setAllowedOrigins(Arrays.asList("*")); |
|
|
|
config.setAllowedOrigins(Arrays.asList("*")); |
|
|
|
assertEquals("*", config.checkOrigin("http://domain.com")); |
|
|
|
assertEquals("*", config.checkOrigin("http://domain.com")); |
|
|
|
config.setAllowCredentials(true); |
|
|
|
config.setAllowCredentials(true); |
|
|
|
@ -164,6 +171,7 @@ public class CorsConfigurationTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void checkOriginNotAllowed() { |
|
|
|
public void checkOriginNotAllowed() { |
|
|
|
|
|
|
|
CorsConfiguration config = new CorsConfiguration(); |
|
|
|
assertNull(config.checkOrigin(null)); |
|
|
|
assertNull(config.checkOrigin(null)); |
|
|
|
assertNull(config.checkOrigin("http://domain.com")); |
|
|
|
assertNull(config.checkOrigin("http://domain.com")); |
|
|
|
config.addAllowedOrigin("*"); |
|
|
|
config.addAllowedOrigin("*"); |
|
|
|
@ -176,6 +184,7 @@ public class CorsConfigurationTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void checkMethodAllowed() { |
|
|
|
public void checkMethodAllowed() { |
|
|
|
|
|
|
|
CorsConfiguration config = new CorsConfiguration(); |
|
|
|
assertEquals(Arrays.asList(HttpMethod.GET, HttpMethod.HEAD), config.checkHttpMethod(HttpMethod.GET)); |
|
|
|
assertEquals(Arrays.asList(HttpMethod.GET, HttpMethod.HEAD), config.checkHttpMethod(HttpMethod.GET)); |
|
|
|
config.addAllowedMethod("GET"); |
|
|
|
config.addAllowedMethod("GET"); |
|
|
|
assertEquals(Arrays.asList(HttpMethod.GET), config.checkHttpMethod(HttpMethod.GET)); |
|
|
|
assertEquals(Arrays.asList(HttpMethod.GET), config.checkHttpMethod(HttpMethod.GET)); |
|
|
|
@ -186,6 +195,7 @@ public class CorsConfigurationTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void checkMethodNotAllowed() { |
|
|
|
public void checkMethodNotAllowed() { |
|
|
|
|
|
|
|
CorsConfiguration config = new CorsConfiguration(); |
|
|
|
assertNull(config.checkHttpMethod(null)); |
|
|
|
assertNull(config.checkHttpMethod(null)); |
|
|
|
assertNull(config.checkHttpMethod(HttpMethod.DELETE)); |
|
|
|
assertNull(config.checkHttpMethod(HttpMethod.DELETE)); |
|
|
|
config.setAllowedMethods(new ArrayList<>()); |
|
|
|
config.setAllowedMethods(new ArrayList<>()); |
|
|
|
@ -194,6 +204,7 @@ public class CorsConfigurationTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void checkHeadersAllowed() { |
|
|
|
public void checkHeadersAllowed() { |
|
|
|
|
|
|
|
CorsConfiguration config = new CorsConfiguration(); |
|
|
|
assertEquals(Collections.emptyList(), config.checkHeaders(Collections.emptyList())); |
|
|
|
assertEquals(Collections.emptyList(), config.checkHeaders(Collections.emptyList())); |
|
|
|
config.addAllowedHeader("header1"); |
|
|
|
config.addAllowedHeader("header1"); |
|
|
|
config.addAllowedHeader("header2"); |
|
|
|
config.addAllowedHeader("header2"); |
|
|
|
@ -204,13 +215,11 @@ public class CorsConfigurationTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void checkHeadersNotAllowed() { |
|
|
|
public void checkHeadersNotAllowed() { |
|
|
|
|
|
|
|
CorsConfiguration config = new CorsConfiguration(); |
|
|
|
assertNull(config.checkHeaders(null)); |
|
|
|
assertNull(config.checkHeaders(null)); |
|
|
|
|
|
|
|
|
|
|
|
assertNull(config.checkHeaders(Arrays.asList("header1"))); |
|
|
|
assertNull(config.checkHeaders(Arrays.asList("header1"))); |
|
|
|
|
|
|
|
|
|
|
|
config.setAllowedHeaders(Collections.emptyList()); |
|
|
|
config.setAllowedHeaders(Collections.emptyList()); |
|
|
|
assertNull(config.checkHeaders(Arrays.asList("header1"))); |
|
|
|
assertNull(config.checkHeaders(Arrays.asList("header1"))); |
|
|
|
|
|
|
|
|
|
|
|
config.addAllowedHeader("header2"); |
|
|
|
config.addAllowedHeader("header2"); |
|
|
|
config.addAllowedHeader("header3"); |
|
|
|
config.addAllowedHeader("header3"); |
|
|
|
assertNull(config.checkHeaders(Arrays.asList("header1"))); |
|
|
|
assertNull(config.checkHeaders(Arrays.asList("header1"))); |
|
|
|
|