Search in sources :

Example 41 with State

use of org.apache.gobblin.configuration.State in project incubator-gobblin by apache.

the class PasswordManagerTest method testMultipleMasterPasswords.

@Test
public void testMultipleMasterPasswords() throws IOException {
    String password = UUID.randomUUID().toString();
    String masterPassword = UUID.randomUUID().toString();
    String masterPassword1 = UUID.randomUUID().toString();
    String masterPassword2 = UUID.randomUUID().toString();
    String masterPassword3 = UUID.randomUUID().toString();
    File masterPasswordFile = File.createTempFile("masterPassword", null);
    Files.write(masterPassword, masterPasswordFile, Charset.defaultCharset());
    Files.write(masterPassword1, new File(masterPasswordFile.toString() + ".1"), Charset.defaultCharset());
    Files.write(masterPassword2, new File(masterPasswordFile.toString() + ".2"), Charset.defaultCharset());
    Files.write(masterPassword3, new File(masterPasswordFile.toString() + ".3"), Charset.defaultCharset());
    State state = new State();
    BasicTextEncryptor encryptor = new BasicTextEncryptor();
    state.setProp(ConfigurationKeys.ENCRYPT_KEY_LOC, masterPasswordFile.toString());
    state.setProp(ConfigurationKeys.NUMBER_OF_ENCRYPT_KEYS, 3);
    PasswordManager passwordManager = PasswordManager.getInstance(state);
    // Test current master password
    encryptor.setPassword(masterPassword);
    String encrypted = "ENC(" + encryptor.encrypt(password) + ")";
    String decrypted = passwordManager.readPassword(encrypted);
    Assert.assertEquals(decrypted, password);
    // Test last master password using same passwordManager
    encryptor = new BasicTextEncryptor();
    encryptor.setPassword(masterPassword1);
    encrypted = "ENC(" + encryptor.encrypt(password) + ")";
    decrypted = passwordManager.readPassword(encrypted);
    Assert.assertEquals(decrypted, password);
    // Test second last master password using same passwordManager
    encryptor = new BasicTextEncryptor();
    encryptor.setPassword(masterPassword2);
    encrypted = "ENC(" + encryptor.encrypt(password) + ")";
    decrypted = passwordManager.readPassword(encrypted);
    Assert.assertEquals(decrypted, password);
    // Test third last master password using same passwordManager
    // This one is not accepted because ConfigurationKeys.NUMBER_OF_ENCRYPT_KEYS = 3
    encryptor = new BasicTextEncryptor();
    encryptor.setPassword(masterPassword3);
    encrypted = "ENC(" + encryptor.encrypt(password) + ")";
    try {
        passwordManager.readPassword(encrypted);
    } catch (RuntimeException e) {
        Assert.assertTrue(e.getMessage().startsWith("Failed to decrypt password"));
        return;
    }
    Assert.fail("Password Manager decrypted too old password.");
}
Also used : State(org.apache.gobblin.configuration.State) BasicTextEncryptor(org.jasypt.util.text.BasicTextEncryptor) File(java.io.File) Test(org.testng.annotations.Test)

Example 42 with State

use of org.apache.gobblin.configuration.State in project incubator-gobblin by apache.

the class PasswordManagerTest method testMasterPasswordNotExist.

@Test
public void testMasterPasswordNotExist() {
    String password = "ENC(" + UUID.randomUUID().toString() + ")";
    State state = new State();
    state.setProp(ConfigurationKeys.ENCRYPT_KEY_LOC, UUID.randomUUID());
    Assert.assertEquals(PasswordManager.getInstance(state).readPassword(password), password);
}
Also used : State(org.apache.gobblin.configuration.State) Test(org.testng.annotations.Test)

Example 43 with State

use of org.apache.gobblin.configuration.State in project incubator-gobblin by apache.

the class PasswordManagerTest method testStrongEncryptionAndDecryption.

