From e4be06c7c8a4801e375344954e442bb15aa3f636 Mon Sep 17 00:00:00 2001 From: Jeff Storck Date: Fri, 8 Feb 2019 00:08:47 -0500 Subject: [PATCH] NIFI-5967: Removed unused ALLOW_EXPLICIT_KEYTAB private variable Updated Hive_1_1ConnectionPoolTest.testKerberosAuthException to use a mocked KerberosCredentialsService This closes #3272 --- .../dbcp/hive/Hive_1_1ConnectionPool.java | 2 -- .../dbcp/hive/Hive_1_1ConnectionPoolTest.java | 20 +++++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive_1_1-processors/src/main/java/org/apache/nifi/dbcp/hive/Hive_1_1ConnectionPool.java b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive_1_1-processors/src/main/java/org/apache/nifi/dbcp/hive/Hive_1_1ConnectionPool.java index 76ff47ae0a..dd2e1fe606 100644 --- a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive_1_1-processors/src/main/java/org/apache/nifi/dbcp/hive/Hive_1_1ConnectionPool.java +++ b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive_1_1-processors/src/main/java/org/apache/nifi/dbcp/hive/Hive_1_1ConnectionPool.java @@ -65,8 +65,6 @@ import org.apache.nifi.expression.ExpressionLanguageScope; @Tags({"hive", "dbcp", "jdbc", "database", "connection", "pooling", "store"}) @CapabilityDescription("Provides Database Connection Pooling Service for Apache Hive 1.1.x. Connections can be asked from pool and returned after usage.") public class Hive_1_1ConnectionPool extends AbstractControllerService implements Hive_1_1DBCPService { - private static final String ALLOW_EXPLICIT_KEYTAB = "NIFI_ALLOW_EXPLICIT_KEYTAB"; - public static final PropertyDescriptor DATABASE_URL = new PropertyDescriptor.Builder() .name("hive-db-connect-url") .displayName("Database Connection URL") diff --git a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive_1_1-processors/src/test/java/org/apache/nifi/dbcp/hive/Hive_1_1ConnectionPoolTest.java b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive_1_1-processors/src/test/java/org/apache/nifi/dbcp/hive/Hive_1_1ConnectionPoolTest.java index 8bafaa5c6b..631ea7ab65 100644 --- a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive_1_1-processors/src/test/java/org/apache/nifi/dbcp/hive/Hive_1_1ConnectionPoolTest.java +++ b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive_1_1-processors/src/test/java/org/apache/nifi/dbcp/hive/Hive_1_1ConnectionPoolTest.java @@ -30,17 +30,19 @@ import java.security.PrivilegedExceptionAction; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; +import java.util.UUID; import org.apache.commons.dbcp.BasicDataSource; import org.apache.hadoop.security.UserGroupInformation; import org.apache.nifi.components.PropertyDescriptor; import org.apache.nifi.controller.AbstractControllerService; -import org.apache.nifi.hadoop.KerberosProperties; +import org.apache.nifi.kerberos.KerberosCredentialsService; import org.apache.nifi.logging.ComponentLog; import org.apache.nifi.processor.exception.ProcessException; import org.apache.nifi.registry.VariableDescriptor; import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.util.MockConfigurationContext; +import org.apache.nifi.util.MockControllerServiceLookup; import org.apache.nifi.util.MockVariableRegistry; import org.junit.Before; import org.junit.Ignore; @@ -154,23 +156,25 @@ public class Hive_1_1ConnectionPoolTest { final String conf = "src/test/resources/hive-site-security.xml"; final String ktab = "src/test/resources/fake.keytab"; final String kprinc = "bad@PRINCIPAL.COM"; - - KerberosProperties kerbProperties = new KerberosProperties(krb5conf); + final String kerberosCredentialsServiceId = UUID.randomUUID().toString(); Map props = new HashMap() {{ put(Hive_1_1ConnectionPool.DATABASE_URL, "${url}"); put(Hive_1_1ConnectionPool.HIVE_CONFIGURATION_RESOURCES, "${conf}"); - put(kerbProperties.getKerberosKeytab(), "${ktab}"); - put(kerbProperties.getKerberosPrincipal(), "${kprinc}"); + put(Hive_1_1ConnectionPool.KERBEROS_CREDENTIALS_SERVICE, kerberosCredentialsServiceId); }}; MockVariableRegistry registry = new MockVariableRegistry(); registry.setVariable(new VariableDescriptor("url"), URL); registry.setVariable(new VariableDescriptor("conf"), conf); - registry.setVariable(new VariableDescriptor("ktab"), ktab); - registry.setVariable(new VariableDescriptor("kprinc"), kprinc); - MockConfigurationContext context = new MockConfigurationContext(props, null, registry); + MockControllerServiceLookup mockControllerServiceLookup = new MockControllerServiceLookup() {}; + KerberosCredentialsService kerberosCredentialsService = mock(KerberosCredentialsService.class); + when(kerberosCredentialsService.getKeytab()).thenReturn(ktab); + when(kerberosCredentialsService.getPrincipal()).thenReturn(kprinc); + mockControllerServiceLookup.addControllerService(kerberosCredentialsService, kerberosCredentialsServiceId); + + MockConfigurationContext context = new MockConfigurationContext(props, mockControllerServiceLookup, registry); hiveConnectionPool.onConfigured(context); } }