|
29 | 29 | import org.junit.jupiter.api.AfterEach;
|
30 | 30 | import org.junit.jupiter.api.BeforeEach;
|
31 | 31 | import org.junit.jupiter.api.Test;
|
32 |
| - |
33 | 32 | import org.springframework.http.HttpHeaders;
|
34 | 33 | import org.springframework.http.MediaType;
|
35 | 34 | import org.springframework.security.oauth2.core.AuthorizationGrantType;
|
@@ -455,6 +454,120 @@ public void issuerWhenOAuth2ConfigurationDoesNotMatchThenMeaningfulErrorMessage(
|
455 | 454 | // @formatter:on
|
456 | 455 | }
|
457 | 456 |
|
| 457 | + @Test |
| 458 | + public void issuerWhenOidcConfigurationAllInformationThenSuccess() throws Exception { |
| 459 | + ClientRegistration registration = registration(this.response).build(); |
| 460 | + ClientRegistration.ProviderDetails provider = registration.getProviderDetails(); |
| 461 | + assertIssuerMetadata(registration, provider); |
| 462 | + assertThat(provider.getUserInfoEndpoint().getUri()).isEqualTo("https://example.com/oauth2/v3/userinfo"); |
| 463 | + } |
| 464 | + |
| 465 | + private ClientRegistration.Builder registration(Map<String, Object> configuration) { |
| 466 | + this.issuer = "https://example.com"; |
| 467 | + return ClientRegistrations.fromOidcConfiguration(configuration) |
| 468 | + .clientId("client-id") |
| 469 | + .clientSecret("client-secret"); |
| 470 | + } |
| 471 | + |
| 472 | + @Test |
| 473 | + public void issuerWhenOidcConfigurationResponseMissingJwksUriThenThrowsIllegalArgumentException() throws Exception { |
| 474 | + this.response.remove("jwks_uri"); |
| 475 | + assertThatIllegalArgumentException().isThrownBy(() -> registration(this.response).build()) |
| 476 | + .withMessageContaining("The public JWK set URI must not be null"); |
| 477 | + } |
| 478 | + |
| 479 | + @Test |
| 480 | + public void issuerWhenOidcConfigurationResponseMissingUserInfoUriThenSuccess() throws Exception { |
| 481 | + this.response.remove("userinfo_endpoint"); |
| 482 | + ClientRegistration registration = registration(this.response).build(); |
| 483 | + assertThat(registration.getProviderDetails().getUserInfoEndpoint().getUri()).isNull(); |
| 484 | + } |
| 485 | + |
| 486 | + @Test |
| 487 | + public void issuerWhenOidcConfigurationGrantTypesSupportedNullThenDefaulted() throws Exception { |
| 488 | + this.response.remove("grant_types_supported"); |
| 489 | + ClientRegistration registration = registration(this.response).build(); |
| 490 | + assertThat(registration.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.AUTHORIZATION_CODE); |
| 491 | + } |
| 492 | + |
| 493 | + @Test |
| 494 | + public void issuerWhenOidcConfigurationImplicitGrantTypeThenSuccess() throws Exception { |
| 495 | + this.response.put("grant_types_supported", Arrays.asList("implicit")); |
| 496 | + ClientRegistration registration = registration(this.response).build(); |
| 497 | + // The authorization_code grant type is still the default |
| 498 | + assertThat(registration.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.AUTHORIZATION_CODE); |
| 499 | + } |
| 500 | + |
| 501 | + @Test |
| 502 | + public void issuerWhenOidcConfigurationResponseAuthorizationEndpointIsNullThenSuccess() throws Exception { |
| 503 | + this.response.put("grant_types_supported", Arrays.asList("urn:ietf:params:oauth:grant-type:jwt-bearer")); |
| 504 | + this.response.remove("authorization_endpoint"); |
| 505 | + ClientRegistration registration = registration(this.response) |
| 506 | + .authorizationGrantType(AuthorizationGrantType.JWT_BEARER) |
| 507 | + .build(); |
| 508 | + assertThat(registration.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.JWT_BEARER); |
| 509 | + ClientRegistration.ProviderDetails provider = registration.getProviderDetails(); |
| 510 | + assertThat(provider.getAuthorizationUri()).isNull(); |
| 511 | + } |
| 512 | + |
| 513 | + @Test |
| 514 | + public void issuerWhenOidcConfigurationTokenEndpointAuthMethodsNullThenDefaulted() throws Exception { |
| 515 | + this.response.remove("token_endpoint_auth_methods_supported"); |
| 516 | + ClientRegistration registration = registration(this.response).build(); |
| 517 | + assertThat(registration.getClientAuthenticationMethod()) |
| 518 | + .isEqualTo(ClientAuthenticationMethod.CLIENT_SECRET_BASIC); |
| 519 | + } |
| 520 | + |
| 521 | + @Test |
| 522 | + public void issuerWhenOidcConfigurationClientSecretBasicAuthMethodThenMethodIsBasic() throws Exception { |
| 523 | + this.response.put("token_endpoint_auth_methods_supported", Arrays.asList("client_secret_basic")); |
| 524 | + ClientRegistration registration = registration(this.response).build(); |
| 525 | + assertThat(registration.getClientAuthenticationMethod()) |
| 526 | + .isEqualTo(ClientAuthenticationMethod.CLIENT_SECRET_BASIC); |
| 527 | + } |
| 528 | + |
| 529 | + @Test |
| 530 | + public void issuerWhenOidcConfigurationTokenEndpointAuthMethodsPostThenMethodIsPost() throws Exception { |
| 531 | + this.response.put("token_endpoint_auth_methods_supported", Arrays.asList("client_secret_post")); |
| 532 | + ClientRegistration registration = registration(this.response).build(); |
| 533 | + assertThat(registration.getClientAuthenticationMethod()) |
| 534 | + .isEqualTo(ClientAuthenticationMethod.CLIENT_SECRET_POST); |
| 535 | + } |
| 536 | + |
| 537 | + @Test |
| 538 | + public void issuerWhenOidcConfigurationClientSecretJwtAuthMethodThenMethodIsClientSecretBasic() throws Exception { |
| 539 | + this.response.put("token_endpoint_auth_methods_supported", Arrays.asList("client_secret_jwt")); |
| 540 | + ClientRegistration registration = registration(this.response).build(); |
| 541 | + // The client_secret_basic auth method is still the default |
| 542 | + assertThat(registration.getClientAuthenticationMethod()) |
| 543 | + .isEqualTo(ClientAuthenticationMethod.CLIENT_SECRET_BASIC); |
| 544 | + } |
| 545 | + |
| 546 | + @Test |
| 547 | + public void issuerWhenOidcConfigurationPrivateKeyJwtAuthMethodThenMethodIsClientSecretBasic() throws Exception { |
| 548 | + this.response.put("token_endpoint_auth_methods_supported", Arrays.asList("private_key_jwt")); |
| 549 | + ClientRegistration registration = registration(this.response).build(); |
| 550 | + // The client_secret_basic auth method is still the default |
| 551 | + assertThat(registration.getClientAuthenticationMethod()) |
| 552 | + .isEqualTo(ClientAuthenticationMethod.CLIENT_SECRET_BASIC); |
| 553 | + } |
| 554 | + |
| 555 | + @Test |
| 556 | + public void issuerWhenOidcConfigurationTokenEndpointAuthMethodsNoneThenMethodIsNone() throws Exception { |
| 557 | + this.response.put("token_endpoint_auth_methods_supported", Arrays.asList("none")); |
| 558 | + ClientRegistration registration = registration(this.response).build(); |
| 559 | + assertThat(registration.getClientAuthenticationMethod()).isEqualTo(ClientAuthenticationMethod.NONE); |
| 560 | + } |
| 561 | + |
| 562 | + @Test |
| 563 | + public void issuerWhenOidcConfigurationTlsClientAuthMethodThenSuccess() throws Exception { |
| 564 | + this.response.put("token_endpoint_auth_methods_supported", Arrays.asList("tls_client_auth")); |
| 565 | + ClientRegistration registration = registration(this.response).build(); |
| 566 | + // The client_secret_basic auth method is still the default |
| 567 | + assertThat(registration.getClientAuthenticationMethod()) |
| 568 | + .isEqualTo(ClientAuthenticationMethod.CLIENT_SECRET_BASIC); |
| 569 | + } |
| 570 | + |
458 | 571 | private ClientRegistration.Builder registration(String path) throws Exception {
|
459 | 572 | this.issuer = createIssuerFromServer(path);
|
460 | 573 | this.response.put("issuer", this.issuer);
|
|
0 commit comments