@Test public void helper_shouldPutVersion_afterDatabaseReset() throws IOException { Config config = ConfigFactory.empty() .withValue("database.reset", ConfigValueFactory.fromAnyRef(true)); SPO systemProperties = new SPO(config); systemProperties.setDataBaseDir(databaseDir); systemProperties.setDatabaseVersion(33); final File testFile = createFile(); assertTrue(testFile.exists()); resetHelper.process(systemProperties); assertEquals(new Integer(33), resetHelper.getDatabaseVersion(versionFile)); assertFalse(testFile.exists()); // reset should have cleared file }
private SystemProperties withConfig(int databaseVersion, Initializer.DatabaseVersionHandler.Behavior behavior) { Config config = ConfigFactory.empty() // reset is true for tests .withValue("database.reset", ConfigValueFactory.fromAnyRef(false)); if (behavior != null) { config = config.withValue("database.incompatibleDatabaseBehavior", ConfigValueFactory.fromAnyRef(behavior.toString().toLowerCase())); } SPO systemProperties = new SPO(config); systemProperties.setDataBaseDir(databaseDir); systemProperties.setDatabaseVersion(databaseVersion); return systemProperties; }
private SystemProperties loadGenesis(String genesisFile, String genesisResource) { Config config = ConfigFactory.empty(); if (genesisResource != null) { config = config.withValue("genesis", ConfigValueFactory.fromAnyRef(genesisResource)); } if (genesisFile != null) { config = config.withValue("genesisFile", ConfigValueFactory.fromAnyRef(genesisFile)); } SystemProperties properties = new SystemProperties(config); properties.getGenesis(); return properties; }
private Config expectedConfiguration() { return ConfigFactory.parseMap(Map.ofEntries( entry(GAME_NET_IP, CFG_NET_IP), entry(GAME_NET_PORT, CFG_NET_PORT), entry(GAME_NET_TIMEOUT, 2000), entry(GAME_NET_RETRY_COUNT, 10), entry(GAME_EXE_PATH, gameRoot().toString()), entry(GAME_EXE_BUILD, CFG_EXE_BUILD_NEW), entry(GAME_EXE_FILE, CFG_EXE_FILE), entry(GAME_EXE_DATA_VER, CFG_EXE_DATA_VER), entry(GAME_EXE_IS_64, true), entry(GAME_WINDOW_W, CFG_WINDOW_W), entry(GAME_WINDOW_H, CFG_WINDOW_H), entry(GAME_WINDOW_X, CFG_WINDOW_X), entry(GAME_WINDOW_Y, CFG_WINDOW_Y), entry(GAME_WINDOW_MODE, 0) )).withValue(GAME_CLI_DATA_DIR, ConfigValueFactory.fromAnyRef(nothing())) .withValue(GAME_CLI_EGL_PATH, ConfigValueFactory.fromAnyRef(nothing())) .withValue(GAME_CLI_OS_MESA_PATH, ConfigValueFactory.fromAnyRef(nothing())) .withValue(GAME_CLI_DATA_DIR, ConfigValueFactory.fromAnyRef(nothing())) .withValue(GAME_CLI_TEMP_DIR, ConfigValueFactory.fromAnyRef(nothing())) .withValue(GAME_CLI_VERBOSE, ConfigValueFactory.fromAnyRef(nothing())); }
private SystemProperties withConfig(int databaseVersion, Behavior behavior) { Config config = ConfigFactory.empty() // reset is true for tests .withValue("database.reset", ConfigValueFactory.fromAnyRef(false)); if (behavior != null) { config = config.withValue("database.incompatibleDatabaseBehavior", ConfigValueFactory.fromAnyRef(behavior.toString().toLowerCase())); } SPO systemProperties = new SPO(config); systemProperties.setDataBaseDir(databaseDir); systemProperties.setDatabaseVersion(databaseVersion); return systemProperties; }
@Test public void testDefaultConnection() throws Exception { // Default root from sabot-module.conf assertNull(zooKeeperServer.getZKClient().exists("/dremio/test-path", false)); final SabotConfig config = DEFAULT_SABOT_CONFIG .withValue(ZK_ROOT, ConfigValueFactory.fromAnyRef("dremio/test-path")) .withValue(CLUSTER_ID, ConfigValueFactory.fromAnyRef("test-cluster-id")); try(ZKClusterClient client = new ZKClusterClient(config, new Provider<Integer>() { @Override public Integer get() { return zooKeeperServer.getPort(); } })) { client.start(); ZKServiceSet serviceSet = client.newServiceSet("coordinator"); serviceSet.register(NodeEndpoint.newBuilder().setAddress("foo").build()); Stat stat = zooKeeperServer.getZKClient().exists("/dremio/test-path/test-cluster-id/coordinator", false); assertNotNull(stat); assertEquals(1, stat.getNumChildren()); } }
/** * Remove this once all scripts stop referencing these old properties. */ @Deprecated private static Config applyLegacySystemProperties(Config config){ // legacy stuff for now. config = setSystemProperty(config, "dremd.write", LOCAL_WRITE_PATH_STRING); config = setSystemProperty(config, "dremio_autoPort", DEBUG_AUTOPORT_BOOL); config = setSystemProperty(config, "dremd.master", MASTER_NODE_STRING); config = setSystemProperty(config, "dremd.masterPort", MASTER_PORT_INT); config = setSystemProperty(config, "dac_prepopulate", DEBUG_PREPOPULATE_BOOL); config = setSystemProperty(config, "dremio_allowTestApis", DEBUG_ALLOW_TEST_APIS_BOOL); config = setSystemProperty(config, "dremd.localPort", SERVER_PORT_INT); config = setSystemProperty(config, "dremd.httpPort", WEB_PORT_INT); if("LOCAL".equalsIgnoreCase(System.getProperty("dremd.mode"))){ config = config.withValue(DEBUG_SINGLE_NODE_BOOL, ConfigValueFactory.fromAnyRef(true)); logger.info("Applying provided leagcy system property to config: -Ddremd.mode=LOCAL"); } return config; }
private static Config applySystemProperties(Config config, Config reference){ for (Entry<String, ConfigValue> entry : reference.entrySet()) { String property = System.getProperty(entry.getKey()); if (property != null && !property.isEmpty()) { // hack to deal with array of strings if (property.startsWith("[") && property.endsWith("]")) { property = property.substring(1, property.length()-1); if (property.trim().isEmpty()) { continue; } String[] strings = property.split(","); if (strings != null && strings.length > 0) { List<String> listStrings = new ArrayList<>(); for (String str : strings) { listStrings.add(str.trim()); } config = config.withValue(entry.getKey(), ConfigValueFactory.fromAnyRef(listStrings)); } } else { config = config.withValue(entry.getKey(), ConfigValueFactory.fromAnyRef(property)); } logger.info("Applying provided system property to config: -D{}={}", entry.getKey(), property); } } return config; }
@Test public void testHandlerReflection() { Config config = ConfigFactory.load().withValue("bag.30", ConfigValueFactory.fromAnyRef(BagForTest.class.getName())); BaggageHandlerRegistry registry = BaggageHandlerRegistry.create(config); assertEquals(1, registry.registrations.keys.length); assertEquals(1, registry.registrations.handlers.length); assertEquals(BagKey.indexed(30), registry.registrations.keys[0]); assertEquals(handler, registry.registrations.handlers[0]); BaggageHandlerForTest handler2 = new BaggageHandlerForTest(); registry.doAdd(BagKey.indexed(5), handler2); assertEquals(2, registry.registrations.keys.length); assertEquals(2, registry.registrations.handlers.length); assertEquals(BagKey.indexed(5), registry.registrations.keys[0]); assertEquals(handler2, registry.registrations.handlers[0]); assertEquals(BagKey.indexed(30), registry.registrations.keys[1]); assertEquals(handler, registry.registrations.handlers[1]); }
@Test public void accessDeniedCreatesUserWithPassword() throws Exception { Config config = defaultConfig().withValue(PASSWORD.toString(), ConfigValueFactory.fromAnyRef("password")); when(dbTestStatement.getMetaData()).thenThrow(new SQLException("access denied")); PrepareDatabaseRunner runner = new PrepareDatabaseRunner(config); SwingUtilities.invokeLater(runner); enterSuperUser(robot.finder()); while (! runner.complete) Thread.yield(); if (runner.thrownException != null) runner.thrownException.printStackTrace(); assertThat(runner.createTables).isTrue(); assertThat(runner.thrownException).isNull(); verify(updateProgress).accept("Creating database..."); verifyTestDatabaseQuery(); assertThat(superConnections).hasSize(2); verify(superConnections.get(0), never()).prepareStatement(anyString()); verify(superConnections.get(0), never()).createStatement(); verifyPreparedStatement(superConnections.get(1), "create user if not exists ? identified by ?", config.getString(USER.toString()), config.getString(PASSWORD.toString())); verify(superConnections.get(1)).createStatement(); verifyCreateDatabase(config); verifyCloseConnections(); }
@BeforeClass public static void setupCluster() { // Create a new DrillConfig which has user authentication enabled and authenticator set to // UserAuthenticatorTestImpl. final Properties props = cloneDefaultTestConfigProperties(); final DrillConfig newConfig = new DrillConfig(DrillConfig.create(props) .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef("true")) .withValue(ExecConstants.USER_AUTHENTICATOR_IMPL, ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE)), false); final Properties connectionProps = new Properties(); connectionProps.setProperty(DrillProperties.USER, "anonymous"); connectionProps.setProperty(DrillProperties.PASSWORD, "anything works!"); updateTestCluster(3, newConfig, connectionProps); }
@Test // Should pass because the keystore password will be used. public void testNoKeyPassword() throws Exception { DrillConfig testConfig = new DrillConfig(DrillConfig.create(sslConfig) .withValue(ExecConstants.SSL_KEY_PASSWORD, ConfigValueFactory.fromAnyRef("")), false); // Start an SSL enabled cluster boolean failureCaught = false; try { updateTestCluster(1, testConfig, initProps); } catch (Exception e) { failureCaught = true; } assertEquals(failureCaught, false); }
/** * Test invalid {@link SpnegoConfig} with missing keytab and principal * @throws Exception */ @Test public void testInvalidSpnegoConfig() throws Exception { // Invalid configuration for SPNEGO try { final DrillConfig newConfig = new DrillConfig(DrillConfig.create() .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(true)) .withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain"))) .withValue(ExecConstants.USER_AUTHENTICATOR_IMPL, ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE)), false); final SpnegoConfig spnegoConfig = new SpnegoConfig(newConfig); spnegoConfig.validateSpnegoConfig(); fail(); } catch (Exception ex) { assertTrue(ex instanceof DrillException); } }
@Test public void testAcksWithSingleData() throws Exception { sourceConfiguration = sourceConfiguration.withValue("akka.remote.auto-ack", ConfigValueFactory.fromAnyRef("on")); source = new AkkaTestSource(sourceConfiguration); feederActorSystem.actorOf( Props.create(FeederActor.class, FeederActor.MessageTypes.SINGLE_DATA), feederActorName); source.open(config); sourceThread.start(); while (DummySourceContext.numElementsCollected != 1) { Thread.sleep(5); } int noOfRetries = 1; while (Message.ACK_MESSAGE == null && noOfRetries <= 5) { Thread.sleep(5); noOfRetries++; } Assert.assertEquals("ack", Message.ACK_MESSAGE); }
@DataProvider(value = { "true", "false" }) @Test public void codahaleMetricsEngine_is_configured_with_jvm_metrics_on_or_off_based_on_property(boolean reportJvmMetrics) { // given configForTesting = generateAppConfigWithMetricsEnabledOrDisabled(true, true, false) .withValue("metrics.reportJvmMetrics", ConfigValueFactory.fromAnyRef(reportJvmMetrics)); appGuiceModule = new AppGuiceModule(configForTesting); injector = generateInjector(appGuiceModule, configForTesting); // when CodahaleMetricsEngine engine = injector.getInstance(CodahaleMetricsEngine.class); // then assertThat(Whitebox.getInternalState(engine, "jvmMetricsAdded")).isEqualTo(reportJvmMetrics); }
@BeforeClass public static void setupCluster() throws Exception { // Create a new DrillConfig which has user authentication enabled and test authenticator set final DrillConfig config = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties()) .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(true)) .withValue(ExecConstants.USER_AUTHENTICATOR_IMPL, ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE)), false); final Properties connectionProps = new Properties(); connectionProps.setProperty(DrillProperties.USER, PROCESS_USER); connectionProps.setProperty(DrillProperties.PASSWORD, PROCESS_USER_PASSWORD); updateTestCluster(1, config, connectionProps); // Add user "admin" to admin username list test(String.format("ALTER SYSTEM SET `%s`='%s,%s'", ExecConstants.ADMIN_USERS_KEY, ADMIN_USER, PROCESS_USER)); // Set "admingrp" to admin username list test(String.format("ALTER SYSTEM SET `%s`='%s'", ExecConstants.ADMIN_USER_GROUPS_KEY, ADMIN_GROUP)); }
@Test public void testGetImmediateDependentSteps() { Step step1 = new BatchStep("step1", ConfigFactory.empty().withValue("dependencies", ConfigValueFactory.fromIterable(Sets.newHashSet()))); Step step2 = new BatchStep("step2", ConfigFactory.empty().withValue("dependencies", ConfigValueFactory.fromIterable(Sets.newHashSet("step1")))); Step step3 = new BatchStep("step3", ConfigFactory.empty().withValue("dependencies", ConfigValueFactory.fromIterable(Sets.newHashSet("step2")))); Set<Step> steps = Sets.newHashSet(step1, step2, step3); Set<Step> step1ImmediateDependents = StepUtils.getImmediateDependentSteps(step1, steps); Set<Step> step2ImmediateDependents = StepUtils.getImmediateDependentSteps(step2, steps); Set<Step> step3ImmediateDependents = StepUtils.getImmediateDependentSteps(step3, steps); assertEquals(step1ImmediateDependents.size(), 1); assertEquals(step2ImmediateDependents.size(), 1); assertEquals(step3ImmediateDependents.size(), 0); assertEquals(step1ImmediateDependents, Sets.newHashSet(step2)); assertEquals(step2ImmediateDependents, Sets.newHashSet(step3)); assertEquals(step3ImmediateDependents, Sets.newHashSet()); }
@Test public void testGetPartialKey() throws Exception { addEntriesToHBase(); Table table = connection.getTable(TableName.valueOf(TABLE)); scanAndCountTable(table, INPUT_ROWS * 4); Config config = ConfigUtils.configFromResource("/hbase/hbase-output-test.conf").getConfig("output"); config = config.withValue("zookeeper", ConfigValueFactory.fromAnyRef("localhost:" + utility.getZkCluster().getClientPort())); HBaseOutput output = new HBaseOutput(); output.configure(config); StructType partialKeySchema = new StructType(new StructField[] { new StructField("symbol", DataTypes.StringType, false, null) }); List<Row> filters = Lists.newArrayList(); filters.add(new RowWithSchema(partialKeySchema, "AAPL")); filters.add(new RowWithSchema(partialKeySchema, "GOOG")); Iterable<Row> filtered = output.getExistingForFilters(filters); assertEquals(25, Iterables.size(filtered)); }
@Test public void testTranslation() throws Exception { String kvps = "field3=100.9---field6=---field7=true---field2=-99.8---field1=hello---field4=-1---field5=120"; Config config = ConfigFactory.empty() .withValue(KVPTranslator.FIELD_NAMES_CONFIG_NAME, ConfigValueFactory.fromIterable( Lists.newArrayList("field1", "field2", "field3", "field4", "field5", "field6", "field7"))) .withValue(KVPTranslator.FIELD_TYPES_CONFIG_NAME, ConfigValueFactory.fromIterable( Lists.newArrayList("string", "float", "double", "int", "long", "int", "boolean"))) .withValue(KVPTranslator.KVP_DELIMITER_CONFIG_NAME, ConfigValueFactory.fromAnyRef("---")) .withValue(KVPTranslator.FIELD_DELIMITER_CONFIG_NAME, ConfigValueFactory.fromAnyRef("=")); Translator<String, String> t = new KVPTranslator(); t.configure(config); Row r = t.translate(null, kvps).iterator().next(); assertEquals(r.length(), 7); assertEquals(r.get(0), "hello"); assertEquals(r.get(1), -99.8f); assertEquals(r.get(2), 100.9d); assertEquals(r.get(3), -1); assertEquals(r.get(4), 120L); assertEquals(r.get(5), null); assertEquals(r.get(6), true); }
@Test public void testTranslation() throws Exception { String delimited = "hello%$-100.1%$1000.5%$99%$888%$%$false"; Config config = ConfigFactory.empty() .withValue(DelimitedTranslator.FIELD_NAMES_CONFIG_NAME, ConfigValueFactory.fromIterable( Lists.newArrayList("field1", "field2", "field3", "field4", "field5", "field6", "field7"))) .withValue(DelimitedTranslator.FIELD_TYPES_CONFIG_NAME, ConfigValueFactory.fromIterable( Lists.newArrayList("string", "float", "double", "int", "long", "int", "boolean"))) .withValue(DelimitedTranslator.DELIMITER_CONFIG_NAME, ConfigValueFactory.fromAnyRef("%$")); Translator<String, String> t = new DelimitedTranslator(); t.configure(config); Row r = t.translate(null, delimited).iterator().next(); assertEquals(r.length(), 7); assertEquals(r.get(0), "hello"); assertEquals(r.get(1), -100.1f); assertEquals(r.get(2), 1000.5d); assertEquals(r.get(3), 99); assertEquals(r.get(4), 888L); assertEquals(r.get(5), null); assertEquals(r.get(6), false); }
@Test public void testCarryForwardWhenNull() { p = new EventTimeHistoryPlanner(); config = config.withValue(EventTimeHistoryPlanner.CARRY_FORWARD_CONFIG_NAME, ConfigValueFactory.fromAnyRef(true)); p.configure(config); existing.add(new RowWithSchema(existingSchema, "a", "hello", 100L, 100L, EventTimeHistoryPlanner.FAR_FUTURE_MILLIS, EventTimeHistoryPlanner.CURRENT_FLAG_YES, "")); arriving.add(new RowWithSchema(arrivingSchema, "a", null, 200L)); Row key = new RowWithSchema(keySchema, "a"); List<PlannedRow> planned = p.planMutationsForKey(key, arriving, existing); assertEquals(planned.size(), 2); assertEquals(planned.get(0).getMutationType(), MutationType.UPDATE); assertEquals(RowUtils.get(planned.get(0).getRow(), "value"), "hello"); assertEquals(RowUtils.get(planned.get(0).getRow(), "startdate"), 100L); assertEquals(RowUtils.get(planned.get(0).getRow(), "enddate"), 199L); assertEquals(RowUtils.get(planned.get(0).getRow(), "currentflag"), EventTimeHistoryPlanner.CURRENT_FLAG_NO); assertEquals(planned.get(1).getMutationType(), MutationType.INSERT); assertEquals(RowUtils.get(planned.get(1).getRow(), "value"), "hello"); assertEquals(RowUtils.get(planned.get(1).getRow(), "startdate"), 200L); assertEquals(RowUtils.get(planned.get(1).getRow(), "enddate"), EventTimeHistoryPlanner.FAR_FUTURE_MILLIS); assertEquals(RowUtils.get(planned.get(1).getRow(), "currentflag"), EventTimeHistoryPlanner.CURRENT_FLAG_YES); }
/** * register class with default kryo serializers. */ private Config registerSerializers(Config config, Map<String, String> userSerializers) { Map<String, String> serializers = new HashMap<>(); serializers.put("org.apache.beam.sdk.util.WindowedValue$ValueInGlobalWindow", ""); serializers.put("org.apache.beam.sdk.util.WindowedValue$TimestampedValueInSingleWindow", ""); serializers.put("org.apache.beam.sdk.util.WindowedValue$TimestampedValueInGlobalWindow", ""); serializers.put("org.apache.beam.sdk.util.WindowedValue$TimestampedValueInMultipleWindows", ""); serializers.put("org.apache.beam.sdk.transforms.windowing.PaneInfo", ""); serializers.put("org.apache.beam.sdk.transforms.windowing.PaneInfo$Timing", ""); serializers.put("org.joda.time.Instant", ""); serializers.put("org.apache.beam.sdk.values.KV", ""); serializers.put("org.apache.beam.sdk.transforms.windowing.IntervalWindow", ""); serializers.put("org.apache.beam.sdk.values.TimestampedValue", ""); serializers.put( "org.apache.beam.runners.gearpump.translators.utils.TranslatorUtils$RawUnionValue", ""); if (userSerializers != null && !userSerializers.isEmpty()) { serializers.putAll(userSerializers); } return config.withValue(GEARPUMP_SERIALIZERS, ConfigValueFactory.fromMap(serializers)); }
@Test public void testValueSource() { GearpumpPipelineOptions options = PipelineOptionsFactory.create().as(GearpumpPipelineOptions.class); Config config = ClusterConfig.master(null); config = config.withValue(Constants.APPLICATION_TOTAL_RETRIES(), ConfigValueFactory.fromAnyRef(0)); EmbeddedCluster cluster = new EmbeddedCluster(config); cluster.start(); options.setEmbeddedCluster(cluster); options.setRunner(GearpumpRunner.class); options.setParallelism(1); Pipeline p = Pipeline.create(options); List<String> values = Lists.newArrayList("1", "2", "3", "4", "5"); ValuesSource<String> source = new ValuesSource<>(values, StringUtf8Coder.of()); p.apply(Read.from(source)).apply(ParDo.of(new ResultCollector())); p.run().waitUntilFinish(); cluster.stop(); Assert.assertEquals(Sets.newHashSet(values), ResultCollector.RESULTS); }
/** * Validate when none of the security mechanism is specified in the * {@link ExecConstants#HTTP_AUTHENTICATION_MECHANISMS}, FORM security handler is still configured correctly when * authentication is enabled along with PAM authenticator module. * @throws Exception */ @Test public void testConfigBackwardCompatibility() throws Exception { final DrillConfig newConfig = new DrillConfig(DrillConfig.create() .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(true)), false); final ScanResult scanResult = ClassPathScanner.fromPrescan(newConfig); final AuthenticatorProviderImpl authenticatorProvider = Mockito.mock(AuthenticatorProviderImpl.class); Mockito.when(authenticatorProvider.containsFactory(PlainFactory.SIMPLE_NAME)).thenReturn(true); final DrillbitContext context = Mockito.mock(DrillbitContext.class); Mockito.when(context.getClasspathScan()).thenReturn(scanResult); Mockito.when(context.getConfig()).thenReturn(newConfig); Mockito.when(context.getAuthProvider()).thenReturn(authenticatorProvider); final DrillHttpSecurityHandlerProvider securityProvider = new DrillHttpSecurityHandlerProvider(newConfig, context); assertTrue(securityProvider.isFormEnabled()); assertTrue(!securityProvider.isSpnegoEnabled()); }
@BeforeClass public static void setup() { final DrillConfig newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties()) .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(true)) .withValue(ExecConstants.USER_AUTHENTICATOR_IMPL, ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE)) .withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain"))) .withValue(ExecConstants.USER_ENCRYPTION_SASL_ENABLED, ConfigValueFactory.fromAnyRef(false)), false); final Properties connectionProps = new Properties(); connectionProps.setProperty(DrillProperties.USER, "anonymous"); connectionProps.setProperty(DrillProperties.PASSWORD, "anything works!"); updateTestCluster(1, newConfig, connectionProps); }
/** * Test showing when Drillbit is not configured for authentication whereas client explicitly requested for PLAIN * authentication then connection succeeds without authentication. * @throws Exception */ @Test public void testDisableDrillbitAuth_EnableClientAuthPlain() throws Exception { final DrillConfig newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties()) .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(false)), false); final Properties connectionProps = new Properties(); connectionProps.setProperty(DrillProperties.USER, "anonymous"); connectionProps.setProperty(DrillProperties.PASSWORD, "anything works!"); try { updateTestCluster(1, newConfig, connectionProps); } catch (Exception ex) { fail(); } }
/** * Test showing when Drillbit is not configured for authentication whereas client explicitly requested for Kerberos * authentication then connection fails due to new check before SASL Handshake. * @throws Exception */ @Test public void testDisableDrillbitAuth_EnableClientAuthKerberos() throws Exception { final DrillConfig newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties()) .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(false)), false); final Properties connectionProps = new Properties(); connectionProps.setProperty(DrillProperties.AUTH_MECHANISM, "kerberos"); try { updateTestCluster(1, newConfig, connectionProps); fail(); } catch (Exception ex) { assertTrue(ex.getCause() instanceof NonTransientRpcException); assertTrue(!(ex.getCause().getCause() instanceof SaslException)); } }
/** * Test showing failure before SASL handshake when Drillbit is not configured for authentication whereas client * explicitly requested for encrypted connection. * @throws Exception */ @Test public void testDisableDrillbitAuth_EnableClientEncryption() throws Exception { final DrillConfig newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties()) .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(false)), false); final Properties connectionProps = new Properties(); connectionProps.setProperty(DrillProperties.USER, "anonymous"); connectionProps.setProperty(DrillProperties.PASSWORD, "anything works!"); connectionProps.setProperty(DrillProperties.SASL_ENCRYPT, "true"); try { updateTestCluster(1, newConfig, connectionProps); fail(); } catch (Exception ex) { assertTrue(ex.getCause() instanceof NonTransientRpcException); assertTrue(!(ex.getCause().getCause() instanceof SaslException)); } }
/** * Test showing failure in SASL handshake when Drillbit is configured for authentication only whereas client doesn't * provide any security properties like username/password in this case. * @throws Exception */ @Test public void testEnableDrillbitAuth_DisableClientAuth() throws Exception { final DrillConfig newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties()) .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(true)) .withValue(ExecConstants.USER_AUTHENTICATOR_IMPL, ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE)) .withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain"))) .withValue(ExecConstants.USER_ENCRYPTION_SASL_ENABLED, ConfigValueFactory.fromAnyRef(false)), false); final Properties connectionProps = new Properties(); try { updateTestCluster(1, newConfig, connectionProps); fail(); } catch (Exception ex) { assertTrue(ex.getCause() instanceof NonTransientRpcException); assertTrue(ex.getCause().getCause() instanceof SaslException); } }
/** * Test showing failure in SASL handshake when Drillbit is configured for encryption whereas client doesn't provide any * security properties like username/password in this case. * @throws Exception */ @Test public void testEnableDrillbitEncryption_DisableClientAuth() throws Exception { final DrillConfig newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties()) .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(true)) .withValue(ExecConstants.USER_AUTHENTICATOR_IMPL, ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE)) .withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain"))) .withValue(ExecConstants.USER_ENCRYPTION_SASL_ENABLED, ConfigValueFactory.fromAnyRef(true)), false); final Properties connectionProps = new Properties(); connectionProps.setProperty(DrillProperties.USER, "anonymous"); connectionProps.setProperty(DrillProperties.PASSWORD, "anything works!"); try { updateTestCluster(1, newConfig, connectionProps); fail(); } catch (Exception ex) { assertTrue(ex.getCause() instanceof NonTransientRpcException); assertTrue(ex.getCause().getCause() instanceof SaslException); } }
/** * Test showing successful SASL handshake when both Drillbit and client side authentication is enabled using PLAIN * mechanism. * @throws Exception */ @Test public void testEnableDrillbitClientAuth() throws Exception { final DrillConfig newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties()) .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(true)) .withValue(ExecConstants.USER_AUTHENTICATOR_IMPL, ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE)) .withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain"))) .withValue(ExecConstants.USER_ENCRYPTION_SASL_ENABLED, ConfigValueFactory.fromAnyRef(false)), false); final Properties connectionProps = new Properties(); connectionProps.setProperty(DrillProperties.USER, "anonymous"); connectionProps.setProperty(DrillProperties.PASSWORD, "anything works!"); try { updateTestCluster(1, newConfig, connectionProps); } catch (Exception ex) { fail(); } }
/** * Test showing successful handshake when authentication is disabled on Drillbit side and client also * doesn't provide any security properties in connection URL. * @throws Exception */ @Test public void testDisableDrillbitClientAuth() throws Exception { final DrillConfig newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties()) .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(false)), false); final Properties connectionProps = new Properties(); try { updateTestCluster(1, newConfig, connectionProps); } catch (Exception ex) { fail(); } }
/** * Test showing successful handshake when authentication is disabled but impersonation is enabled on Drillbit side * and client only provides USERNAME as a security property in connection URL. * @throws Exception */ @Test public void testEnableDrillbitImpersonation_DisableClientAuth() throws Exception { final DrillConfig newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties()) .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(false)) .withValue(ExecConstants.IMPERSONATION_ENABLED, ConfigValueFactory.fromAnyRef(true)) .withValue(ExecConstants.IMPERSONATION_MAX_CHAINED_USER_HOPS, ConfigValueFactory.fromAnyRef(3)), false); final Properties connectionProps = new Properties(); connectionProps.setProperty(DrillProperties.USER, "anonymous"); try { updateTestCluster(1, newConfig, connectionProps); } catch (Exception ex) { fail(); } }
/** * Test to validate that older clients are successfully connecting to secure cluster * with encryption disabled. */ @Test public void successOldClientEncryptionDisabled() { final Properties connectionProps = new Properties(); connectionProps.setProperty(DrillProperties.SERVICE_PRINCIPAL, krbHelper.SERVER_PRINCIPAL); connectionProps.setProperty(DrillProperties.USER, krbHelper.CLIENT_PRINCIPAL); connectionProps.setProperty(DrillProperties.KEYTAB, krbHelper.clientKeytab.getAbsolutePath()); connectionProps.setProperty(DrillProperties.TEST_SASL_LEVEL, "1"); newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties()) .withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(true)) .withValue(ExecConstants.USER_AUTHENTICATOR_IMPL, ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE)) .withValue(BootStrapContext.SERVICE_PRINCIPAL, ConfigValueFactory.fromAnyRef(krbHelper.SERVER_PRINCIPAL)) .withValue(BootStrapContext.SERVICE_KEYTAB_LOCATION, ConfigValueFactory.fromAnyRef(krbHelper.serverKeytab.toString())) .withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain", "kerberos"))), false); updateTestCluster(1, newConfig, connectionProps); }
private MutableList<Config> getSysConfigs() { if (rootConfig.isEmpty()) { return Lists.mutable.empty(); } final Config instanceConfig = rootConfig.getConfig(dbType); return SetAdapter.adapt(instanceConfig.root().keySet()).collect(new Function<String, Config>() { @Override public Config valueOf(String envName) { return instanceConfig.getConfig(envName) .withFallback(defaultConfig) .withValue("envName", ConfigValueFactory.fromAnyRef(envName)) .resolve(); } }).toList(); }
@Test public void test() throws SQLException { Config config = ConfigFactory.empty() .withValue("poolName", ConfigValueFactory.fromAnyRef("test pool")) .withValue("jdbcUrl", ConfigValueFactory.fromAnyRef("jdbc:hsqldb:mem:testdb")) .withValue("maximumPoolSize", ConfigValueFactory.fromAnyRef(10)) .withValue("minimumIdle", ConfigValueFactory.fromAnyRef(2)) .withValue("username", ConfigValueFactory.fromAnyRef("SA")) .withValue("password", ConfigValueFactory.fromAnyRef("")) .withValue("cachePrepStmts", ConfigValueFactory.fromAnyRef(true)) .withValue("prepStmtCacheSize", ConfigValueFactory.fromAnyRef(256)) .withValue("prepStmtCacheSqlLimit", ConfigValueFactory.fromAnyRef(2048)) .withValue("useServerPrepStmts", ConfigValueFactory.fromAnyRef(true)) ; MetricRegistry metricRegistry = new MetricRegistry(); HealthCheckRegistry healthCheckRegistry = new HealthCheckRegistry(); try (HikariDataSource ds = ConnectionPool.getDataSourceFromConfig(config, metricRegistry, healthCheckRegistry)) { assertTrue(ds.getPoolName().equals("test pool")); assertTrue(ds.getMaximumPoolSize() == 10); assertTrue(ds.getMinimumIdle() == 2); assertTrue(ds.getUsername().equals("SA")); assertTrue(ds.getPassword().equals("")); Properties dsp = ds.getDataSourceProperties(); assertTrue(((boolean)dsp.get("cachePrepStmts")) == true); assertTrue(((int)dsp.get("prepStmtCacheSize")) == 256); assertTrue(((int)dsp.get("prepStmtCacheSqlLimit")) == 2048); assertTrue(((boolean)dsp.get("useServerPrepStmts")) == true); // Using identity equals on purpose assertTrue(ds.getHealthCheckRegistry() == healthCheckRegistry); assertTrue(ds.getMetricRegistry() == metricRegistry); try (Connection conn = ds.getConnection()) { assertTrue(conn.isValid(1000)); } } }
private static Config setSystemProperty(Config config, String sysProp, String configProp){ String systemProperty = System.getProperty(sysProp); if(systemProperty != null) { config = config.withValue(configProp, ConfigValueFactory.fromAnyRef(systemProperty)); logger.info("Applying provided leagcy system property to config: -D{}={}", configProp, systemProperty); } return config; }
/** * Invalid configuration with principal only and missing keytab * @throws Exception */ @Test public void testSpnegoConfigOnlyPrincipal() throws Exception { try { final DrillConfig newConfig = new DrillConfig(DrillConfig.create().withValue(ExecConstants.USER_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(true)).withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("plain"))).withValue(ExecConstants.HTTP_SPNEGO_PRINCIPAL, ConfigValueFactory.fromAnyRef(spnegoHelper.SERVER_PRINCIPAL)).withValue(ExecConstants.USER_AUTHENTICATOR_IMPL, ConfigValueFactory.fromAnyRef(UserAuthenticatorTestImpl.TYPE)), false); final SpnegoConfig spnegoConfig = new SpnegoConfig(newConfig); spnegoConfig.validateSpnegoConfig(); fail(); } catch (Exception ex) { assertTrue(ex instanceof DrillException); } }