Search in sources :

Example 21 with DrillException

use of org.apache.drill.common.exceptions.DrillException in project drill by axbaretto.

the class TestSpnegoConfig method testSpnegoConfigOnlyPrincipal.

/**
 * 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)));
        final SpnegoConfig spnegoConfig = new SpnegoConfig(newConfig);
        spnegoConfig.validateSpnegoConfig();
        fail();
    } catch (Exception ex) {
        assertTrue(ex instanceof DrillException);
    }
}
Also used : DrillConfig(org.apache.drill.common.config.DrillConfig) SpnegoConfig(org.apache.drill.exec.server.rest.auth.SpnegoConfig) DrillException(org.apache.drill.common.exceptions.DrillException) DrillException(org.apache.drill.common.exceptions.DrillException) Test(org.junit.Test) SecurityTest(org.apache.drill.categories.SecurityTest)

Example 22 with DrillException

use of org.apache.drill.common.exceptions.DrillException in project drill by apache.

the class TestSSLConfig method testInvalidHadoopKeystore.

@Test
public void testInvalidHadoopKeystore() throws Exception {
    Configuration hadoopConfig = new Configuration();
    String hadoopSSLFileProp = MessageFormat.format(HADOOP_SSL_CONF_TPL_KEY, SSLConfig.Mode.SERVER.toString().toLowerCase());
    hadoopConfig.set(hadoopSSLFileProp, "ssl-server-invalid.xml");
    ConfigBuilder config = new ConfigBuilder();
    config.put(ExecConstants.USER_SSL_ENABLED, true);
    config.put(ExecConstants.SSL_USE_HADOOP_CONF, true);
    SSLConfig sslv;
    try {
        sslv = new SSLConfigBuilder().config(config.build()).mode(SSLConfig.Mode.SERVER).initializeSSLContext(false).validateKeyStore(true).hadoopConfig(hadoopConfig).build();
        fail();
    } catch (Exception e) {
        assertTrue(e instanceof DrillException);
    }
}
Also used : SSLConfig(org.apache.drill.exec.ssl.SSLConfig) Configuration(org.apache.hadoop.conf.Configuration) SSLConfigBuilder(org.apache.drill.exec.ssl.SSLConfigBuilder) ConfigBuilder(org.apache.drill.test.ConfigBuilder) SSLConfigBuilder(org.apache.drill.exec.ssl.SSLConfigBuilder) DrillException(org.apache.drill.common.exceptions.DrillException) DrillException(org.apache.drill.common.exceptions.DrillException) Test(org.junit.Test) BaseTest(org.apache.drill.test.BaseTest) SecurityTest(org.apache.drill.categories.SecurityTest)

Example 23 with DrillException

use of org.apache.drill.common.exceptions.DrillException in project drill by apache.

the class TestSSLConfig method testMissingKeystorePassword.

@Test
public void testMissingKeystorePassword() throws Exception {
    ConfigBuilder config = new ConfigBuilder();
    config.put(ExecConstants.HTTP_KEYSTORE_PATH, "/root");
    config.put(ExecConstants.HTTP_KEYSTORE_PASSWORD, "");
    config.put(ExecConstants.SSL_USE_HADOOP_CONF, false);
    config.put(ExecConstants.USER_SSL_ENABLED, true);
    try {
        SSLConfig sslv = new SSLConfigBuilder().config(config.build()).mode(SSLConfig.Mode.SERVER).initializeSSLContext(false).validateKeyStore(true).build();
        fail();
    // Expected
    } catch (Exception e) {
        assertTrue(e instanceof DrillException);
    }
}
Also used : SSLConfig(org.apache.drill.exec.ssl.SSLConfig) SSLConfigBuilder(org.apache.drill.exec.ssl.SSLConfigBuilder) ConfigBuilder(org.apache.drill.test.ConfigBuilder) SSLConfigBuilder(org.apache.drill.exec.ssl.SSLConfigBuilder) DrillException(org.apache.drill.common.exceptions.DrillException) DrillException(org.apache.drill.common.exceptions.DrillException) Test(org.junit.Test) BaseTest(org.apache.drill.test.BaseTest) SecurityTest(org.apache.drill.categories.SecurityTest)

Example 24 with DrillException

use of org.apache.drill.common.exceptions.DrillException in project drill by apache.

the class TestUnnestCorrectness method testUnnest.

// test unnest for various input conditions optionally invoking kill. if the kill or killBatch
// parameter is greater than 0 then the record batch is sent a kill after that many batches have been processed
private <T> void testUnnest(TupleMetadata[] incomingSchemas, RecordBatch.IterOutcome[] iterOutcomes, // kill unnest after every 'unnestLimit' number of values in every record
int unnestLimit, // number of batches after which to kill the execution (!)
int execKill, T[][] data, T[][] baseline) throws Exception {
    // Get the incoming container with dummy data for LJ
    final List<VectorContainer> incomingContainer = new ArrayList<>(data.length);
    // Create data
    ArrayList<RowSet.SingleRowSet> rowSets = new ArrayList<>();
    int rowNumber = 0;
    int batchNum = 0;
    for (Object[] recordBatch : data) {
        RowSetBuilder rowSetBuilder = fixture.rowSetBuilder(incomingSchemas[batchNum]);
        for (Object rowData : recordBatch) {
            rowSetBuilder.addRow(++rowNumber, rowData);
        }
        RowSet.SingleRowSet rowSet = rowSetBuilder.build();
        rowSets.add(rowSet);
        incomingContainer.add(rowSet.container());
        batchNum++;
    }
    // Get the unnest POPConfig
    final UnnestPOP unnestPopConfig = new UnnestPOP(null, new SchemaPath(new PathSegment.NameSegment("unnestColumn")), DrillUnnestRelBase.IMPLICIT_COLUMN);
    // Get the IterOutcomes for LJ
    final List<RecordBatch.IterOutcome> outcomes = new ArrayList<>(iterOutcomes.length);
    for (RecordBatch.IterOutcome o : iterOutcomes) {
        outcomes.add(o);
    }
    // Create incoming MockRecordBatch
    final MockRecordBatch incomingMockBatch = new MockRecordBatch(fixture.getFragmentContext(), operatorContext, incomingContainer, outcomes, incomingContainer.get(0).getSchema());
    final MockLateralJoinBatch lateralJoinBatch = new MockLateralJoinBatch(fixture.getFragmentContext(), operatorContext, incomingMockBatch);
    // setup Unnest record batch
    final UnnestRecordBatch unnestBatch = new UnnestRecordBatch(unnestPopConfig, fixture.getFragmentContext());
    // set pointer to Lateral in unnest pop config
    unnestBatch.setIncoming((LateralContract) lateralJoinBatch);
    // set backpointer to lateral join in unnest
    lateralJoinBatch.setUnnest(unnestBatch);
    lateralJoinBatch.setUnnestLimit(unnestLimit);
    // Simulate the pipeline by calling next on the incoming
    List<ValueVector> results = null;
    int batchesProcessed = 0;
    try {
        while (!isTerminal(lateralJoinBatch.next())) {
            batchesProcessed++;
            if (batchesProcessed == execKill) {
                lateralJoinBatch.getContext().getExecutorState().fail(new DrillException("Testing failure of execution."));
                lateralJoinBatch.cancel();
            }
        // else nothing to do
        }
        // Check results against baseline
        results = lateralJoinBatch.getResultList();
        int i = 0;
        for (ValueVector vv : results) {
            int valueCount = vv.getAccessor().getValueCount();
            if (valueCount != baseline[i].length) {
                fail("Test failed in validating unnest output. Value count mismatch.");
            }
            for (int j = 0; j < valueCount; j++) {
                if (vv instanceof MapVector) {
                    if (!compareMapBaseline(baseline[i][j], vv.getAccessor().getObject(j))) {
                        fail("Test failed in validating unnest(Map) output. Value mismatch");
                    }
                } else if (vv instanceof VarCharVector) {
                    Object val = vv.getAccessor().getObject(j);
                    if (((String) baseline[i][j]).compareTo(val.toString()) != 0) {
                        fail("Test failed in validating unnest output. Value mismatch. Baseline value[]" + i + "][" + j + "]" + ": " + baseline[i][j] + "   VV.getObject(j): " + val);
                    }
                } else {
                    Object val = vv.getAccessor().getObject(j);
                    if (!baseline[i][j].equals(val)) {
                        fail("Test failed in validating unnest output. Value mismatch. Baseline value[" + i + "][" + j + "]" + ": " + baseline[i][j] + "   VV.getObject(j): " + val);
                    }
                }
            }
            i++;
        }
        assertTrue(lateralJoinBatch.isCompleted());
    } catch (UserException e) {
        // Valid exception
        throw e;
    } catch (Exception e) {
        fail("Test failed in validating unnest output. Exception : " + e.getMessage());
    } finally {
        // Close all the resources for this test case
        unnestBatch.close();
        lateralJoinBatch.close();
        incomingMockBatch.close();
        if (results != null) {
            for (ValueVector vv : results) {
                vv.clear();
            }
        }
        for (RowSet.SingleRowSet rowSet : rowSets) {
            rowSet.clear();
        }
    }
}
Also used : MockRecordBatch(org.apache.drill.exec.physical.impl.MockRecordBatch) RecordBatch(org.apache.drill.exec.record.RecordBatch) ArrayList(java.util.ArrayList) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) UnnestPOP(org.apache.drill.exec.physical.config.UnnestPOP) DrillException(org.apache.drill.common.exceptions.DrillException) RowSetBuilder(org.apache.drill.exec.physical.rowSet.RowSetBuilder) SchemaPath(org.apache.drill.common.expression.SchemaPath) UserException(org.apache.drill.common.exceptions.UserException) VarCharVector(org.apache.drill.exec.vector.VarCharVector) UserException(org.apache.drill.common.exceptions.UserException) DrillException(org.apache.drill.common.exceptions.DrillException) VectorContainer(org.apache.drill.exec.record.VectorContainer) ValueVector(org.apache.drill.exec.vector.ValueVector) MockRecordBatch(org.apache.drill.exec.physical.impl.MockRecordBatch) MapVector(org.apache.drill.exec.vector.complex.MapVector)

Example 25 with DrillException

use of org.apache.drill.common.exceptions.DrillException in project drill by apache.

the class TestSpnegoConfig method testInvalidSpnegoConfig.

/**
 * 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)));
        final SpnegoConfig spnegoConfig = new SpnegoConfig(newConfig);
        spnegoConfig.validateSpnegoConfig();
        fail();
    } catch (Exception ex) {
        assertTrue(ex instanceof DrillException);
    }
}
Also used : DrillConfig(org.apache.drill.common.config.DrillConfig) SpnegoConfig(org.apache.drill.exec.server.rest.auth.SpnegoConfig) DrillException(org.apache.drill.common.exceptions.DrillException) DrillException(org.apache.drill.common.exceptions.DrillException) Test(org.junit.Test) BaseTest(org.apache.drill.test.BaseTest) SecurityTest(org.apache.drill.categories.SecurityTest)

Aggregations

DrillException (org.apache.drill.common.exceptions.DrillException)28 SecurityTest (org.apache.drill.categories.SecurityTest)12 Test (org.junit.Test)12 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)10 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)6 DrillConfig (org.apache.drill.common.config.DrillConfig)6 SpnegoConfig (org.apache.drill.exec.server.rest.auth.SpnegoConfig)6 SSLConfig (org.apache.drill.exec.ssl.SSLConfig)6 SSLConfigBuilder (org.apache.drill.exec.ssl.SSLConfigBuilder)6 BaseTest (org.apache.drill.test.BaseTest)6 ConfigBuilder (org.apache.drill.test.ConfigBuilder)6 SslContext (io.netty.handler.ssl.SslContext)4 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 KeyStore (java.security.KeyStore)4 SSLContext (javax.net.ssl.SSLContext)4 Configuration (org.apache.hadoop.conf.Configuration)4 InsecureTrustManagerFactory (io.netty.handler.ssl.util.InsecureTrustManagerFactory)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2