RestSTSInstanceStateServiceListenerTest.java revision 3744900be632496920d4c9aca8f94ba6db4dd882
/*
* 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 Copyrighted [year] [name of copyright owner]".
*
* Copyright 2015 ForgeRock AS.
*/
import org.forgerock.openam.sts.tokengeneration.oidc.crypto.OpenIdConnectTokenPKIProviderFactoryImpl;
public class RestSTSInstanceStateServiceListenerTest {
private RestSTSInstanceStateProvider provider;
private ServiceListener serviceListener;
class TestModule extends AbstractModule {
protected void configure() {
bind(new TypeLiteral<STSInstanceConfigStore<RestSTSInstanceConfig>>(){}).toInstance(mockConfigStore);
bind(OpenIdConnectTokenPKIProviderFactory.class).to(OpenIdConnectTokenPKIProviderFactoryImpl.class);
bind(ServiceListener.class).annotatedWith(Names.named(TokenGenerationModule.REST_STS_INSTANCE_STATE_LISTENER))
.to(RestSTSInstanceStateFactoryImpl.class);
}
}
public void setUpTest() {
}
/**
* This test will seed the RestSTSInstanceStateProvider class with a RestSTSInstanceConfig instance, which should
* populate the cache entry. Then the ServiceListener#organizationalConfigChanged method will be invoked, which should
* invalidate the cache entry.
*/
@Test
public void testServiceListenerCacheInvalidation() throws UnsupportedEncodingException, STSPublishException, TokenCreationException {
when(mockConfigStore.getSTSInstanceConfig(DEPLOYMENT_URL_ELEMENT, REALM)).thenReturn(instanceConfig);
//initializes the cache with the mocked config
//this should invalidate the cache. Lower-case is necessary on the DEPLOYMENT_URL_ELEMENT as
//due to ldap case-insensitivity.
serviceListener.organizationConfigChanged(AMSTSConstants.REST_STS_SERVICE_NAME, AMSTSConstants.REST_STS_SERVICE_VERSION,
//should initialize cache with new entry when getSTSInstanceConfig is called
when(mockConfigStore.getSTSInstanceConfig(DEPLOYMENT_URL_ELEMENT, REALM)).thenReturn(instanceConfig1);
RestSTSInstanceConfig providerConfig = provider.getSTSInstanceState(DEPLOYMENT_URL_ELEMENT, REALM).getConfig();
}
.build();
.build();
.nameIdFormat("urn:oasis:names:tc:SAML:2.0:nameid-format:persistent")
.build();
return RestSTSInstanceConfig.builder()
.build();
}
}