TokenTranslateOperationImplTest.java revision bbb43b578c74fb7367a176e7cb07c94daf71c209
/*
* 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 2013-2015 ForgeRock AS.
*/
/*
Note that an injector is created in each test as the behavior of mocks need to be changed in each test.
*/
public class TokenTranslateOperationImplTest {
static final boolean INVALIDATE_INTERIM_AM_SESSIONS = true;
class MyModule extends AbstractModule {
protected void configure() {
/*
Have to mock the TokenTransformFactory in the module because it will be invoked in the TokenTranslateOperationImpl
ctor to build the set of TokenTransform instances.
*/
try {
when(mockTransformFactory.buildTokenTransform(any(TokenTransformConfig.class))).thenReturn(mockTokenTransform);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
supportedTransforms.add(new TokenTransformConfig(TokenType.USERNAME, TokenType.SAML2, INVALIDATE_INTERIM_AM_SESSIONS));
return supportedTransforms;
}
return "bobo";
}
String getJsonRoot() {
return "json";
}
Logger getSlf4jLogger() {
}
return "client_cert";
}
return Collections.emptySet();
}
return Collections.emptySet();
}
return Collections.emptySet();
}
return Collections.emptySet();
}
}
public void testUnsupportedTransform() throws Exception {
TokenTranslateOperation tokenTranslateOperation = injector.getInstance(TokenTranslateOperation.class);
when(mockTokenTransform.isTransformSupported(any(TokenType.class), any(TokenType.class))).thenReturn(Boolean.FALSE);
}
public void testUnknownTransform() throws Exception {
TokenTranslateOperation tokenTranslateOperation = Guice.createInjector(new MyModule()).getInstance(TokenTranslateOperation.class);
RestSTSTokenTranslationInvocationState.builder().inputTokenState(bunkTokenState).outputTokenState(bunkTokenState).build();
}
private RestSTSTokenTranslationInvocationState buildInvocationState(TokenType desiredTokenType) throws Exception {
UsernameTokenState untState = UsernameTokenState.builder().password("bobo".getBytes()).username("dodo".getBytes()).build();
.build()
.toJson();
} else {
}
return RestSTSTokenTranslationInvocationState.builder().inputTokenState(untState.toJson()).outputTokenState(outputTokenState).build();
}
}