Search in sources :

Example 1 with HiveAccumuloHelper

use of org.apache.hadoop.hive.accumulo.HiveAccumuloHelper in project hive by apache.

the class TestHiveAccumuloTableOutputFormat method testSaslConfiguration.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testSaslConfiguration() throws IOException, AccumuloException, AccumuloSecurityException {
    final HiveAccumuloTableOutputFormat outputFormat = Mockito.mock(HiveAccumuloTableOutputFormat.class);
    final AuthenticationToken authToken = Mockito.mock(AuthenticationToken.class);
    final Token hadoopToken = Mockito.mock(Token.class);
    final HiveAccumuloHelper helper = Mockito.mock(HiveAccumuloHelper.class);
    final AccumuloConnectionParameters cnxnParams = Mockito.mock(AccumuloConnectionParameters.class);
    final Connector connector = Mockito.mock(Connector.class);
    // Set UGI to use Kerberos
    // Have to use the string constant to support hadoop 1
    conf.set("hadoop.security.authentication", "kerberos");
    UserGroupInformation.setConfiguration(conf);
    // Set the current UGI to a fake user
    UserGroupInformation user1 = UserGroupInformation.createUserForTesting(user, new String[0]);
    // Use that as the "current user"
    Mockito.when(outputFormat.getCurrentUser()).thenReturn(user1);
    // Turn off passwords, enable sasl and set a keytab
    conf.unset(AccumuloConnectionParameters.USER_PASS);
    // Call the real method instead of the mock
    Mockito.doCallRealMethod().when(outputFormat).configureAccumuloOutputFormat(conf);
    // Return our mocked objects
    Mockito.when(outputFormat.getHelper()).thenReturn(helper);
    Mockito.when(outputFormat.getConnectionParams(conf)).thenReturn(cnxnParams);
    Mockito.when(cnxnParams.getConnector()).thenReturn(connector);
    Mockito.when(helper.getDelegationToken(connector)).thenReturn(authToken);
    Mockito.when(helper.getHadoopToken(authToken)).thenReturn(hadoopToken);
    // Stub AccumuloConnectionParameters actions
    Mockito.when(cnxnParams.useSasl()).thenReturn(true);
    Mockito.when(cnxnParams.getAccumuloUserName()).thenReturn(user);
    Mockito.when(cnxnParams.getAccumuloInstanceName()).thenReturn(instanceName);
    Mockito.when(cnxnParams.getZooKeepers()).thenReturn(zookeepers);
    // Stub OutputFormat actions
    Mockito.when(outputFormat.hasKerberosCredentials(user1)).thenReturn(true);
    // Invoke the method
    outputFormat.configureAccumuloOutputFormat(conf);
    // The AccumuloInputFormat methods
    Mockito.verify(outputFormat).setZooKeeperInstanceWithErrorChecking(conf, instanceName, zookeepers, true);
    Mockito.verify(outputFormat).setConnectorInfoWithErrorChecking(conf, user, authToken);
    Mockito.verify(outputFormat).setDefaultAccumuloTableName(conf, outputTable);
    // Other methods we expect
    Mockito.verify(helper).mergeTokenIntoJobConf(conf, hadoopToken);
    // Make sure the token made it into the UGI
    Collection<Token<? extends TokenIdentifier>> tokens = user1.getTokens();
    Assert.assertEquals(1, tokens.size());
    Assert.assertEquals(hadoopToken, tokens.iterator().next());
}
Also used : TokenIdentifier(org.apache.hadoop.security.token.TokenIdentifier) Connector(org.apache.accumulo.core.client.Connector) AuthenticationToken(org.apache.accumulo.core.client.security.tokens.AuthenticationToken) AuthenticationToken(org.apache.accumulo.core.client.security.tokens.AuthenticationToken) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) Token(org.apache.hadoop.security.token.Token) AccumuloConnectionParameters(org.apache.hadoop.hive.accumulo.AccumuloConnectionParameters) HiveAccumuloHelper(org.apache.hadoop.hive.accumulo.HiveAccumuloHelper) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Aggregations

Connector (org.apache.accumulo.core.client.Connector)1 AuthenticationToken (org.apache.accumulo.core.client.security.tokens.AuthenticationToken)1 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)1 AccumuloConnectionParameters (org.apache.hadoop.hive.accumulo.AccumuloConnectionParameters)1 HiveAccumuloHelper (org.apache.hadoop.hive.accumulo.HiveAccumuloHelper)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 Token (org.apache.hadoop.security.token.Token)1 TokenIdentifier (org.apache.hadoop.security.token.TokenIdentifier)1 Test (org.junit.Test)1