use of org.codice.ddf.security.token.storage.api.TokenInformation in project ddf by codice.
the class FileSystemTokenStorageTest method testRead.
@Test
public void testRead() throws Exception {
folder.newFile(USERNAME_HASH);
String path = folder.getRoot().getAbsolutePath() + "/" + USERNAME_HASH;
Files.write(Paths.get(path), ENCRYPTED.getBytes());
String json = GSON.toJson(ImmutableMap.of(SOURCE_ID, ImmutableMap.of(ACCESS_TOKEN, ACCESS_TOKEN_VAL, REFRESH_TOKEN, REFRESH_TOKEN_VAL, DISCOVERY_URL, DISCOVERY_URL_VAL)));
when(crypter.decrypt(any(InputStream.class))).thenReturn(new ByteArrayInputStream(json.getBytes()));
TokenInformation tokenInformation = tokenStorage.read(USERNAME);
TokenInformation.TokenEntry tokenEntry = tokenInformation.getTokenEntries().get(SOURCE_ID);
assertEquals(USERNAME_HASH, tokenInformation.getId());
assertEquals(json, tokenInformation.getTokenJson());
assertEquals(Collections.singleton(DISCOVERY_URL_VAL), tokenInformation.getDiscoveryUrls());
assertEquals(ACCESS_TOKEN_VAL, tokenEntry.getAccessToken());
assertEquals(REFRESH_TOKEN_VAL, tokenEntry.getRefreshToken());
assertEquals(DISCOVERY_URL_VAL, tokenEntry.getDiscoveryUrl());
}
Aggregations