use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.
the class SAMLAdapterTest method shouldNotStoreSecondaryKeyIfNull.
@Test
public void shouldNotStoreSecondaryKeyIfNull() {
// Given
SAMLToken samlToken = new SAMLToken("primary", null, 12345, "");
given(tokenIdFactory.toSAMLPrimaryTokenId(anyString())).willReturn("id");
given(serialisation.serialise(anyObject())).willReturn("");
// When
Token token = adapter.toToken(samlToken);
// Then
assertThat(token.<String>getValue(SAMLTokenField.SECONDARY_KEY.getField())).isNull();
}
use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.
the class SessionAdapterTest method shouldFilterLatestAccessTime.
@Test
public void shouldFilterLatestAccessTime() throws CoreTokenException {
// Given
Token token = new Token("badger", TokenType.SESSION);
String latestAccessTime = "\"latestAccessTime\":1376308558,";
String someJSONLikeText = "{\"clientDomain\":null,\"creationTime\":1376307674,\"isISStored\":true," + latestAccessTime + "\"maxCachingTime\":3}";
token.setBlob(someJSONLikeText.getBytes());
TokenBlobUtils utils = new TokenBlobUtils();
// When
adapter.filterLatestAccessTime(token);
// Then
String contents = utils.getBlobAsString(token);
// Present in the original json text.
assertTrue(someJSONLikeText.contains(latestAccessTime));
// Removed in the treated json text.
assertFalse(contents.contains(latestAccessTime));
}
use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.
the class JavaBeanAdapterTest method wrongTokenTypeFails.
@Test(expectedExceptions = IllegalArgumentException.class)
public void wrongTokenTypeFails() throws Exception {
// Given
Token token = new Token("abc123", TokenType.REST);
// When
adapter.fromToken(token);
// Then exception
}
use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.
the class OAuthAdapterTest method shouldDeserialiseSerialisedToken.
@Test
public void shouldDeserialiseSerialisedToken() {
// Given
String[] id = { "badger" };
List<String> list = new ArrayList<String>(Arrays.asList(id));
OAuthTokenField field = OAuthTokenField.ID;
JSONSerialisation serialisation = new JSONSerialisation(new ObjectMapper());
OAuthAdapter adapter = generateOAuthAdapter();
// Populate a map for serialisation.
Map<String, Object> values = new HashMap<String, Object>();
values.put(field.getOAuthField(), list);
//Map<String, Object> map = new HashMap<String, Object>();
//map.put(OAuthAdapter.VALUE, values);
String serialisedObject = serialisation.serialise(values);
Token token = new Token(id[0], TokenType.OAUTH);
// Set the serialised binary data
token.setBlob(serialisedObject.getBytes());
// When
JsonValue result = adapter.fromToken(token);
// Then
assertNotNull(result);
assert (result.asMap().get(field.getOAuthField()).toString().contains(id[0]));
}
use of org.forgerock.openam.cts.api.tokens.Token in project OpenAM by OpenRock.
the class OAuthAdapterTest method shouldSerialiseSimpleString.
@Test
public void shouldSerialiseSimpleString() {
// Given
OAuthAdapter adapter = generateOAuthAdapter();
Set<String> text = new HashSet<String>();
text.add("badger");
OAuthTokenField field = OAuthTokenField.PARENT;
Map<String, Object> values = new HashMap<String, Object>();
values.put(field.getOAuthField(), text);
JsonValue jsonValue = makeDefaultJsonValue(values);
// When
Token result = adapter.toToken(jsonValue);
// Then
assert (result.getValue(field.getField()).toString().contains("badger"));
}
Aggregations