|
|
@ -48,6 +48,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
|
|
|
* @author Phillip Webb
|
|
|
|
* @author Phillip Webb
|
|
|
|
* @author Madhura Bhave
|
|
|
|
* @author Madhura Bhave
|
|
|
|
* @author Thiago Hirata
|
|
|
|
* @author Thiago Hirata
|
|
|
|
|
|
|
|
* @author HaiTao Zhang
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
class OAuth2ClientPropertiesRegistrationAdapterTests {
|
|
|
|
class OAuth2ClientPropertiesRegistrationAdapterTests {
|
|
|
|
|
|
|
|
|
|
|
@ -209,7 +210,7 @@ class OAuth2ClientPropertiesRegistrationAdapterTests {
|
|
|
|
Registration login = new OAuth2ClientProperties.Registration();
|
|
|
|
Registration login = new OAuth2ClientProperties.Registration();
|
|
|
|
login.setClientId("clientId");
|
|
|
|
login.setClientId("clientId");
|
|
|
|
login.setClientSecret("clientSecret");
|
|
|
|
login.setClientSecret("clientSecret");
|
|
|
|
testOidcConfiguration(login, "okta");
|
|
|
|
testIssuerConfiguration(login, "okta", 0, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -218,7 +219,23 @@ class OAuth2ClientPropertiesRegistrationAdapterTests {
|
|
|
|
login.setProvider("okta-oidc");
|
|
|
|
login.setProvider("okta-oidc");
|
|
|
|
login.setClientId("clientId");
|
|
|
|
login.setClientId("clientId");
|
|
|
|
login.setClientSecret("clientSecret");
|
|
|
|
login.setClientSecret("clientSecret");
|
|
|
|
testOidcConfiguration(login, "okta-oidc");
|
|
|
|
testIssuerConfiguration(login, "okta-oidc", 0, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void issuerUriConfigurationTriesOidcRfc8414UriSecond() throws Exception {
|
|
|
|
|
|
|
|
OAuth2ClientProperties.Registration login = new Registration();
|
|
|
|
|
|
|
|
login.setClientId("clientId");
|
|
|
|
|
|
|
|
login.setClientSecret("clientSecret");
|
|
|
|
|
|
|
|
testIssuerConfiguration(login, "okta", 1, 2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void issuerUriConfigurationTriesOAuthMetadataUriThird() throws Exception {
|
|
|
|
|
|
|
|
OAuth2ClientProperties.Registration login = new Registration();
|
|
|
|
|
|
|
|
login.setClientId("clientId");
|
|
|
|
|
|
|
|
login.setClientSecret("clientSecret");
|
|
|
|
|
|
|
|
testIssuerConfiguration(login, "okta", 2, 3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -273,12 +290,12 @@ class OAuth2ClientPropertiesRegistrationAdapterTests {
|
|
|
|
return registration;
|
|
|
|
return registration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void testOidcConfiguration(OAuth2ClientProperties.Registration registration, String providerId)
|
|
|
|
private void testIssuerConfiguration(OAuth2ClientProperties.Registration registration, String providerId,
|
|
|
|
throws Exception {
|
|
|
|
int errorResponseCount, int numberOfRequests) throws Exception {
|
|
|
|
this.server = new MockWebServer();
|
|
|
|
this.server = new MockWebServer();
|
|
|
|
this.server.start();
|
|
|
|
this.server.start();
|
|
|
|
String issuer = this.server.url("").toString();
|
|
|
|
String issuer = this.server.url("").toString();
|
|
|
|
setupMockResponse(issuer);
|
|
|
|
setupMockResponsesWithErrors(issuer, errorResponseCount);
|
|
|
|
OAuth2ClientProperties properties = new OAuth2ClientProperties();
|
|
|
|
OAuth2ClientProperties properties = new OAuth2ClientProperties();
|
|
|
|
Provider provider = new Provider();
|
|
|
|
Provider provider = new Provider();
|
|
|
|
provider.setIssuerUri(issuer);
|
|
|
|
provider.setIssuerUri(issuer);
|
|
|
@ -300,6 +317,7 @@ class OAuth2ClientPropertiesRegistrationAdapterTests {
|
|
|
|
assertThat(userInfoEndpoint.getUri()).isEqualTo("https://example.com/oauth2/v3/userinfo");
|
|
|
|
assertThat(userInfoEndpoint.getUri()).isEqualTo("https://example.com/oauth2/v3/userinfo");
|
|
|
|
assertThat(userInfoEndpoint.getAuthenticationMethod())
|
|
|
|
assertThat(userInfoEndpoint.getAuthenticationMethod())
|
|
|
|
.isEqualTo(org.springframework.security.oauth2.core.AuthenticationMethod.HEADER);
|
|
|
|
.isEqualTo(org.springframework.security.oauth2.core.AuthenticationMethod.HEADER);
|
|
|
|
|
|
|
|
assertThat(this.server.getRequestCount()).isEqualTo(numberOfRequests);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void setupMockResponse(String issuer) throws JsonProcessingException {
|
|
|
|
private void setupMockResponse(String issuer) throws JsonProcessingException {
|
|
|
@ -309,6 +327,14 @@ class OAuth2ClientPropertiesRegistrationAdapterTests {
|
|
|
|
this.server.enqueue(mockResponse);
|
|
|
|
this.server.enqueue(mockResponse);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void setupMockResponsesWithErrors(String issuer, int errorResponseCount) throws JsonProcessingException {
|
|
|
|
|
|
|
|
for (int i = 0; i < errorResponseCount; i++) {
|
|
|
|
|
|
|
|
MockResponse emptyResponse = new MockResponse().setResponseCode(HttpStatus.NOT_FOUND.value());
|
|
|
|
|
|
|
|
this.server.enqueue(emptyResponse);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
setupMockResponse(issuer);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, Object> getResponse(String issuer) {
|
|
|
|
private Map<String, Object> getResponse(String issuer) {
|
|
|
|
Map<String, Object> response = new HashMap<>();
|
|
|
|
Map<String, Object> response = new HashMap<>();
|
|
|
|
response.put("authorization_endpoint", "https://example.com/o/oauth2/v2/auth");
|
|
|
|
response.put("authorization_endpoint", "https://example.com/o/oauth2/v2/auth");
|
|
|
|