Search in sources :

Example 1 with SimpleSaslClientAuthenticationProvider

use of org.apache.hadoop.hbase.security.provider.SimpleSaslClientAuthenticationProvider in project hbase by apache.

the class TestHBaseSaslRpcClient method testFailedEvaluateResponse.

@Test(expected = IOException.class)
public void testFailedEvaluateResponse() throws IOException {
    // prep mockin the SaslClient
    SimpleSaslClientAuthenticationProvider mockProvider = Mockito.mock(SimpleSaslClientAuthenticationProvider.class);
    SaslClient mockClient = Mockito.mock(SaslClient.class);
    Assert.assertNotNull(mockProvider);
    Assert.assertNotNull(mockClient);
    Mockito.when(mockProvider.createClient(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.anyBoolean(), Mockito.any())).thenReturn(mockClient);
    HBaseSaslRpcClient rpcClient = new HBaseSaslRpcClient(HBaseConfiguration.create(), mockProvider, createTokenMock(), Mockito.mock(InetAddress.class), Mockito.mock(SecurityInfo.class), false);
    // simulate getting an error from a failed saslServer.evaluateResponse
    DataOutputBuffer errorBuffer = new DataOutputBuffer();
    errorBuffer.writeInt(SaslStatus.ERROR.state);
    WritableUtils.writeString(errorBuffer, IOException.class.getName());
    WritableUtils.writeString(errorBuffer, "Invalid Token");
    DataInputBuffer in = new DataInputBuffer();
    in.reset(errorBuffer.getData(), 0, errorBuffer.getLength());
    DataOutputBuffer out = new DataOutputBuffer();
    // simulate that authentication exchange has completed quickly after sending the token
    Mockito.when(mockClient.isComplete()).thenReturn(true);
    rpcClient.saslConnect(in, out);
}
Also used : SimpleSaslClientAuthenticationProvider(org.apache.hadoop.hbase.security.provider.SimpleSaslClientAuthenticationProvider) DataInputBuffer(org.apache.hadoop.io.DataInputBuffer) DataOutputBuffer(org.apache.hadoop.io.DataOutputBuffer) IOException(java.io.IOException) InetAddress(java.net.InetAddress) SaslClient(javax.security.sasl.SaslClient) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 SaslClient (javax.security.sasl.SaslClient)1 SimpleSaslClientAuthenticationProvider (org.apache.hadoop.hbase.security.provider.SimpleSaslClientAuthenticationProvider)1 DataInputBuffer (org.apache.hadoop.io.DataInputBuffer)1 DataOutputBuffer (org.apache.hadoop.io.DataOutputBuffer)1 Test (org.junit.Test)1