20 changed files with 1187 additions and 210 deletions
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
/* |
||||
* Copyright 2002-2017 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.security.oauth2.core; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* Tests for {@link AuthorizationGrantType}. |
||||
* |
||||
* @author Joe Grandja |
||||
*/ |
||||
public class AuthorizationGrantTypeTests { |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void constructorWhenValueIsNullThenThrowIllegalArgumentException() { |
||||
new AuthorizationGrantType(null); |
||||
} |
||||
|
||||
@Test |
||||
public void getValueWhenAuthorizationCodeGrantTypeThenReturnAuthorizationCode() { |
||||
assertThat(AuthorizationGrantType.AUTHORIZATION_CODE.getValue()).isEqualTo("authorization_code"); |
||||
} |
||||
|
||||
@Test |
||||
public void getValueWhenImplicitGrantTypeThenReturnImplicit() { |
||||
assertThat(AuthorizationGrantType.IMPLICIT.getValue()).isEqualTo("implicit"); |
||||
} |
||||
} |
||||
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
/* |
||||
* Copyright 2002-2017 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.security.oauth2.core; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* Tests for {@link ClientAuthenticationMethod}. |
||||
* |
||||
* @author Joe Grandja |
||||
*/ |
||||
public class ClientAuthenticationMethodTests { |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void constructorWhenValueIsNullThenThrowIllegalArgumentException() { |
||||
new ClientAuthenticationMethod(null); |
||||
} |
||||
|
||||
@Test |
||||
public void getValueWhenAuthenticationMethodBasicThenReturnBasic() { |
||||
assertThat(ClientAuthenticationMethod.BASIC.getValue()).isEqualTo("basic"); |
||||
} |
||||
|
||||
@Test |
||||
public void getValueWhenAuthenticationMethodPostThenReturnPost() { |
||||
assertThat(ClientAuthenticationMethod.POST.getValue()).isEqualTo("post"); |
||||
} |
||||
} |
||||
@ -0,0 +1,85 @@
@@ -0,0 +1,85 @@
|
||||
/* |
||||
* Copyright 2002-2017 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.security.oauth2.core; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import java.time.Instant; |
||||
import java.util.Arrays; |
||||
import java.util.LinkedHashSet; |
||||
import java.util.Set; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* Tests for {@link OAuth2AccessToken}. |
||||
* |
||||
* @author Joe Grandja |
||||
*/ |
||||
public class OAuth2AccessTokenTests { |
||||
private static final OAuth2AccessToken.TokenType TOKEN_TYPE = OAuth2AccessToken.TokenType.BEARER; |
||||
private static final String TOKEN_VALUE = "access-token"; |
||||
private static final Instant ISSUED_AT = Instant.now(); |
||||
private static final Instant EXPIRES_AT = Instant.from(ISSUED_AT).plusSeconds(60); |
||||
private static final Set<String> SCOPES = new LinkedHashSet<>(Arrays.asList("scope1", "scope2")); |
||||
|
||||
@Test |
||||
public void tokenTypeGetValueWhenTokenTypeBearerThenReturnBearer() { |
||||
assertThat(OAuth2AccessToken.TokenType.BEARER.getValue()).isEqualTo("Bearer"); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void constructorWhenTokenTypeIsNullThenThrowIllegalArgumentException() { |
||||
new OAuth2AccessToken(null, TOKEN_VALUE, ISSUED_AT, EXPIRES_AT); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void constructorWhenTokenValueIsNullThenThrowIllegalArgumentException() { |
||||
new OAuth2AccessToken(TOKEN_TYPE, null, ISSUED_AT, EXPIRES_AT); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void constructorWhenIssuedAtIsNullThenThrowIllegalArgumentException() { |
||||
new OAuth2AccessToken(TOKEN_TYPE, TOKEN_VALUE, null, EXPIRES_AT); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void constructorWhenExpiresAtIsNullThenThrowIllegalArgumentException() { |
||||
new OAuth2AccessToken(TOKEN_TYPE, TOKEN_VALUE, ISSUED_AT, null); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void constructorWhenIssuedAtAfterExpiresAtThenThrowIllegalArgumentException() { |
||||
new OAuth2AccessToken(TOKEN_TYPE, TOKEN_VALUE, Instant.from(EXPIRES_AT).plusSeconds(1), EXPIRES_AT); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void constructorWhenExpiresAtBeforeIssuedAtThenThrowIllegalArgumentException() { |
||||
new OAuth2AccessToken(TOKEN_TYPE, TOKEN_VALUE, ISSUED_AT, Instant.from(ISSUED_AT).minusSeconds(1)); |
||||
} |
||||
|
||||
@Test |
||||
public void constructorWhenAllParametersProvidedAndValidThenCreated() { |
||||
OAuth2AccessToken accessToken = new OAuth2AccessToken( |
||||
TOKEN_TYPE, TOKEN_VALUE, ISSUED_AT, EXPIRES_AT, SCOPES); |
||||
|
||||
assertThat(accessToken.getTokenType()).isEqualTo(TOKEN_TYPE); |
||||
assertThat(accessToken.getTokenValue()).isEqualTo(TOKEN_VALUE); |
||||
assertThat(accessToken.getIssuedAt()).isEqualTo(ISSUED_AT); |
||||
assertThat(accessToken.getExpiresAt()).isEqualTo(EXPIRES_AT); |
||||
assertThat(accessToken.getScopes()).isEqualTo(SCOPES); |
||||
} |
||||
} |
||||
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
/* |
||||
* Copyright 2002-2017 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.security.oauth2.core; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* Tests for {@link OAuth2Error}. |
||||
* |
||||
* @author Joe Grandja |
||||
*/ |
||||
public class OAuth2ErrorTests { |
||||
private static final String ERROR_CODE = "error-code"; |
||||
private static final String ERROR_DESCRIPTION = "error-description"; |
||||
private static final String ERROR_URI = "error-uri"; |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void constructorWhenErrorCodeIsNullThenThrowIllegalArgumentException() { |
||||
new OAuth2Error(null, ERROR_DESCRIPTION, ERROR_URI); |
||||
} |
||||
|
||||
@Test |
||||
public void constructorWhenAllParametersProvidedAndValidThenCreated() { |
||||
OAuth2Error error = new OAuth2Error(ERROR_CODE, ERROR_DESCRIPTION, ERROR_URI); |
||||
|
||||
assertThat(error.getErrorCode()).isEqualTo(ERROR_CODE); |
||||
assertThat(error.getDescription()).isEqualTo(ERROR_DESCRIPTION); |
||||
assertThat(error.getUri()).isEqualTo(ERROR_URI); |
||||
} |
||||
} |
||||
@ -0,0 +1,54 @@
@@ -0,0 +1,54 @@
|
||||
/* |
||||
* Copyright 2002-2017 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.security.oauth2.core.endpoint; |
||||
|
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
import org.powermock.core.classloader.annotations.PrepareForTest; |
||||
import org.powermock.modules.junit4.PowerMockRunner; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
import static org.mockito.Mockito.mock; |
||||
|
||||
/** |
||||
* Tests for {@link OAuth2AuthorizationExchange}. |
||||
* |
||||
* @author Joe Grandja |
||||
*/ |
||||
@RunWith(PowerMockRunner.class) |
||||
@PrepareForTest({OAuth2AuthorizationExchange.class, OAuth2AuthorizationRequest.class, OAuth2AuthorizationResponse.class}) |
||||
public class OAuth2AuthorizationExchangeTests { |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void constructorWhenAuthorizationRequestIsNullThenThrowIllegalArgumentException() { |
||||
new OAuth2AuthorizationExchange(null, mock(OAuth2AuthorizationResponse.class)); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void constructorWhenAuthorizationResponseIsNullThenThrowIllegalArgumentException() { |
||||
new OAuth2AuthorizationExchange(mock(OAuth2AuthorizationRequest.class), null); |
||||
} |
||||
|
||||
@Test |
||||
public void constructorWhenRequiredArgsProvidedThenCreated() { |
||||
OAuth2AuthorizationRequest authorizationRequest = mock(OAuth2AuthorizationRequest.class); |
||||
OAuth2AuthorizationResponse authorizationResponse = mock(OAuth2AuthorizationResponse.class); |
||||
OAuth2AuthorizationExchange authorizationExchange = |
||||
new OAuth2AuthorizationExchange(authorizationRequest, authorizationResponse); |
||||
assertThat(authorizationExchange.getAuthorizationRequest()).isEqualTo(authorizationRequest); |
||||
assertThat(authorizationExchange.getAuthorizationResponse()).isEqualTo(authorizationResponse); |
||||
} |
||||
} |
||||
@ -0,0 +1,127 @@
@@ -0,0 +1,127 @@
|
||||
/* |
||||
* Copyright 2002-2017 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.security.oauth2.core.endpoint; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
import static org.assertj.core.api.Assertions.assertThatCode; |
||||
|
||||
/** |
||||
* Tests for {@link OAuth2AuthorizationResponse}. |
||||
* |
||||
* @author Joe Grandja |
||||
*/ |
||||
public class OAuth2AuthorizationResponseTests { |
||||
private static final String AUTH_CODE = "auth-code"; |
||||
private static final String REDIRECT_URI = "http://example.com"; |
||||
private static final String STATE = "state"; |
||||
private static final String ERROR_CODE = "error-code"; |
||||
private static final String ERROR_DESCRIPTION = "error-description"; |
||||
private static final String ERROR_URI = "error-uri"; |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void buildSuccessResponseWhenAuthCodeIsNullThenThrowIllegalArgumentException() { |
||||
OAuth2AuthorizationResponse.success(null) |
||||
.redirectUri(REDIRECT_URI) |
||||
.state(STATE) |
||||
.build(); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void buildSuccessResponseWhenRedirectUriIsNullThenThrowIllegalArgumentException() { |
||||
OAuth2AuthorizationResponse.success(AUTH_CODE) |
||||
.redirectUri(null) |
||||
.state(STATE) |
||||
.build(); |
||||
} |
||||
|
||||
@Test |
||||
public void buildSuccessResponseWhenStateIsNullThenDoesNotThrowAnyException() { |
||||
assertThatCode(() -> OAuth2AuthorizationResponse.success(AUTH_CODE) |
||||
.redirectUri(REDIRECT_URI) |
||||
.state(null) |
||||
.build()).doesNotThrowAnyException(); |
||||
} |
||||
|
||||
@Test |
||||
public void buildSuccessResponseWhenAllAttributesProvidedThenAllAttributesAreSet() { |
||||
OAuth2AuthorizationResponse authorizationResponse = OAuth2AuthorizationResponse.success(AUTH_CODE) |
||||
.redirectUri(REDIRECT_URI) |
||||
.state(STATE) |
||||
.build(); |
||||
assertThat(authorizationResponse.getCode()).isEqualTo(AUTH_CODE); |
||||
assertThat(authorizationResponse.getRedirectUri()).isEqualTo(REDIRECT_URI); |
||||
assertThat(authorizationResponse.getState()).isEqualTo(STATE); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void buildSuccessResponseWhenErrorCodeIsSetThenThrowIllegalArgumentException() { |
||||
OAuth2AuthorizationResponse.success(AUTH_CODE) |
||||
.redirectUri(REDIRECT_URI) |
||||
.state(STATE) |
||||
.errorCode(ERROR_CODE) |
||||
.build(); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void buildErrorResponseWhenErrorCodeIsNullThenThrowIllegalArgumentException() { |
||||
OAuth2AuthorizationResponse.error(null) |
||||
.redirectUri(REDIRECT_URI) |
||||
.state(STATE) |
||||
.build(); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void buildErrorResponseWhenRedirectUriIsNullThenThrowIllegalArgumentException() { |
||||
OAuth2AuthorizationResponse.error(ERROR_CODE) |
||||
.redirectUri(null) |
||||
.state(STATE) |
||||
.build(); |
||||
} |
||||
|
||||
@Test |
||||
public void buildErrorResponseWhenStateIsNullThenDoesNotThrowAnyException() { |
||||
assertThatCode(() -> OAuth2AuthorizationResponse.error(ERROR_CODE) |
||||
.redirectUri(REDIRECT_URI) |
||||
.state(null) |
||||
.build()).doesNotThrowAnyException(); |
||||
} |
||||
|
||||
@Test |
||||
public void buildErrorResponseWhenAllAttributesProvidedThenAllAttributesAreSet() { |
||||
OAuth2AuthorizationResponse authorizationResponse = OAuth2AuthorizationResponse.error(ERROR_CODE) |
||||
.errorDescription(ERROR_DESCRIPTION) |
||||
.errorUri(ERROR_URI) |
||||
.redirectUri(REDIRECT_URI) |
||||
.state(STATE) |
||||
.build(); |
||||
assertThat(authorizationResponse.getError().getErrorCode()).isEqualTo(ERROR_CODE); |
||||
assertThat(authorizationResponse.getError().getDescription()).isEqualTo(ERROR_DESCRIPTION); |
||||
assertThat(authorizationResponse.getError().getUri()).isEqualTo(ERROR_URI); |
||||
assertThat(authorizationResponse.getRedirectUri()).isEqualTo(REDIRECT_URI); |
||||
assertThat(authorizationResponse.getState()).isEqualTo(STATE); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void buildErrorResponseWhenAuthCodeIsSetThenThrowIllegalArgumentException() { |
||||
OAuth2AuthorizationResponse.error(ERROR_CODE) |
||||
.redirectUri(REDIRECT_URI) |
||||
.state(STATE) |
||||
.code(AUTH_CODE) |
||||
.build(); |
||||
} |
||||
} |
||||
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
/* |
||||
* Copyright 2002-2017 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.security.oauth2.core.endpoint; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* Tests for {@link OAuth2AuthorizationResponseType}. |
||||
* |
||||
* @author Joe Grandja |
||||
*/ |
||||
public class OAuth2AuthorizationResponseTypeTests { |
||||
|
||||
@Test |
||||
public void getValueWhenResponseTypeCodeThenReturnCode() { |
||||
assertThat(OAuth2AuthorizationResponseType.CODE.getValue()).isEqualTo("code"); |
||||
} |
||||
|
||||
@Test |
||||
public void getValueWhenResponseTypeTokenThenReturnToken() { |
||||
assertThat(OAuth2AuthorizationResponseType.TOKEN.getValue()).isEqualTo("token"); |
||||
} |
||||
} |
||||
@ -0,0 +1,85 @@
@@ -0,0 +1,85 @@
|
||||
/* |
||||
* Copyright 2002-2017 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.security.oauth2.core.oidc; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* Tests for {@link DefaultAddressStandardClaim}. |
||||
* |
||||
* @author Joe Grandja |
||||
*/ |
||||
public class DefaultAddressStandardClaimTests { |
||||
static final String FORMATTED_FIELD_NAME = "formatted"; |
||||
static final String STREET_ADDRESS_FIELD_NAME = "street_address"; |
||||
static final String LOCALITY_FIELD_NAME = "locality"; |
||||
static final String REGION_FIELD_NAME = "region"; |
||||
static final String POSTAL_CODE_FIELD_NAME = "postal_code"; |
||||
static final String COUNTRY_FIELD_NAME = "country"; |
||||
static final String FORMATTED = "formatted"; |
||||
static final String STREET_ADDRESS = "street_address"; |
||||
static final String LOCALITY = "locality"; |
||||
static final String REGION = "region"; |
||||
static final String POSTAL_CODE = "postal_code"; |
||||
static final String COUNTRY = "country"; |
||||
|
||||
@Test |
||||
public void buildWhenAllAttributesProvidedThenAllAttributesAreSet() { |
||||
AddressStandardClaim addressStandardClaim = |
||||
new DefaultAddressStandardClaim.Builder() |
||||
.formatted(FORMATTED) |
||||
.streetAddress(STREET_ADDRESS) |
||||
.locality(LOCALITY) |
||||
.region(REGION) |
||||
.postalCode(POSTAL_CODE) |
||||
.country(COUNTRY) |
||||
.build(); |
||||
|
||||
assertThat(addressStandardClaim.getFormatted()).isEqualTo(FORMATTED); |
||||
assertThat(addressStandardClaim.getStreetAddress()).isEqualTo(STREET_ADDRESS); |
||||
assertThat(addressStandardClaim.getLocality()).isEqualTo(LOCALITY); |
||||
assertThat(addressStandardClaim.getRegion()).isEqualTo(REGION); |
||||
assertThat(addressStandardClaim.getPostalCode()).isEqualTo(POSTAL_CODE); |
||||
assertThat(addressStandardClaim.getCountry()).isEqualTo(COUNTRY); |
||||
} |
||||
|
||||
@Test |
||||
public void buildWhenAllAttributesProvidedToConstructorThenAllAttributesAreSet() { |
||||
Map<String, Object> addressFields = new HashMap<>(); |
||||
addressFields.put(FORMATTED_FIELD_NAME, FORMATTED); |
||||
addressFields.put(STREET_ADDRESS_FIELD_NAME, STREET_ADDRESS); |
||||
addressFields.put(LOCALITY_FIELD_NAME, LOCALITY); |
||||
addressFields.put(REGION_FIELD_NAME, REGION); |
||||
addressFields.put(POSTAL_CODE_FIELD_NAME, POSTAL_CODE); |
||||
addressFields.put(COUNTRY_FIELD_NAME, COUNTRY); |
||||
|
||||
AddressStandardClaim addressStandardClaim = |
||||
new DefaultAddressStandardClaim.Builder(addressFields) |
||||
.build(); |
||||
|
||||
assertThat(addressStandardClaim.getFormatted()).isEqualTo(FORMATTED); |
||||
assertThat(addressStandardClaim.getStreetAddress()).isEqualTo(STREET_ADDRESS); |
||||
assertThat(addressStandardClaim.getLocality()).isEqualTo(LOCALITY); |
||||
assertThat(addressStandardClaim.getRegion()).isEqualTo(REGION); |
||||
assertThat(addressStandardClaim.getPostalCode()).isEqualTo(POSTAL_CODE); |
||||
assertThat(addressStandardClaim.getCountry()).isEqualTo(COUNTRY); |
||||
} |
||||
} |
||||
@ -0,0 +1,121 @@
@@ -0,0 +1,121 @@
|
||||
/* |
||||
* Copyright 2002-2017 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.security.oauth2.core.oidc; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import java.time.Instant; |
||||
import java.util.Arrays; |
||||
import java.util.Collections; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* Tests for {@link OidcIdToken}. |
||||
* |
||||
* @author Joe Grandja |
||||
*/ |
||||
public class OidcIdTokenTests { |
||||
private static final String ISS_CLAIM = "iss"; |
||||
private static final String SUB_CLAIM = "sub"; |
||||
private static final String AUD_CLAIM = "aud"; |
||||
private static final String IAT_CLAIM = "iat"; |
||||
private static final String EXP_CLAIM = "exp"; |
||||
private static final String AUTH_TIME_CLAIM = "auth_time"; |
||||
private static final String NONCE_CLAIM = "nonce"; |
||||
private static final String ACR_CLAIM = "acr"; |
||||
private static final String AMR_CLAIM = "amr"; |
||||
private static final String AZP_CLAIM = "azp"; |
||||
private static final String AT_HASH_CLAIM = "at_hash"; |
||||
private static final String C_HASH_CLAIM = "c_hash"; |
||||
|
||||
private static final String ISS_VALUE = "https://provider.com"; |
||||
private static final String SUB_VALUE = "subject1"; |
||||
private static final List<String> AUD_VALUE = Arrays.asList("aud1", "aud2"); |
||||
private static final long IAT_VALUE = Instant.now().toEpochMilli(); |
||||
private static final long EXP_VALUE = Instant.now().plusSeconds(60).toEpochMilli(); |
||||
private static final long AUTH_TIME_VALUE = Instant.now().minusSeconds(5).toEpochMilli(); |
||||
private static final String NONCE_VALUE = "nonce"; |
||||
private static final String ACR_VALUE = "acr"; |
||||
private static final List<String> AMR_VALUE = Arrays.asList("amr1", "amr2"); |
||||
private static final String AZP_VALUE = "azp"; |
||||
private static final String AT_HASH_VALUE = "at_hash"; |
||||
private static final String C_HASH_VALUE = "c_hash"; |
||||
|
||||
private static final Map<String, Object> CLAIMS; |
||||
private static final String ID_TOKEN_VALUE = "id-token-value"; |
||||
|
||||
static { |
||||
CLAIMS = new HashMap<>(); |
||||
CLAIMS.put(ISS_CLAIM, ISS_VALUE); |
||||
CLAIMS.put(SUB_CLAIM, SUB_VALUE); |
||||
CLAIMS.put(AUD_CLAIM, AUD_VALUE); |
||||
CLAIMS.put(IAT_CLAIM, IAT_VALUE); |
||||
CLAIMS.put(EXP_CLAIM, EXP_VALUE); |
||||
CLAIMS.put(AUTH_TIME_CLAIM, AUTH_TIME_VALUE); |
||||
CLAIMS.put(NONCE_CLAIM, NONCE_VALUE); |
||||
CLAIMS.put(ACR_CLAIM, ACR_VALUE); |
||||
CLAIMS.put(AMR_CLAIM, AMR_VALUE); |
||||
CLAIMS.put(AZP_CLAIM, AZP_VALUE); |
||||
CLAIMS.put(AT_HASH_CLAIM, AT_HASH_VALUE); |
||||
CLAIMS.put(C_HASH_CLAIM, C_HASH_VALUE); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void constructorWhenTokenValueIsNullThenThrowIllegalArgumentException() { |
||||
new OidcIdToken(null, Instant.ofEpochMilli(IAT_VALUE), Instant.ofEpochMilli(EXP_VALUE), CLAIMS); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void constructorWhenIssuedAtIsNullThenThrowIllegalArgumentException() { |
||||
new OidcIdToken(ID_TOKEN_VALUE, null, Instant.ofEpochMilli(EXP_VALUE), CLAIMS); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void constructorWhenExpiresAtIsNullThenThrowIllegalArgumentException() { |
||||
new OidcIdToken(ID_TOKEN_VALUE, Instant.ofEpochMilli(IAT_VALUE), null, CLAIMS); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void constructorWhenClaimsIsEmptyThenThrowIllegalArgumentException() { |
||||
new OidcIdToken(ID_TOKEN_VALUE, Instant.ofEpochMilli(IAT_VALUE), |
||||
Instant.ofEpochMilli(EXP_VALUE), Collections.emptyMap()); |
||||
} |
||||
|
||||
@Test |
||||
public void constructorWhenParametersProvidedAndValidThenCreated() { |
||||
OidcIdToken idToken = new OidcIdToken(ID_TOKEN_VALUE, Instant.ofEpochMilli(IAT_VALUE), |
||||
Instant.ofEpochMilli(EXP_VALUE), CLAIMS); |
||||
|
||||
assertThat(idToken.getClaims()).isEqualTo(CLAIMS); |
||||
assertThat(idToken.getTokenValue()).isEqualTo(ID_TOKEN_VALUE); |
||||
assertThat(idToken.getIssuer().toString()).isEqualTo(ISS_VALUE); |
||||
assertThat(idToken.getSubject()).isEqualTo(SUB_VALUE); |
||||
assertThat(idToken.getAudience()).isEqualTo(AUD_VALUE); |
||||
assertThat(idToken.getIssuedAt().toEpochMilli()).isEqualTo(IAT_VALUE); |
||||
assertThat(idToken.getExpiresAt().toEpochMilli()).isEqualTo(EXP_VALUE); |
||||
assertThat(idToken.getAuthenticatedAt().toEpochMilli()).isEqualTo(AUTH_TIME_VALUE); |
||||
assertThat(idToken.getNonce()).isEqualTo(NONCE_VALUE); |
||||
assertThat(idToken.getAuthenticationContextClass()).isEqualTo(ACR_VALUE); |
||||
assertThat(idToken.getAuthenticationMethods()).isEqualTo(AMR_VALUE); |
||||
assertThat(idToken.getAuthorizedParty()).isEqualTo(AZP_VALUE); |
||||
assertThat(idToken.getAccessTokenHash()).isEqualTo(AT_HASH_VALUE); |
||||
assertThat(idToken.getAuthorizationCodeHash()).isEqualTo(C_HASH_VALUE); |
||||
} |
||||
} |
||||
@ -0,0 +1,142 @@
@@ -0,0 +1,142 @@
|
||||
/* |
||||
* Copyright 2002-2017 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.security.oauth2.core.oidc; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import java.time.Instant; |
||||
import java.util.Collections; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
import static org.springframework.security.oauth2.core.oidc.DefaultAddressStandardClaimTests.*; |
||||
|
||||
/** |
||||
* Tests for {@link OidcUserInfo}. |
||||
* |
||||
* @author Joe Grandja |
||||
*/ |
||||
public class OidcUserInfoTests { |
||||
private static final String SUB_CLAIM = "sub"; |
||||
private static final String NAME_CLAIM = "name"; |
||||
private static final String GIVEN_NAME_CLAIM = "given_name"; |
||||
private static final String FAMILY_NAME_CLAIM = "family_name"; |
||||
private static final String MIDDLE_NAME_CLAIM = "middle_name"; |
||||
private static final String NICKNAME_CLAIM = "nickname"; |
||||
private static final String PREFERRED_USERNAME_CLAIM = "preferred_username"; |
||||
private static final String PROFILE_CLAIM = "profile"; |
||||
private static final String PICTURE_CLAIM = "picture"; |
||||
private static final String WEBSITE_CLAIM = "website"; |
||||
private static final String EMAIL_CLAIM = "email"; |
||||
private static final String EMAIL_VERIFIED_CLAIM = "email_verified"; |
||||
private static final String GENDER_CLAIM = "gender"; |
||||
private static final String BIRTHDATE_CLAIM = "birthdate"; |
||||
private static final String ZONEINFO_CLAIM = "zoneinfo"; |
||||
private static final String LOCALE_CLAIM = "locale"; |
||||
private static final String PHONE_NUMBER_CLAIM = "phone_number"; |
||||
private static final String PHONE_NUMBER_VERIFIED_CLAIM = "phone_number_verified"; |
||||
private static final String ADDRESS_CLAIM = "address"; |
||||
private static final String UPDATED_AT_CLAIM = "updated_at"; |
||||
|
||||
private static final String SUB_VALUE = "subject1"; |
||||
private static final String NAME_VALUE = "full_name"; |
||||
private static final String GIVEN_NAME_VALUE = "given_name"; |
||||
private static final String FAMILY_NAME_VALUE = "family_name"; |
||||
private static final String MIDDLE_NAME_VALUE = "middle_name"; |
||||
private static final String NICKNAME_VALUE = "nickname"; |
||||
private static final String PREFERRED_USERNAME_VALUE = "preferred_username"; |
||||
private static final String PROFILE_VALUE = "profile"; |
||||
private static final String PICTURE_VALUE = "picture"; |
||||
private static final String WEBSITE_VALUE = "website"; |
||||
private static final String EMAIL_VALUE = "email"; |
||||
private static final Boolean EMAIL_VERIFIED_VALUE = true; |
||||
private static final String GENDER_VALUE = "gender"; |
||||
private static final String BIRTHDATE_VALUE = "birthdate"; |
||||
private static final String ZONEINFO_VALUE = "zoneinfo"; |
||||
private static final String LOCALE_VALUE = "locale"; |
||||
private static final String PHONE_NUMBER_VALUE = "phone_number"; |
||||
private static final Boolean PHONE_NUMBER_VERIFIED_VALUE = true; |
||||
private static final Map<String, Object> ADDRESS_VALUE; |
||||
private static final long UPDATED_AT_VALUE = Instant.now().minusSeconds(60).toEpochMilli(); |
||||
|
||||
private static final Map<String, Object> CLAIMS; |
||||
|
||||
static { |
||||
CLAIMS = new HashMap<>(); |
||||
CLAIMS.put(SUB_CLAIM, SUB_VALUE); |
||||
CLAIMS.put(NAME_CLAIM, NAME_VALUE); |
||||
CLAIMS.put(GIVEN_NAME_CLAIM, GIVEN_NAME_VALUE); |
||||
CLAIMS.put(FAMILY_NAME_CLAIM, FAMILY_NAME_VALUE); |
||||
CLAIMS.put(MIDDLE_NAME_CLAIM, MIDDLE_NAME_VALUE); |
||||
CLAIMS.put(NICKNAME_CLAIM, NICKNAME_VALUE); |
||||
CLAIMS.put(PREFERRED_USERNAME_CLAIM, PREFERRED_USERNAME_VALUE); |
||||
CLAIMS.put(PROFILE_CLAIM, PROFILE_VALUE); |
||||
CLAIMS.put(PICTURE_CLAIM, PICTURE_VALUE); |
||||
CLAIMS.put(WEBSITE_CLAIM, WEBSITE_VALUE); |
||||
CLAIMS.put(EMAIL_CLAIM, EMAIL_VALUE); |
||||
CLAIMS.put(EMAIL_VERIFIED_CLAIM, EMAIL_VERIFIED_VALUE); |
||||
CLAIMS.put(GENDER_CLAIM, GENDER_VALUE); |
||||
CLAIMS.put(BIRTHDATE_CLAIM, BIRTHDATE_VALUE); |
||||
CLAIMS.put(ZONEINFO_CLAIM, ZONEINFO_VALUE); |
||||
CLAIMS.put(LOCALE_CLAIM, LOCALE_VALUE); |
||||
CLAIMS.put(PHONE_NUMBER_CLAIM, PHONE_NUMBER_VALUE); |
||||
CLAIMS.put(PHONE_NUMBER_VERIFIED_CLAIM, PHONE_NUMBER_VERIFIED_VALUE); |
||||
|
||||
ADDRESS_VALUE = new HashMap<>(); |
||||
ADDRESS_VALUE.put(FORMATTED_FIELD_NAME, FORMATTED); |
||||
ADDRESS_VALUE.put(STREET_ADDRESS_FIELD_NAME, STREET_ADDRESS); |
||||
ADDRESS_VALUE.put(LOCALITY_FIELD_NAME, LOCALITY); |
||||
ADDRESS_VALUE.put(REGION_FIELD_NAME, REGION); |
||||
ADDRESS_VALUE.put(POSTAL_CODE_FIELD_NAME, POSTAL_CODE); |
||||
ADDRESS_VALUE.put(COUNTRY_FIELD_NAME, COUNTRY); |
||||
CLAIMS.put(ADDRESS_CLAIM, ADDRESS_VALUE); |
||||
|
||||
CLAIMS.put(UPDATED_AT_CLAIM, UPDATED_AT_VALUE); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void constructorWhenClaimsIsEmptyThenThrowIllegalArgumentException() { |
||||
new OidcUserInfo(Collections.emptyMap()); |
||||
} |
||||
|
||||
@Test |
||||
public void constructorWhenParametersProvidedAndValidThenCreated() { |
||||
OidcUserInfo userInfo = new OidcUserInfo(CLAIMS); |
||||
|
||||
assertThat(userInfo.getClaims()).isEqualTo(CLAIMS); |
||||
assertThat(userInfo.getSubject()).isEqualTo(SUB_VALUE); |
||||
assertThat(userInfo.getFullName()).isEqualTo(NAME_VALUE); |
||||
assertThat(userInfo.getGivenName()).isEqualTo(GIVEN_NAME_VALUE); |
||||
assertThat(userInfo.getFamilyName()).isEqualTo(FAMILY_NAME_VALUE); |
||||
assertThat(userInfo.getMiddleName()).isEqualTo(MIDDLE_NAME_VALUE); |
||||
assertThat(userInfo.getNickName()).isEqualTo(NICKNAME_VALUE); |
||||
assertThat(userInfo.getPreferredUsername()).isEqualTo(PREFERRED_USERNAME_VALUE); |
||||
assertThat(userInfo.getProfile()).isEqualTo(PROFILE_VALUE); |
||||
assertThat(userInfo.getPicture()).isEqualTo(PICTURE_VALUE); |
||||
assertThat(userInfo.getWebsite()).isEqualTo(WEBSITE_VALUE); |
||||
assertThat(userInfo.getEmail()).isEqualTo(EMAIL_VALUE); |
||||
assertThat(userInfo.getEmailVerified()).isEqualTo(EMAIL_VERIFIED_VALUE); |
||||
assertThat(userInfo.getGender()).isEqualTo(GENDER_VALUE); |
||||
assertThat(userInfo.getBirthdate()).isEqualTo(BIRTHDATE_VALUE); |
||||
assertThat(userInfo.getZoneInfo()).isEqualTo(ZONEINFO_VALUE); |
||||
assertThat(userInfo.getLocale()).isEqualTo(LOCALE_VALUE); |
||||
assertThat(userInfo.getPhoneNumber()).isEqualTo(PHONE_NUMBER_VALUE); |
||||
assertThat(userInfo.getPhoneNumberVerified()).isEqualTo(PHONE_NUMBER_VERIFIED_VALUE); |
||||
assertThat(userInfo.getAddress()).isEqualTo(new DefaultAddressStandardClaim.Builder(ADDRESS_VALUE).build()); |
||||
assertThat(userInfo.getUpdatedAt().toEpochMilli()).isEqualTo(UPDATED_AT_VALUE); |
||||
} |
||||
} |
||||
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
/* |
||||
* Copyright 2002-2017 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.security.oauth2.core.oidc.user; |
||||
|
||||
import org.junit.Test; |
||||
import org.springframework.security.oauth2.core.oidc.IdTokenClaimNames; |
||||
import org.springframework.security.oauth2.core.oidc.OidcIdToken; |
||||
import org.springframework.security.oauth2.core.oidc.OidcUserInfo; |
||||
import org.springframework.security.oauth2.core.oidc.StandardClaimNames; |
||||
|
||||
import java.time.Instant; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
import static org.assertj.core.api.Assertions.assertThatCode; |
||||
|
||||
/** |
||||
* Tests for {@link OidcUserAuthority}. |
||||
* |
||||
* @author Joe Grandja |
||||
*/ |
||||
public class OidcUserAuthorityTests { |
||||
private static final String AUTHORITY = "ROLE_USER"; |
||||
private static final String SUBJECT = "test-subject"; |
||||
private static final String EMAIL = "test-subject@example.com"; |
||||
private static final String NAME = "test-name"; |
||||
private static final Map<String, Object> ID_TOKEN_CLAIMS = new HashMap<>(); |
||||
private static final Map<String, Object> USER_INFO_CLAIMS = new HashMap<>(); |
||||
|
||||
static { |
||||
ID_TOKEN_CLAIMS.put(IdTokenClaimNames.ISS, "https://example.com"); |
||||
ID_TOKEN_CLAIMS.put(IdTokenClaimNames.SUB, SUBJECT); |
||||
USER_INFO_CLAIMS.put(StandardClaimNames.NAME, NAME); |
||||
USER_INFO_CLAIMS.put(StandardClaimNames.EMAIL, EMAIL); |
||||
} |
||||
|
||||
private static final OidcIdToken ID_TOKEN = new OidcIdToken("id-token-value", Instant.EPOCH, Instant.MAX, ID_TOKEN_CLAIMS); |
||||
private static final OidcUserInfo USER_INFO = new OidcUserInfo(USER_INFO_CLAIMS); |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void constructorWhenIdTokenIsNullThenThrowIllegalArgumentException() { |
||||
new OidcUserAuthority(null); |
||||
} |
||||
|
||||
@Test |
||||
public void constructorWhenUserInfoIsNullThenDoesNotThrowAnyException() { |
||||
assertThatCode(() -> new OidcUserAuthority(ID_TOKEN, null)).doesNotThrowAnyException(); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void constructorWhenAuthorityIsNullThenThrowIllegalArgumentException() { |
||||
new OidcUserAuthority(null, ID_TOKEN, USER_INFO); |
||||
} |
||||
|
||||
@Test |
||||
public void constructorWhenAllParametersProvidedAndValidThenCreated() { |
||||
OidcUserAuthority userAuthority = new OidcUserAuthority(AUTHORITY, ID_TOKEN, USER_INFO); |
||||
|
||||
assertThat(userAuthority.getIdToken()).isEqualTo(ID_TOKEN); |
||||
assertThat(userAuthority.getUserInfo()).isEqualTo(USER_INFO); |
||||
assertThat(userAuthority.getAuthority()).isEqualTo(AUTHORITY); |
||||
assertThat(userAuthority.getAttributes()).containsOnlyKeys( |
||||
IdTokenClaimNames.ISS, IdTokenClaimNames.SUB, StandardClaimNames.NAME, StandardClaimNames.EMAIL); |
||||
} |
||||
} |
||||
@ -0,0 +1,56 @@
@@ -0,0 +1,56 @@
|
||||
/* |
||||
* Copyright 2002-2017 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.security.oauth2.core.user; |
||||
|
||||
import org.junit.Test; |
||||
|
||||
import java.util.Collections; |
||||
import java.util.Map; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* Tests for {@link OAuth2UserAuthority}. |
||||
* |
||||
* @author Joe Grandja |
||||
*/ |
||||
public class OAuth2UserAuthorityTests { |
||||
private static final String AUTHORITY = "ROLE_USER"; |
||||
private static final Map<String, Object> ATTRIBUTES = Collections.singletonMap("username", "test"); |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void constructorWhenAuthorityIsNullThenThrowIllegalArgumentException() { |
||||
new OAuth2UserAuthority(null, ATTRIBUTES); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void constructorWhenAttributesIsNullThenThrowIllegalArgumentException() { |
||||
new OAuth2UserAuthority(AUTHORITY, null); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void constructorWhenAttributesIsEmptyThenThrowIllegalArgumentException() { |
||||
new OAuth2UserAuthority(AUTHORITY, Collections.emptyMap()); |
||||
} |
||||
|
||||
@Test |
||||
public void constructorWhenAllParametersProvidedAndValidThenCreated() { |
||||
OAuth2UserAuthority userAuthority = new OAuth2UserAuthority(AUTHORITY, ATTRIBUTES); |
||||
|
||||
assertThat(userAuthority.getAuthority()).isEqualTo(AUTHORITY); |
||||
assertThat(userAuthority.getAttributes()).isEqualTo(ATTRIBUTES); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue