use of org.apache.drill.exec.store.security.EnvCredentialsProvider in project drill by apache.
the class CredentialsProviderImplementationsTest method testEnvCredentialsProvider.
@Test
public void testEnvCredentialsProvider() {
String variableName = "USER";
String expectedValue = System.getenv(variableName);
CredentialsProvider envCredentialsProvider = new EnvCredentialsProvider(ImmutableMap.of(UsernamePasswordCredentials.USERNAME, variableName));
Map<String, String> actualCredentials = envCredentialsProvider.getCredentials();
assertEquals(Collections.singletonMap(UsernamePasswordCredentials.USERNAME, expectedValue), actualCredentials);
}
use of org.apache.drill.exec.store.security.EnvCredentialsProvider in project drill by apache.
the class CredentialsProviderImplementationsTest method testHadoopCredentialsProvider.
@Test
public void testHadoopCredentialsProvider() {
Configuration configuration = new Configuration();
String expectedUsernameValue = "user1";
String expectedPassValue = "pass123!@#";
String usernamePropertyName = "username_key";
String passwordPropertyName = "password_key";
configuration.set(usernamePropertyName, expectedUsernameValue);
configuration.set(passwordPropertyName, expectedPassValue);
CredentialsProvider envCredentialsProvider = new HadoopCredentialsProvider(configuration, ImmutableMap.of(UsernamePasswordCredentials.USERNAME, usernamePropertyName, UsernamePasswordCredentials.PASSWORD, passwordPropertyName));
Map<String, String> actualCredentials = envCredentialsProvider.getCredentials();
assertEquals(ImmutableMap.of(UsernamePasswordCredentials.USERNAME, expectedUsernameValue, UsernamePasswordCredentials.PASSWORD, expectedPassValue), actualCredentials);
}
use of org.apache.drill.exec.store.security.EnvCredentialsProvider in project drill by apache.
the class CredentialsProviderImplementationsTest method testVaultCredentialsProvider.
@Test
public void testVaultCredentialsProvider() throws VaultException {
DrillConfig config = cluster.drillbit().getContext().getConfig();
CredentialsProvider envCredentialsProvider = new VaultCredentialsProvider(SECRET_PATH, ImmutableMap.of(UsernamePasswordCredentials.USERNAME, "top_secret", UsernamePasswordCredentials.PASSWORD, "db_password"), config);
Map<String, String> actualCredentials = envCredentialsProvider.getCredentials();
assertEquals(ImmutableMap.of(UsernamePasswordCredentials.USERNAME, "password1", UsernamePasswordCredentials.PASSWORD, "dbpassword1"), actualCredentials);
}
use of org.apache.drill.exec.store.security.EnvCredentialsProvider in project drill by apache.
the class CredentialsProviderSerDeTest method testEnvCredentialsProviderSerDe.
@Test
public void testEnvCredentialsProviderSerDe() throws JsonProcessingException {
ObjectMapper mapper = cluster.drillbit().getContext().getLpPersistence().getMapper();
CredentialsProvider envCredentialsProvider = new EnvCredentialsProvider(ImmutableMap.of(UsernamePasswordCredentials.USERNAME, "myLoginVar", UsernamePasswordCredentials.PASSWORD, "myPassVar"));
String serialized = mapper.writerFor(CredentialsProvider.class).writeValueAsString(envCredentialsProvider);
String expected = "{\n" + " \"credentialsProviderType\" : \"EnvCredentialsProvider\",\n" + " \"envVariables\" : {\n" + " \"username\" : \"myLoginVar\",\n" + " \"password\" : \"myPassVar\"\n" + " }\n" + "}";
assertEquals(expected, serialized);
CredentialsProvider deserialized = mapper.readerFor(CredentialsProvider.class).readValue(serialized);
assertEquals(envCredentialsProvider, deserialized);
}
Aggregations