|
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 { |
@@ -581,6 +583,33 @@ public void oidcWhenHostContainsUnderscoreThenRetains() { |
581 | 583 | assertThat(oidcRfc8414.getHost()).isEqualTo("elated_sutherland"); |
582 | 584 | } |
583 | 585 |
|
| 586 | + @Test |
| 587 | + public void issuerWhenAllEndpointsFailedThenExceptionIncludesFailureInformation() { |
| 588 | + this.issuer = createIssuerFromServer("issuer1"); |
| 589 | + this.server.setDispatcher(new Dispatcher() { |
| 590 | + @Override |
| 591 | + public MockResponse dispatch(RecordedRequest request) { |
| 592 | + int responseCode = switch (request.getPath()) { |
| 593 | + case "/issuer1/.well-known/openid-configuration" -> 405; |
| 594 | + case "/.well-known/openid-configuration/issuer1" -> 400; |
| 595 | + default -> 404; |
| 596 | + }; |
| 597 | + return new MockResponse().setResponseCode(responseCode); |
| 598 | + } |
| 599 | + }); |
| 600 | + String message = """ |
| 601 | + Unable to resolve Configuration with the provided Issuer of "%s", errors: [\ |
| 602 | + 405 Client Error on GET request for "%s": [no body], \ |
| 603 | + 400 Client Error on GET request for "%s": [no body], \ |
| 604 | + 404 Client Error on GET request for "%s": [no body]]\ |
| 605 | + """.formatted(this.issuer, this.server.url("/issuer1/.well-known/openid-configuration"), |
| 606 | + this.server.url("/.well-known/openid-configuration/issuer1"), |
| 607 | + this.server.url("/.well-known/oauth-authorization-server/issuer1")); |
| 608 | + assertThatExceptionOfType(IllegalArgumentException.class) |
| 609 | + .isThrownBy(() -> ClientRegistrations.fromIssuerLocation(this.issuer).build()) |
| 610 | + .withMessage(message); |
| 611 | + } |
| 612 | + |
584 | 613 | private ClientRegistration.Builder registration(String path) throws Exception { |
585 | 614 | this.issuer = createIssuerFromServer(path); |
586 | 615 | this.response.put("issuer", this.issuer); |
|
0 commit comments