| 
21 | 21 | 
 
  | 
22 | 22 | @RunWith(SpringRunner.class)  | 
23 | 23 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,  | 
24 |  | -		properties = {"spring.cloud.discovery.enabled = false"})  | 
 | 24 | +        properties = {"spring.cloud.discovery.enabled = false"})  | 
25 | 25 | public class ApiGatewayApplicationTests {  | 
26 | 26 | 
 
  | 
27 |  | -	@Autowired  | 
28 |  | -	WebTestClient webTestClient;  | 
29 |  | - | 
30 |  | -	@MockBean  | 
31 |  | -	ReactiveJwtDecoder jwtDecoder;  | 
32 |  | - | 
33 |  | -	@Test  | 
34 |  | -	public void testCorsConfiguration() {  | 
35 |  | -		Jwt jwt = jwt();  | 
36 |  | -		when(this.jwtDecoder.decode(anyString())).thenReturn(Mono.just(jwt));  | 
37 |  | -		WebTestClient.ResponseSpec response = webTestClient.put()  | 
38 |  | -				.uri("/")  | 
39 |  | -				.headers(addJwt(jwt))  | 
40 |  | -				.header("Origin", "http://example.com")  | 
41 |  | -				.exchange();  | 
42 |  | - | 
43 |  | -		response.expectHeader().valueEquals("Access-Control-Allow-Origin", "*");  | 
44 |  | -	}  | 
45 |  | - | 
46 |  | -	private Jwt jwt() {  | 
47 |  | -		return new Jwt("token", null, null,  | 
48 |  | -				Map.of("alg", "none"), Map.of("sub", "dave"));  | 
49 |  | -	}  | 
50 |  | - | 
51 |  | -	private Consumer<HttpHeaders> addJwt(Jwt jwt) {  | 
52 |  | -		return headers -> headers.setBearerAuth(jwt.getTokenValue());  | 
53 |  | -	}  | 
 | 27 | +    @Autowired  | 
 | 28 | +    WebTestClient webTestClient;  | 
 | 29 | + | 
 | 30 | +    @MockBean  | 
 | 31 | +    ReactiveJwtDecoder jwtDecoder;  | 
 | 32 | + | 
 | 33 | +    @Test  | 
 | 34 | +    public void testCorsConfiguration() {  | 
 | 35 | +        Jwt jwt = jwt();  | 
 | 36 | +        when(this.jwtDecoder.decode(anyString())).thenReturn(Mono.just(jwt));  | 
 | 37 | +        WebTestClient.ResponseSpec response = webTestClient.put().uri("/")  | 
 | 38 | +                .headers(addJwt(jwt))  | 
 | 39 | +                .header("Origin", "http://example.com")  | 
 | 40 | +                .exchange();  | 
 | 41 | + | 
 | 42 | +        response.expectHeader().valueEquals("Access-Control-Allow-Origin", "*");  | 
 | 43 | +    }  | 
 | 44 | + | 
 | 45 | +    private Jwt jwt() {  | 
 | 46 | +        return new Jwt("token", null, null,  | 
 | 47 | +                Map.of("alg", "none"), Map.of("sub", "dave"));  | 
 | 48 | +    }  | 
 | 49 | + | 
 | 50 | +    private Consumer<HttpHeaders> addJwt(Jwt jwt) {  | 
 | 51 | +        return headers -> headers.setBearerAuth(jwt.getTokenValue());  | 
 | 52 | +    }  | 
54 | 53 | }  | 
0 commit comments