Skip to content

Commit 2cb1cec

Browse files
authored
DRILL-8256: Fix unit tests of Kerberos auth in RPC (#2592)
1 parent bd1cb80 commit 2cb1cec

File tree

8 files changed

+173
-245
lines changed

8 files changed

+173
-245
lines changed

exec/java-exec/src/main/java/org/apache/drill/exec/rpc/security/AuthenticatorProviderImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ public class AuthenticatorProviderImpl implements AuthenticatorProvider {
4545

4646
@SuppressWarnings("unchecked")
4747
public AuthenticatorProviderImpl(final DrillConfig config, final ScanResult scan) throws DrillbitStartupException {
48-
// Skip auth mechanisms setup if user authentication is disabled
49-
if (!config.getBoolean(ExecConstants.USER_AUTHENTICATION_ENABLED)) {
48+
// Skip auth mechanisms setup if no authentication is enabled
49+
if (
50+
!config.getBoolean(ExecConstants.USER_AUTHENTICATION_ENABLED) &&
51+
!config.getBoolean(ExecConstants.BIT_AUTHENTICATION_ENABLED)
52+
) {
5053
return;
5154
}
5255

exec/java-exec/src/test/java/org/apache/drill/exec/rpc/data/TestBitBitKerberos.java

Lines changed: 141 additions & 230 deletions
Large diffs are not rendered by default.

exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitKerberos.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.drill.exec.rpc.security.KerberosHelper;
2828
import org.apache.drill.exec.rpc.user.UserRpcMetrics;
2929
import org.apache.drill.exec.rpc.user.security.testing.UserAuthenticatorTestImpl;
30+
import org.apache.drill.test.BaseDirTestWatcher;
3031
import org.apache.drill.test.ClientFixture;
3132
import org.apache.drill.test.ClusterFixture;
3233
import org.apache.drill.test.ClusterFixtureBuilder;
@@ -51,7 +52,7 @@ public class TestUserBitKerberos extends ClusterTest {
5152
@BeforeClass
5253
public static void setupTest() throws Exception {
5354
krbHelper = new KerberosHelper(TestUserBitKerberos.class.getSimpleName(), null);
54-
krbHelper.setupKdc(dirTestWatcher.getTmpDir());
55+
krbHelper.setupKdc(BaseDirTestWatcher.createTempDir(dirTestWatcher.getTmpDir()));
5556
cluster = defaultClusterConfig().build();
5657
}
5758

exec/java-exec/src/test/java/org/apache/drill/exec/rpc/user/security/TestUserBitKerberosEncryption.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.drill.exec.rpc.user.security;
1919

2020
import org.apache.drill.shaded.guava.com.google.common.collect.Lists;
21+
import org.apache.drill.test.BaseDirTestWatcher;
2122
import org.apache.drill.test.ClientFixture;
2223
import org.apache.drill.test.ClusterFixture;
2324
import org.apache.drill.test.ClusterFixtureBuilder;
@@ -56,7 +57,7 @@ public class TestUserBitKerberosEncryption extends ClusterTest {
5657
@BeforeClass
5758
public static void setupTest() throws Exception {
5859
krbHelper = new KerberosHelper(TestUserBitKerberosEncryption.class.getSimpleName(), null);
59-
krbHelper.setupKdc(dirTestWatcher.getTmpDir());
60+
krbHelper.setupKdc(BaseDirTestWatcher.createTempDir(dirTestWatcher.getTmpDir()));
6061
cluster = defaultClusterConfig().build();
6162
}
6263

exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/spnego/TestDrillSpnegoAuthenticator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public class TestDrillSpnegoAuthenticator extends BaseTest {
8181
@BeforeClass
8282
public static void setupTest() throws Exception {
8383
spnegoHelper = new KerberosHelper(TestDrillSpnegoAuthenticator.class.getSimpleName(), primaryName);
84-
spnegoHelper.setupKdc(dirTestWatcher.getTmpDir());
84+
spnegoHelper.setupKdc(BaseDirTestWatcher.createTempDir(dirTestWatcher.getTmpDir()));
8585

8686
// (1) Refresh Kerberos config.
8787
// This disabled call to an unsupported internal API does not appear to be

exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/spnego/TestSpnegoAuthentication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public class TestSpnegoAuthentication extends BaseTest {
7676
@BeforeClass
7777
public static void setupTest() throws Exception {
7878
spnegoHelper = new KerberosHelper(TestSpnegoAuthentication.class.getSimpleName(), primaryName);
79-
spnegoHelper.setupKdc(dirTestWatcher.getTmpDir());
79+
spnegoHelper.setupKdc(BaseDirTestWatcher.createTempDir(dirTestWatcher.getTmpDir()));
8080

8181
// (1) Refresh Kerberos config.
8282
// This disabled call to an unsupported internal API does not appear to be

exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/spnego/TestSpnegoConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class TestSpnegoConfig extends BaseTest {
5656
@BeforeClass
5757
public static void setupTest() throws Exception {
5858
spnegoHelper = new KerberosHelper(TestSpnegoConfig.class.getSimpleName(), primaryName);
59-
spnegoHelper.setupKdc(dirTestWatcher.getTmpDir());
59+
spnegoHelper.setupKdc(BaseDirTestWatcher.createTempDir(dirTestWatcher.getTmpDir()));
6060

6161
// (1) Refresh Kerberos config.
6262
// This disabled call to an unsupported internal API does not appear to be

exec/java-exec/src/test/java/org/apache/drill/test/QueryBuilder.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,19 +281,31 @@ public QueryBuilder physical(String plan) {
281281
}
282282

283283
/**
284-
* Run a query contained in a resource file.
284+
* Parse a single SQL statement (with optional ending semi-colon) from
285+
* the resource provided.
285286
*
286-
* @param resource Name of the resource
287+
* @param resource the resource containing exactly one SQL statement, with
288+
* optional ending semi-colon
287289
* @return this builder
288290
*/
289-
public QueryBuilder sqlResource(String resource) {
290-
sql(ClusterFixture.loadResource(resource));
291-
return this;
291+
public QueryBuilder sqlResource(String resource) throws IOException {
292+
String script = ClusterFixture.loadResource(resource);
293+
StatementParser parser = new StatementParser(script);
294+
String sql = parser.parseNext();
295+
if (sql == null) {
296+
throw new IllegalArgumentException("No query found");
297+
}
298+
return sql(sql);
292299
}
293300

294-
public QueryBuilder sqlResource(String resource, Object... args) {
295-
sql(ClusterFixture.loadResource(resource), args);
296-
return this;
301+
public QueryBuilder sqlResource(String resource, Object... args) throws IOException {
302+
String script = ClusterFixture.loadResource(resource);
303+
StatementParser parser = new StatementParser(script);
304+
String sql = parser.parseNext();
305+
if (sql == null) {
306+
throw new IllegalArgumentException("No query found");
307+
}
308+
return sql(sql, args);
297309
}
298310

299311
public QueryBuilder physicalResource(String resource) {

0 commit comments

Comments
 (0)