|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2020 the original author or authors. |
| 2 | + * Copyright 2012-2021 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
16 | 16 |
|
17 | 17 | package org.springframework.boot.actuate.autoconfigure.integrationtest;
|
18 | 18 |
|
19 |
| -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.options; |
20 |
| -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
21 |
| - |
22 | 19 | import java.util.function.Consumer;
|
23 | 20 |
|
24 | 21 | import org.junit.jupiter.api.Test;
|
@@ -74,6 +71,19 @@ void settingAllowedOriginsEnablesCors() {
|
74 | 71 | }));
|
75 | 72 | }
|
76 | 73 |
|
| 74 | + @Test |
| 75 | + void settingAllowedOriginPatternsEnablesCors() { |
| 76 | + this.contextRunner |
| 77 | + .withPropertyValues("management.endpoints.web.cors.allowed-origin-patterns:*.example.org", |
| 78 | + "management.endpoints.web.cors.allow-credentials:true") |
| 79 | + .run(withWebTestClient((webTestClient) -> { |
| 80 | + webTestClient.options().uri("/actuator/beans").header("Origin", "spring.example.com") |
| 81 | + .header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "GET").exchange().expectStatus() |
| 82 | + .isForbidden(); |
| 83 | + performAcceptedCorsRequest(webTestClient, "/actuator/beans"); |
| 84 | + })); |
| 85 | + } |
| 86 | + |
77 | 87 | @Test
|
78 | 88 | void maxAgeDefaultsTo30Minutes() {
|
79 | 89 | this.contextRunner.withPropertyValues("management.endpoints.web.cors.allowed-origins:spring.example.org")
|
@@ -148,29 +158,6 @@ void credentialsCanBeDisabled() {
|
148 | 158 | .expectHeader().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS)));
|
149 | 159 | }
|
150 | 160 |
|
151 |
| - @Test |
152 |
| - void settingAllowedOriginsPattern() { |
153 |
| - this.contextRunner |
154 |
| - .withPropertyValues("management.endpoints.web.cors.allowed-origin-patterns:*.example.com", |
155 |
| - "management.endpoints.web.cors.allow-credentials:true") |
156 |
| - .run(withWebTestClient((webTestClient) -> webTestClient.options().uri("/actuator/beans") |
157 |
| - .header("Origin", "spring.example.com") |
158 |
| - .header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "HEAD").exchange().expectStatus().isOk() |
159 |
| - .expectHeader().valueEquals(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "GET,HEAD"))); |
160 |
| - } |
161 |
| - |
162 |
| - @Test |
163 |
| - void requestsWithDisallowedOriginPatternsAreRejected() { |
164 |
| - this.contextRunner |
165 |
| - .withPropertyValues("management.endpoints.web.cors.allowed-origin-patterns:*.example.com", |
166 |
| - "management.endpoints.web.cors.allow-credentials:true") |
167 |
| - .run(withWebTestClient((webTestClient) -> webTestClient.options().uri("/actuator/beans") |
168 |
| - .header("Origin", "spring.example.org") |
169 |
| - .header(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, "HEAD").exchange().expectStatus() |
170 |
| - .isForbidden())); |
171 |
| - |
172 |
| - } |
173 |
| - |
174 | 161 | private ContextConsumer<ReactiveWebApplicationContext> withWebTestClient(Consumer<WebTestClient> webTestClient) {
|
175 | 162 | return (context) -> webTestClient.accept(WebTestClient.bindToApplicationContext(context).configureClient()
|
176 | 163 | .baseUrl("https://spring.example.org").build());
|
|
0 commit comments