|
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 {
|
@@ -569,6 +571,33 @@ public void issuerWhenOidcConfigurationTlsClientAuthMethodThenSuccess() throws E
|
569 | 571 | .isEqualTo(ClientAuthenticationMethod.CLIENT_SECRET_BASIC);
|
570 | 572 | }
|
571 | 573 |
|
| 574 | + @Test |
| 575 | + public void issuerWhenAllEndpointsFailedThenExceptionIncludesFailureInformation() { |
| 576 | + this.issuer = createIssuerFromServer("issuer1"); |
| 577 | + this.server.setDispatcher(new Dispatcher() { |
| 578 | + @Override |
| 579 | + public MockResponse dispatch(RecordedRequest request) { |
| 580 | + int responseCode = switch (request.getPath()) { |
| 581 | + case "/issuer1/.well-known/openid-configuration" -> 405; |
| 582 | + case "/.well-known/openid-configuration/issuer1" -> 400; |
| 583 | + default -> 404; |
| 584 | + }; |
| 585 | + return new MockResponse().setResponseCode(responseCode); |
| 586 | + } |
| 587 | + }); |
| 588 | + String message = """ |
| 589 | + Unable to resolve Configuration with the provided Issuer of "%s", errors: [\ |
| 590 | + 405 Client Error on GET request for "%s": [no body], \ |
| 591 | + 400 Client Error on GET request for "%s": [no body], \ |
| 592 | + 404 Client Error on GET request for "%s": [no body]]\ |
| 593 | + """.formatted(this.issuer, this.server.url("/issuer1/.well-known/openid-configuration"), |
| 594 | + this.server.url("/.well-known/openid-configuration/issuer1"), |
| 595 | + this.server.url("/.well-known/oauth-authorization-server/issuer1")); |
| 596 | + assertThatExceptionOfType(IllegalArgumentException.class) |
| 597 | + .isThrownBy(() -> ClientRegistrations.fromIssuerLocation(this.issuer).build()) |
| 598 | + .withMessage(message); |
| 599 | + } |
| 600 | + |
572 | 601 | private ClientRegistration.Builder registration(String path) throws Exception {
|
573 | 602 | this.issuer = createIssuerFromServer(path);
|
574 | 603 | this.response.put("issuer", this.issuer);
|
|
0 commit comments