Handle correctly * in CorsConfiguration#combine() other parameter

Issue: SPR-13674
This commit is contained in:
Sebastien Deleuze 2015-11-12 10:40:32 +01:00
parent e8a0ef0206
commit 71e2d8e9de
2 changed files with 11 additions and 7 deletions

View File

@ -17,7 +17,6 @@
package org.springframework.web.cors; package org.springframework.web.cors;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -103,7 +102,7 @@ public class CorsConfiguration {
} }
private List<String> combine(List<String> source, List<String> other) { private List<String> combine(List<String> source, List<String> other) {
if (other == null) { if (other == null || other.contains(ALL)) {
return source; return source;
} }
if (source == null || source.contains(ALL)) { if (source == null || source.contains(ALL)) {

View File

@ -114,11 +114,16 @@ public class CorsConfigurationTests {
other.addAllowedHeader("header1"); other.addAllowedHeader("header1");
other.addExposedHeader("header2"); other.addExposedHeader("header2");
other.addAllowedMethod(HttpMethod.PUT.name()); other.addAllowedMethod(HttpMethod.PUT.name());
config = config.combine(other); CorsConfiguration combinedConfig = config.combine(other);
assertEquals(Arrays.asList("http://domain.com"), config.getAllowedOrigins()); assertEquals(Arrays.asList("http://domain.com"), combinedConfig.getAllowedOrigins());
assertEquals(Arrays.asList("header1"), config.getAllowedHeaders()); assertEquals(Arrays.asList("header1"), combinedConfig.getAllowedHeaders());
assertEquals(Arrays.asList("header2"), config.getExposedHeaders()); assertEquals(Arrays.asList("header2"), combinedConfig.getExposedHeaders());
assertEquals(Arrays.asList(HttpMethod.PUT.name()), config.getAllowedMethods()); assertEquals(Arrays.asList(HttpMethod.PUT.name()), combinedConfig.getAllowedMethods());
combinedConfig = other.combine(config);
assertEquals(Arrays.asList("http://domain.com"), combinedConfig.getAllowedOrigins());
assertEquals(Arrays.asList("header1"), combinedConfig.getAllowedHeaders());
assertEquals(Arrays.asList("header2"), combinedConfig.getExposedHeaders());
assertEquals(Arrays.asList(HttpMethod.PUT.name()), combinedConfig.getAllowedMethods());
} }
@Test @Test