|
52 | 52 | import org.apache.hadoop.hbase.util.Bytes; |
53 | 53 | import org.apache.hadoop.io.DataInputBuffer; |
54 | 54 | import org.apache.hadoop.io.DataOutputBuffer; |
| 55 | +import org.apache.hadoop.io.WritableUtils; |
55 | 56 | import org.apache.hadoop.security.token.Token; |
56 | 57 | import org.apache.hadoop.security.token.TokenIdentifier; |
57 | 58 | import org.apache.log4j.Level; |
58 | 59 | import org.apache.log4j.Logger; |
| 60 | +import org.junit.Assert; |
59 | 61 | import org.junit.BeforeClass; |
60 | 62 | import org.junit.ClassRule; |
61 | 63 | import org.junit.Rule; |
@@ -318,4 +320,33 @@ private HBaseSaslRpcClient createSaslRpcClientSimple(String principal, String pa |
318 | 320 | private Token<? extends TokenIdentifier> createTokenMock() { |
319 | 321 | return mock(Token.class); |
320 | 322 | } |
| 323 | + |
| 324 | + @Test(expected = IOException.class) |
| 325 | + public void testFailedEvaluateResponse() throws IOException { |
| 326 | + //prep mockin the SaslClient |
| 327 | + SimpleSaslClientAuthenticationProvider mockProvider = |
| 328 | + Mockito.mock(SimpleSaslClientAuthenticationProvider.class); |
| 329 | + SaslClient mockClient = Mockito.mock(SaslClient.class); |
| 330 | + Assert.assertNotNull(mockProvider); |
| 331 | + Assert.assertNotNull(mockClient); |
| 332 | + Mockito.when(mockProvider.createClient(Mockito.any(), Mockito.any(), Mockito.any(), |
| 333 | + Mockito.any(), Mockito.anyBoolean(), Mockito.any())).thenReturn(mockClient); |
| 334 | + HBaseSaslRpcClient rpcClient = new HBaseSaslRpcClient(HBaseConfiguration.create(), |
| 335 | + mockProvider, createTokenMock(), |
| 336 | + Mockito.mock(InetAddress.class), Mockito.mock(SecurityInfo.class), false); |
| 337 | + |
| 338 | + //simulate getting an error from a failed saslServer.evaluateResponse |
| 339 | + DataOutputBuffer errorBuffer = new DataOutputBuffer(); |
| 340 | + errorBuffer.writeInt(SaslStatus.ERROR.state); |
| 341 | + WritableUtils.writeString(errorBuffer, IOException.class.getName()); |
| 342 | + WritableUtils.writeString(errorBuffer, "Invalid Token"); |
| 343 | + |
| 344 | + DataInputBuffer in = new DataInputBuffer(); |
| 345 | + in.reset(errorBuffer.getData(), 0, errorBuffer.getLength()); |
| 346 | + DataOutputBuffer out = new DataOutputBuffer(); |
| 347 | + |
| 348 | + //simulate that authentication exchange has completed quickly after sending the token |
| 349 | + Mockito.when(mockClient.isComplete()).thenReturn(true); |
| 350 | + rpcClient.saslConnect(in, out); |
| 351 | + } |
321 | 352 | } |
0 commit comments