Merge pull request #2773 from ilozano2/ilozano/cors-allowCredentials-typo

Correct typo in CORS listener
This commit is contained in:
Ryan Baxter
2022-11-08 09:35:40 -05:00
committed by GitHub
3 changed files with 7 additions and 3 deletions

View File

@@ -86,7 +86,7 @@ public class CorsGatewayFilterApplicationListener implements ApplicationListener
if (corsMetadata != null) {
final CorsConfiguration corsConfiguration = new CorsConfiguration();
findValue(corsMetadata, "allowCredential")
findValue(corsMetadata, "allowCredentials")
.ifPresent(value -> corsConfiguration.setAllowCredentials((Boolean) value));
findValue(corsMetadata, "allowedHeaders")
.ifPresent(value -> corsConfiguration.setAllowedHeaders(asList(value)));

View File

@@ -33,6 +33,7 @@ import org.springframework.test.context.ActiveProfiles;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
import static org.springframework.http.HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS;
import static org.springframework.http.HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN;
import static org.springframework.http.HttpHeaders.ACCESS_CONTROL_MAX_AGE;
@@ -50,12 +51,14 @@ public class CorsPerRouteTests extends BaseWebClientTests {
HttpHeaders responseHeaders = result.getResponseHeaders();
assertThat(responseHeaders.getAccessControlAllowOrigin())
.as(missingHeader(ACCESS_CONTROL_ALLOW_ORIGIN)).isEqualTo("*");
.as(missingHeader(ACCESS_CONTROL_ALLOW_ORIGIN)).isEqualTo("domain.com");
assertThat(responseHeaders.getAccessControlAllowMethods())
.as(missingHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS))
.containsExactlyInAnyOrder(HttpMethod.GET, HttpMethod.POST);
assertThat(responseHeaders.getAccessControlMaxAge()).as(missingHeader(ACCESS_CONTROL_MAX_AGE))
.isEqualTo(30L);
assertThat(responseHeaders.getAccessControlAllowCredentials()).as(missingHeader(ACCESS_CONTROL_ALLOW_CREDENTIALS))
.isEqualTo(true);
});
}

View File

@@ -8,9 +8,10 @@ spring:
- Path=/abc/**
metadata:
cors:
allowedOrigins: '*'
allowedOrigins: 'domain.com'
allowedMethods: [ GET, POST ]
allowedHeaders: '*'
allowCredentials: true
maxAge: 30
- id: cors_test
uri: ${test.uri}