|  | 
| 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,33 @@ 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 on GET request for "%s": [no body], \ | 
|  | 477 | +				400 Client Error on GET request for "%s": [no body], \ | 
|  | 478 | +				404 Client Error on GET request for "%s": [no body]]\ | 
|  | 479 | +				""".formatted(this.issuer, this.server.url("/issuer1/.well-known/openid-configuration"), | 
|  | 480 | +				this.server.url("/.well-known/openid-configuration/issuer1"), | 
|  | 481 | +				this.server.url("/.well-known/oauth-authorization-server/issuer1")); | 
|  | 482 | +		assertThatExceptionOfType(IllegalArgumentException.class) | 
|  | 483 | +			.isThrownBy(() -> ClientRegistrations.fromIssuerLocation(this.issuer).build()) | 
|  | 484 | +			.withMessage(message); | 
|  | 485 | +	} | 
|  | 486 | + | 
| 458 | 487 | 	private ClientRegistration.Builder registration(String path) throws Exception { | 
| 459 | 488 | 		this.issuer = createIssuerFromServer(path); | 
| 460 | 489 | 		this.response.put("issuer", this.issuer); | 
|  | 
0 commit comments