|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2021 the original author or authors. |
| 2 | + * Copyright 2002-2025 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.
|
|
36 | 36 | import org.springframework.security.oauth2.core.ClientAuthenticationMethod;
|
37 | 37 |
|
38 | 38 | import static org.assertj.core.api.Assertions.assertThat;
|
| 39 | +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
39 | 40 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
40 | 41 | import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
41 | 42 |
|
42 | 43 | /**
|
43 | 44 | * @author Rob Winch
|
44 | 45 | * @author Rafiullah Hamedy
|
| 46 | + * @author Evgeniy Cheban |
45 | 47 | * @since 5.1
|
46 | 48 | */
|
47 | 49 | public class ClientRegistrationsTests {
|
@@ -455,6 +457,31 @@ public void issuerWhenOAuth2ConfigurationDoesNotMatchThenMeaningfulErrorMessage(
|
455 | 457 | // @formatter:on
|
456 | 458 | }
|
457 | 459 |
|
| 460 | + @Test |
| 461 | + public void issuerWhenAllEndpointsFailedThenExceptionIncludesFailureInformation() { |
| 462 | + this.issuer = createIssuerFromServer("issuer1"); |
| 463 | + this.server.setDispatcher(new Dispatcher() { |
| 464 | + @Override |
| 465 | + public MockResponse dispatch(RecordedRequest request) { |
| 466 | + int responseCode = switch (request.getPath()) { |
| 467 | + case "/issuer1/.well-known/openid-configuration" -> 405; |
| 468 | + case "/.well-known/openid-configuration/issuer1" -> 400; |
| 469 | + default -> 404; |
| 470 | + }; |
| 471 | + return new MockResponse().setResponseCode(responseCode); |
| 472 | + } |
| 473 | + }); |
| 474 | + String message = """ |
| 475 | + Unable to resolve Configuration with the provided Issuer of "%s", errors: [\ |
| 476 | + 405 Client Error: [no body], \ |
| 477 | + 400 Client Error: [no body], \ |
| 478 | + 404 Client Error: [no body]]\ |
| 479 | + """.formatted(this.issuer); |
| 480 | + assertThatExceptionOfType(IllegalArgumentException.class) |
| 481 | + .isThrownBy(() -> ClientRegistrations.fromIssuerLocation(this.issuer).build()) |
| 482 | + .withMessage(message); |
| 483 | + } |
| 484 | + |
458 | 485 | private ClientRegistration.Builder registration(String path) throws Exception {
|
459 | 486 | this.issuer = createIssuerFromServer(path);
|
460 | 487 | this.response.put("issuer", this.issuer);
|
|
0 commit comments