|
|
|
|
@ -22,6 +22,7 @@ import java.util.Map;
@@ -22,6 +22,7 @@ import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import okhttp3.mockwebserver.MockResponse; |
|
|
|
|
import okhttp3.mockwebserver.MockWebServer; |
|
|
|
|
import org.jspecify.annotations.Nullable; |
|
|
|
|
import org.junit.jupiter.api.AfterEach; |
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
import tools.jackson.databind.ObjectMapper; |
|
|
|
|
@ -51,7 +52,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
@@ -51,7 +52,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
|
|
|
|
*/ |
|
|
|
|
class OAuth2ClientPropertiesMapperTests { |
|
|
|
|
|
|
|
|
|
private MockWebServer server; |
|
|
|
|
private @Nullable MockWebServer server; |
|
|
|
|
|
|
|
|
|
@AfterEach |
|
|
|
|
void cleanup() throws Exception { |
|
|
|
|
@ -72,6 +73,7 @@ class OAuth2ClientPropertiesMapperTests {
@@ -72,6 +73,7 @@ class OAuth2ClientPropertiesMapperTests {
|
|
|
|
|
Map<String, ClientRegistration> registrations = new OAuth2ClientPropertiesMapper(properties) |
|
|
|
|
.asClientRegistrations(); |
|
|
|
|
ClientRegistration adapted = registrations.get("registration"); |
|
|
|
|
assertThat(adapted).isNotNull(); |
|
|
|
|
ProviderDetails adaptedProvider = adapted.getProviderDetails(); |
|
|
|
|
assertThat(adaptedProvider.getAuthorizationUri()).isEqualTo("https://example.com/auth"); |
|
|
|
|
assertThat(adaptedProvider.getTokenUri()).isEqualTo("https://example.com/token"); |
|
|
|
|
@ -104,6 +106,7 @@ class OAuth2ClientPropertiesMapperTests {
@@ -104,6 +106,7 @@ class OAuth2ClientPropertiesMapperTests {
|
|
|
|
|
Map<String, ClientRegistration> registrations = new OAuth2ClientPropertiesMapper(properties) |
|
|
|
|
.asClientRegistrations(); |
|
|
|
|
ClientRegistration adapted = registrations.get("registration"); |
|
|
|
|
assertThat(adapted).isNotNull(); |
|
|
|
|
ProviderDetails adaptedProvider = adapted.getProviderDetails(); |
|
|
|
|
assertThat(adaptedProvider.getAuthorizationUri()).isEqualTo("https://accounts.google.com/o/oauth2/v2/auth"); |
|
|
|
|
assertThat(adaptedProvider.getTokenUri()).isEqualTo("https://www.googleapis.com/oauth2/v4/token"); |
|
|
|
|
@ -132,6 +135,7 @@ class OAuth2ClientPropertiesMapperTests {
@@ -132,6 +135,7 @@ class OAuth2ClientPropertiesMapperTests {
|
|
|
|
|
Map<String, ClientRegistration> registrations = new OAuth2ClientPropertiesMapper(properties) |
|
|
|
|
.asClientRegistrations(); |
|
|
|
|
ClientRegistration adapted = registrations.get("registration"); |
|
|
|
|
assertThat(adapted).isNotNull(); |
|
|
|
|
ProviderDetails adaptedProvider = adapted.getProviderDetails(); |
|
|
|
|
assertThat(adaptedProvider.getAuthorizationUri()).isEqualTo("https://accounts.google.com/o/oauth2/v2/auth"); |
|
|
|
|
assertThat(adaptedProvider.getTokenUri()).isEqualTo("https://www.googleapis.com/oauth2/v4/token"); |
|
|
|
|
@ -174,6 +178,7 @@ class OAuth2ClientPropertiesMapperTests {
@@ -174,6 +178,7 @@ class OAuth2ClientPropertiesMapperTests {
|
|
|
|
|
Map<String, ClientRegistration> registrations = new OAuth2ClientPropertiesMapper(properties) |
|
|
|
|
.asClientRegistrations(); |
|
|
|
|
ClientRegistration adapted = registrations.get("google"); |
|
|
|
|
assertThat(adapted).isNotNull(); |
|
|
|
|
ProviderDetails adaptedProvider = adapted.getProviderDetails(); |
|
|
|
|
assertThat(adaptedProvider.getAuthorizationUri()).isEqualTo("https://accounts.google.com/o/oauth2/v2/auth"); |
|
|
|
|
assertThat(adaptedProvider.getTokenUri()).isEqualTo("https://www.googleapis.com/oauth2/v4/token"); |
|
|
|
|
@ -252,6 +257,7 @@ class OAuth2ClientPropertiesMapperTests {
@@ -252,6 +257,7 @@ class OAuth2ClientPropertiesMapperTests {
|
|
|
|
|
Map<String, ClientRegistration> registrations = new OAuth2ClientPropertiesMapper(properties) |
|
|
|
|
.asClientRegistrations(); |
|
|
|
|
ClientRegistration adapted = registrations.get("okta"); |
|
|
|
|
assertThat(adapted).isNotNull(); |
|
|
|
|
ProviderDetails providerDetails = adapted.getProviderDetails(); |
|
|
|
|
assertThat(adapted.getClientAuthenticationMethod()).isEqualTo(ClientAuthenticationMethod.CLIENT_SECRET_POST); |
|
|
|
|
assertThat(adapted.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.AUTHORIZATION_CODE); |
|
|
|
|
@ -303,6 +309,7 @@ class OAuth2ClientPropertiesMapperTests {
@@ -303,6 +309,7 @@ class OAuth2ClientPropertiesMapperTests {
|
|
|
|
|
Map<String, ClientRegistration> registrations = new OAuth2ClientPropertiesMapper(properties) |
|
|
|
|
.asClientRegistrations(); |
|
|
|
|
ClientRegistration adapted = registrations.get("okta"); |
|
|
|
|
assertThat(adapted).isNotNull(); |
|
|
|
|
ProviderDetails providerDetails = adapted.getProviderDetails(); |
|
|
|
|
assertThat(adapted.getClientAuthenticationMethod()).isEqualTo(ClientAuthenticationMethod.CLIENT_SECRET_BASIC); |
|
|
|
|
assertThat(adapted.getAuthorizationGrantType()).isEqualTo(AuthorizationGrantType.AUTHORIZATION_CODE); |
|
|
|
|
@ -323,10 +330,12 @@ class OAuth2ClientPropertiesMapperTests {
@@ -323,10 +330,12 @@ class OAuth2ClientPropertiesMapperTests {
|
|
|
|
|
MockResponse mockResponse = new MockResponse().setResponseCode(HttpStatus.OK.value()) |
|
|
|
|
.setBody(new ObjectMapper().writeValueAsString(getResponse(issuer))) |
|
|
|
|
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); |
|
|
|
|
assertThat(this.server).isNotNull(); |
|
|
|
|
this.server.enqueue(mockResponse); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void setupMockResponsesWithErrors(String issuer, int errorResponseCount) { |
|
|
|
|
assertThat(this.server).isNotNull(); |
|
|
|
|
for (int i = 0; i < errorResponseCount; i++) { |
|
|
|
|
MockResponse emptyResponse = new MockResponse().setResponseCode(HttpStatus.NOT_FOUND.value()); |
|
|
|
|
this.server.enqueue(emptyResponse); |
|
|
|
|
|