Search in sources :

Example 6 with TokenInformation

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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TokenInformation(org.codice.ddf.security.token.storage.api.TokenInformation) Test(org.junit.Test)

Aggregations

TokenInformation (org.codice.ddf.security.token.storage.api.TokenInformation)6 QueryRequest (ddf.catalog.operation.QueryRequest)3 OAuthPluginException (ddf.catalog.plugin.OAuthPluginException)3 OAuthFederatedSource (ddf.catalog.source.OAuthFederatedSource)3 Subject (ddf.security.Subject)3 Map (java.util.Map)3 Test (org.junit.Test)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 Date (java.util.Date)2 TokenEntry (org.codice.ddf.security.token.storage.api.TokenInformation.TokenEntry)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 DefaultResourceRetriever (com.nimbusds.jose.util.DefaultResourceRetriever)1 ResourceRetriever (com.nimbusds.jose.util.ResourceRetriever)1 ParseException (com.nimbusds.oauth2.sdk.ParseException)1 Scope (com.nimbusds.oauth2.sdk.Scope)1