|
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.
|
|
37 | 37 | import org.springframework.web.util.UriComponents;
|
38 | 38 |
|
39 | 39 | import static org.assertj.core.api.Assertions.assertThat;
|
| 40 | +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
40 | 41 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
41 | 42 | import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
42 | 43 |
|
43 | 44 | /**
|
44 | 45 | * @author Rob Winch
|
45 | 46 | * @author Rafiullah Hamedy
|
| 47 | + * @author Evgeniy Cheban |
46 | 48 | * @since 5.1
|
47 | 49 | */
|
48 | 50 | public class ClientRegistrationsTests {
|
@@ -570,6 +572,33 @@ public void issuerWhenOidcConfigurationTlsClientAuthMethodThenSuccess() throws E
|
570 | 572 | .isEqualTo(ClientAuthenticationMethod.CLIENT_SECRET_BASIC);
|
571 | 573 | }
|
572 | 574 |
|
| 575 | + @Test |
| 576 | + public void issuerWhenAllEndpointsFailedThenExceptionIncludesFailureInformation() { |
| 577 | + this.issuer = createIssuerFromServer("issuer1"); |
| 578 | + this.server.setDispatcher(new Dispatcher() { |
| 579 | + @Override |
| 580 | + public MockResponse dispatch(RecordedRequest request) { |
| 581 | + int responseCode = switch (request.getPath()) { |
| 582 | + case "/issuer1/.well-known/openid-configuration" -> 405; |
| 583 | + case "/.well-known/openid-configuration/issuer1" -> 400; |
| 584 | + default -> 404; |
| 585 | + }; |
| 586 | + return new MockResponse().setResponseCode(responseCode); |
| 587 | + } |
| 588 | + }); |
| 589 | + String message = """ |
| 590 | + Unable to resolve Configuration with the provided Issuer of "%s", errors: [\ |
| 591 | + 405 Client Error on GET request for "%s": [no body], \ |
| 592 | + 400 Client Error on GET request for "%s": [no body], \ |
| 593 | + 404 Client Error on GET request for "%s": [no body]]\ |
| 594 | + """.formatted(this.issuer, this.server.url("/issuer1/.well-known/openid-configuration"), |
| 595 | + this.server.url("/.well-known/openid-configuration/issuer1"), |
| 596 | + this.server.url("/.well-known/oauth-authorization-server/issuer1")); |
| 597 | + assertThatExceptionOfType(IllegalArgumentException.class) |
| 598 | + .isThrownBy(() -> ClientRegistrations.fromIssuerLocation(this.issuer).build()) |
| 599 | + .withMessage(message); |
| 600 | + } |
| 601 | + |
573 | 602 | // gh-15852
|
574 | 603 | @Test
|
575 | 604 | public void oidcWhenHostContainsUnderscoreThenRetains() {
|
|
0 commit comments