Skip to content

Commit 3ea6b8b

Browse files
anmolnarwchevreuil
authored andcommitted
HBASE-28337 Positive connection test in TestShadeSaslAuthenticationProvider runs with Kerberos instead of Shade authentication (#5659)
Signed-off-by: Wellington Chevreuil <wchevreuil@apache.org>
1 parent a04843d commit 3ea6b8b

File tree

2 files changed

+17
-32
lines changed

2 files changed

+17
-32
lines changed

hbase-client/src/main/java/org/apache/hadoop/hbase/security/NettyHBaseSaslRpcClientHandler.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ public byte[] run() throws Exception {
130130
// Mechanisms which have multiple steps will not return true on `SaslClient#isComplete()`
131131
// until the handshake has fully completed. Mechanisms which only send a single buffer may
132132
// return true on `isComplete()` after that initial response is calculated.
133+
134+
// HBASE-28337 We still want to check if the SaslClient completed the handshake, because
135+
// there are certain mechs like PLAIN which doesn't have a server response after the
136+
// initial authentication request. We cannot remove this tryComplete(), otherwise mechs
137+
// like PLAIN will fail with call timeout.
138+
tryComplete(ctx);
133139
} catch (Exception e) {
134140
// the exception thrown by handlerAdded will not be passed to the exceptionCaught below
135141
// because netty will remove a handler if handlerAdded throws an exception.

hbase-examples/src/test/java/org/apache/hadoop/hbase/security/provider/example/TestShadeSaslAuthenticationProvider.java

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import java.io.File;
2828
import java.io.IOException;
2929
import java.io.OutputStreamWriter;
30-
import java.io.PrintWriter;
31-
import java.io.StringWriter;
3230
import java.nio.charset.StandardCharsets;
3331
import java.security.PrivilegedExceptionAction;
3432
import java.util.ArrayList;
@@ -67,10 +65,8 @@
6765
import org.apache.hadoop.hbase.util.Bytes;
6866
import org.apache.hadoop.hbase.util.CommonFSUtils;
6967
import org.apache.hadoop.hbase.util.Pair;
70-
import org.apache.hadoop.ipc.RemoteException;
7168
import org.apache.hadoop.minikdc.MiniKdc;
7269
import org.apache.hadoop.security.UserGroupInformation;
73-
import org.apache.hadoop.security.token.SecretManager.InvalidToken;
7470
import org.junit.AfterClass;
7571
import org.junit.Before;
7672
import org.junit.BeforeClass;
@@ -82,8 +78,6 @@
8278
import org.slf4j.Logger;
8379
import org.slf4j.LoggerFactory;
8480

85-
import org.apache.hbase.thirdparty.com.google.common.base.Throwables;
86-
8781
@Category({ MediumTests.class, SecurityTests.class })
8882
public class TestShadeSaslAuthenticationProvider {
8983
private static final Logger LOG =
@@ -210,21 +204,23 @@ public String run() throws Exception {
210204
@Test
211205
public void testPositiveAuthentication() throws Exception {
212206
final Configuration clientConf = new Configuration(CONF);
213-
try (Connection conn = ConnectionFactory.createConnection(clientConf)) {
207+
try (Connection conn1 = ConnectionFactory.createConnection(clientConf)) {
214208
UserGroupInformation user1 =
215209
UserGroupInformation.createUserForTesting("user1", new String[0]);
216-
user1.addToken(ShadeClientTokenUtil.obtainToken(conn, "user1", USER1_PASSWORD));
210+
user1.addToken(ShadeClientTokenUtil.obtainToken(conn1, "user1", USER1_PASSWORD));
217211
user1.doAs(new PrivilegedExceptionAction<Void>() {
218212
@Override
219213
public Void run() throws Exception {
220-
try (Table t = conn.getTable(tableName)) {
221-
Result r = t.get(new Get(Bytes.toBytes("r1")));
222-
assertNotNull(r);
223-
assertFalse("Should have read a non-empty Result", r.isEmpty());
224-
final Cell cell = r.getColumnLatestCell(Bytes.toBytes("f1"), Bytes.toBytes("q1"));
225-
assertTrue("Unexpected value", CellUtil.matchingValue(cell, Bytes.toBytes("1")));
214+
try (Connection conn = ConnectionFactory.createConnection(clientConf)) {
215+
try (Table t = conn.getTable(tableName)) {
216+
Result r = t.get(new Get(Bytes.toBytes("r1")));
217+
assertNotNull(r);
218+
assertFalse("Should have read a non-empty Result", r.isEmpty());
219+
final Cell cell = r.getColumnLatestCell(Bytes.toBytes("f1"), Bytes.toBytes("q1"));
220+
assertTrue("Unexpected value", CellUtil.matchingValue(cell, Bytes.toBytes("1")));
226221

227-
return null;
222+
return null;
223+
}
228224
}
229225
}
230226
});
@@ -262,7 +258,6 @@ public Void run() throws Exception {
262258
} catch (Exception e) {
263259
LOG.info("Caught exception in negative Master connectivity test", e);
264260
assertEquals("Found unexpected exception", pair.getSecond(), e.getClass());
265-
validateRootCause(Throwables.getRootCause(e));
266261
}
267262
return null;
268263
}
@@ -279,7 +274,6 @@ public Void run() throws Exception {
279274
} catch (Exception e) {
280275
LOG.info("Caught exception in negative RegionServer connectivity test", e);
281276
assertEquals("Found unexpected exception", pair.getSecond(), e.getClass());
282-
validateRootCause(Throwables.getRootCause(e));
283277
}
284278
return null;
285279
}
@@ -293,19 +287,4 @@ public Void run() throws Exception {
293287
}
294288
});
295289
}
296-
297-
void validateRootCause(Throwable rootCause) {
298-
LOG.info("Root cause was", rootCause);
299-
if (rootCause instanceof RemoteException) {
300-
RemoteException re = (RemoteException) rootCause;
301-
IOException actualException = re.unwrapRemoteException();
302-
assertEquals(InvalidToken.class, actualException.getClass());
303-
} else {
304-
StringWriter writer = new StringWriter();
305-
rootCause.printStackTrace(new PrintWriter(writer));
306-
String text = writer.toString();
307-
assertTrue("Message did not contain expected text",
308-
text.contains(InvalidToken.class.getName()));
309-
}
310-
}
311290
}

0 commit comments

Comments
 (0)