use of org.apache.hadoop.crypto.key.KeyProviderDelegationTokenExtension.DelegationTokenExtension in project hadoop by apache.
the class TestEncryptionZones method testDelegationToken.
/**
* Tests obtaining delegation token from stored key
*/
@Test
public void testDelegationToken() throws Exception {
UserGroupInformation.createRemoteUser("JobTracker");
DistributedFileSystem dfs = cluster.getFileSystem();
KeyProvider keyProvider = Mockito.mock(KeyProvider.class, withSettings().extraInterfaces(DelegationTokenExtension.class, CryptoExtension.class));
Mockito.when(keyProvider.getConf()).thenReturn(conf);
byte[] testIdentifier = "Test identifier for delegation token".getBytes();
Token<?> testToken = new Token(testIdentifier, new byte[0], new Text(), new Text());
Mockito.when(((DelegationTokenExtension) keyProvider).addDelegationTokens(anyString(), (Credentials) any())).thenReturn(new Token<?>[] { testToken });
dfs.getClient().setKeyProvider(keyProvider);
Credentials creds = new Credentials();
final Token<?>[] tokens = dfs.addDelegationTokens("JobTracker", creds);
DistributedFileSystem.LOG.debug("Delegation tokens: " + Arrays.asList(tokens));
Assert.assertEquals(2, tokens.length);
Assert.assertEquals(tokens[1], testToken);
Assert.assertEquals(1, creds.numberOfTokens());
}
Aggregations