StatefulTokenStoreTest.java revision adc14d0be45af50dbde99eb71c21de3bc1ddb1c6
/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2014-2016 ForgeRock AS.
*/
public class StatefulTokenStoreTest {
private StatefulTokenStore openAMtokenStore;
private OAuthTokenStore tokenStore;
private RealmNormaliser realmNormaliser;
private SSOTokenManager ssoTokenManager;
private CookieExtractor cookieExtractor;
private OAuth2AuditLogger auditLogger;
public void setUp() {
oAuth2RequestFactory = new RestletOAuth2RequestFactory(new JacksonRepresentationFactory(new ObjectMapper()));
when(failureFactory.getException(any(OAuth2Request.class), anyString())).thenReturn(expectedResult);
new SecureRandom(), failureFactory);
}
@Test
public void shouldReadAccessToken() throws Exception {
//Given
//When
//Then
}
public void shouldNotReadOtherRealmsAccessToken() throws Exception {
//Given
//When
//Then
// expect InvalidGrantException
}
public void shouldReadAccessTokenWhenNull() throws Exception {
//Given
//When
//Then
//Expected InvalidGrantException
}
public void shouldFailToReadAccessToken() throws Exception {
//Given
//When
//Then
//Expected ServerException
}
public void shouldFailWhenNoProvider() throws Exception {
//Given
//When
openAMtokenStore.createAccessToken(null, null, null, null, null, null, null, null, null, null, request);
//Then
//Expected NotFoundException
}
@Test
public void realmAgnosticTokenStoreShouldIgnoreRealmMismatch() throws Exception {
//Given
StatefulTokenStore realmAgnosticTokenStore = new OAuth2GuiceModule.RealmAgnosticStatefulTokenStore(tokenStore,
providerSettingsFactory, oAuth2UrisFactory, clientRegistrationStore, realmNormaliser, ssoTokenManager,
//When
//Then
}
@Test
public void shouldCreateDeviceCode() throws Exception {
// Given
given(request.getAttributes()).willReturn(new ConcurrentHashMap<>(singletonMap("realm", (Object) "MY_REALM")));
// When
DeviceCode code = openAMtokenStore.createDeviceCode(asSet("one", "two"), resourceOwner, "CLIENT ID", "NONCE",
"RESPONSE TYPE", "STATE", "ACR VALUES", "PROMPT", "UI LOCALES", "LOGIN HINT", 55, "CLAIMS",
// Then
assertThat(code.getTokenId()).matches("[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}");
}
public void shouldThrowExceptionForInvalidDeviceCodeJsonValue() throws Exception {
// Given
// When
}
@Test
public void shouldReadValidDeviceCode() throws Exception {
// Given
given(request.getAttributes()).willReturn(new ConcurrentHashMap<>(singletonMap("realm", (Object) "/")));
// When
// Then
}
@Test
public void shouldUpdateDeviceCode() throws Exception {
// Given
given(request.getAttributes()).willReturn(new ConcurrentHashMap<>(singletonMap("realm", (Object) "/")));
// When
// Then
}
@Test
public void shouldDeleteDeviceCode() throws Exception {
// Given
given(request.getAttributes()).willReturn(new ConcurrentHashMap<>(singletonMap("realm", (Object) "/")));
// When
// Then
}
}