@Test
public void testStrongEncryptionAndDecryption() throws IOException {
    String password = UUID.randomUUID().toString();
    String masterPassword = UUID.randomUUID().toString();
    File masterPwdFile = getMasterPwdFile(masterPassword);
    State state = new State();
    state.setProp(ConfigurationKeys.ENCRYPT_KEY_LOC, masterPwdFile.toString());
    state.setProp(ConfigurationKeys.ENCRYPT_USE_STRONG_ENCRYPTOR, true);
    try {
        StrongTextEncryptor encryptor = new StrongTextEncryptor();
        encryptor.setPassword(masterPassword);
        String encrypted = encryptor.encrypt(password);
        encrypted = "ENC(" + encrypted + ")";
        String decrypted = PasswordManager.getInstance(state).readPassword(encrypted);
        Assert.assertEquals(decrypted, password);
    } catch (EncryptionOperationNotPossibleException e) {
    // no strong encryption is supported
    }
}
Also used : StrongTextEncryptor(org.jasypt.util.text.StrongTextEncryptor) State(org.apache.gobblin.configuration.State) EncryptionOperationNotPossibleException(org.jasypt.exceptions.EncryptionOperationNotPossibleException) File(java.io.File) Test(org.testng.annotations.Test)

Example 44 with State

use of org.apache.gobblin.configuration.State in project incubator-gobblin by apache.

the class PasswordManagerTest method testReadNormalPassword.

@Test
public void testReadNormalPassword() throws IOException {
    String password = UUID.randomUUID().toString();
    String masterPassword = UUID.randomUUID().toString();
    File masterPwdFile = getMasterPwdFile(masterPassword);
    State state = new State();
    state.setProp(ConfigurationKeys.ENCRYPT_KEY_LOC, masterPwdFile.toString());
    Assert.assertEquals(PasswordManager.getInstance(state).readPassword(password), password);
    masterPwdFile.delete();
}
Also used : State(org.apache.gobblin.configuration.State) File(java.io.File) Test(org.testng.annotations.Test)

Example 45 with State

use of org.apache.gobblin.configuration.State in project incubator-gobblin by apache.

the class MRCompactor method modifyDatasetStateToRecompact.

public static void modifyDatasetStateToRecompact(Dataset dataset) {
    // Modify the dataset for recompaction
    LOG.info("{} changes to recompact mode", dataset.getDatasetName());
    State recompactState = new State();
    recompactState.setProp(MRCompactor.COMPACTION_RECOMPACT_FROM_DEST_PATHS, Boolean.TRUE);
    recompactState.setProp(MRCompactor.COMPACTION_JOB_LATE_DATA_MOVEMENT_TASK, Boolean.FALSE);
    dataset.modifyDatasetForRecompact(recompactState);
    dataset.setState(VERIFIED);
}
Also used : State(org.apache.gobblin.configuration.State)

Aggregations

State (org.apache.gobblin.configuration.State)195 Test (org.testng.annotations.Test)103 WorkUnitState (org.apache.gobblin.configuration.WorkUnitState)74 SourceState (org.apache.gobblin.configuration.SourceState)38 Path (org.apache.hadoop.fs.Path)30 File (java.io.File)20 IOException (java.io.IOException)16 Map (java.util.Map)14 WorkingState (org.apache.gobblin.configuration.WorkUnitState.WorkingState)14 WorkUnit (org.apache.gobblin.source.workunit.WorkUnit)14 TaskState (org.apache.hadoop.mapreduce.v2.api.records.TaskState)13 Properties (java.util.Properties)12 FinalState (org.apache.gobblin.util.FinalState)12 Configuration (org.apache.hadoop.conf.Configuration)12 TaskLevelPolicyCheckResults (org.apache.gobblin.qualitychecker.task.TaskLevelPolicyCheckResults)9 Config (com.typesafe.config.Config)8 ArrayList (java.util.ArrayList)8 GenericRecord (org.apache.avro.generic.GenericRecord)8 LongWatermark (org.apache.gobblin.source.extractor.extract.LongWatermark)7 FileInputStream (java.io.FileInputStream)6