use of org.apache.druid.metadata.DefaultPasswordProvider in project druid by druid-io.
the class TestAWSCredentialsProvider method testWithFileSessionCredentials.
@Test
public void testWithFileSessionCredentials() throws IOException {
AWSCredentialsConfig config = EasyMock.createMock(AWSCredentialsConfig.class);
EasyMock.expect(config.getAccessKey()).andReturn(new DefaultPasswordProvider(""));
EasyMock.expect(config.getSecretKey()).andReturn(new DefaultPasswordProvider(""));
File file = folder.newFile();
try (BufferedWriter out = Files.newWriter(file, StandardCharsets.UTF_8)) {
out.write("sessionToken=sessionTokenSample\nsecretKey=secretKeySample\naccessKey=accessKeySample\n");
}
EasyMock.expect(config.getFileSessionCredentials()).andReturn(file.getAbsolutePath()).atLeastOnce();
EasyMock.replay(config);
AWSCredentialsProvider provider = awsModule.getAWSCredentialsProvider(config);
AWSCredentials credentials = provider.getCredentials();
Assert.assertTrue(credentials instanceof AWSSessionCredentials);
AWSSessionCredentials sessionCredentials = (AWSSessionCredentials) credentials;
Assert.assertEquals("accessKeySample", sessionCredentials.getAWSAccessKeyId());
Assert.assertEquals("secretKeySample", sessionCredentials.getAWSSecretKey());
Assert.assertEquals("sessionTokenSample", sessionCredentials.getSessionToken());
// try to create
ServerSideEncryptingAmazonS3.Builder amazonS3ClientBuilder = s3Module.getServerSideEncryptingAmazonS3Builder(provider, new AWSProxyConfig(), new AWSEndpointConfig(), new AWSClientConfig(), new S3StorageConfig(new NoopServerSideEncryption()));
s3Module.getAmazonS3Client(amazonS3ClientBuilder);
}
use of org.apache.druid.metadata.DefaultPasswordProvider in project druid by druid-io.
the class TestAWSCredentialsProvider method testWithFixedAWSKeys.
@Test
public void testWithFixedAWSKeys() {
AWSCredentialsConfig config = EasyMock.createMock(AWSCredentialsConfig.class);
EasyMock.expect(config.getAccessKey()).andReturn(new DefaultPasswordProvider("accessKeySample")).atLeastOnce();
EasyMock.expect(config.getSecretKey()).andReturn(new DefaultPasswordProvider("secretKeySample")).atLeastOnce();
EasyMock.replay(config);
AWSCredentialsProvider provider = awsModule.getAWSCredentialsProvider(config);
AWSCredentials credentials = provider.getCredentials();
Assert.assertEquals("accessKeySample", credentials.getAWSAccessKeyId());
Assert.assertEquals("secretKeySample", credentials.getAWSSecretKey());
// try to create
ServerSideEncryptingAmazonS3.Builder amazonS3ClientBuilder = s3Module.getServerSideEncryptingAmazonS3Builder(provider, new AWSProxyConfig(), new AWSEndpointConfig(), new AWSClientConfig(), new S3StorageConfig(new NoopServerSideEncryption()));
s3Module.getAmazonS3Client(amazonS3ClientBuilder);
}
use of org.apache.druid.metadata.DefaultPasswordProvider in project druid by druid-io.
the class EmitterTest method testBasicAuthenticationAndNewlineSeparating.
@Test
public void testBasicAuthenticationAndNewlineSeparating() throws Exception {
final List<UnitEvent> events = Arrays.asList(new UnitEvent("test", 1), new UnitEvent("test", 2));
emitter = manualFlushEmitterWithBasicAuthenticationAndNewlineSeparating(new DefaultPasswordProvider("foo:bar"));
httpClient.setGoHandler(new GoHandler() {
@Override
protected ListenableFuture<Response> go(Request request) throws JsonProcessingException {
Assert.assertEquals(TARGET_URL, request.getUrl());
Assert.assertEquals("application/json", request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE));
Assert.assertEquals("Basic " + StringUtils.encodeBase64String(StringUtils.toUtf8("foo:bar")), request.getHeaders().get(HttpHeaders.Names.AUTHORIZATION));
Assert.assertEquals(StringUtils.format("%s\n%s\n", JSON_MAPPER.writeValueAsString(events.get(0)), JSON_MAPPER.writeValueAsString(events.get(1))), StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString());
return GoHandlers.immediateFuture(okResponse());
}
}.times(1));
for (UnitEvent event : events) {
emitter.emit(event);
}
emitter.flush();
waitForEmission(emitter, 1);
closeNoFlush(emitter);
Assert.assertTrue(httpClient.succeeded());
}
use of org.apache.druid.metadata.DefaultPasswordProvider in project druid by druid-io.
the class HttpInputSourceTest method testConstructorAllowsOnlyCustomProtocols.
@Test
public void testConstructorAllowsOnlyCustomProtocols() {
final HttpInputSourceConfig customConfig = new HttpInputSourceConfig(ImmutableSet.of("druid"));
new HttpInputSource(ImmutableList.of(URI.create("druid:///")), "myName", new DefaultPasswordProvider("myPassword"), customConfig);
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Only [druid] protocols are allowed");
new HttpInputSource(ImmutableList.of(URI.create("https:///")), "myName", new DefaultPasswordProvider("myPassword"), customConfig);
}
use of org.apache.druid.metadata.DefaultPasswordProvider in project druid by druid-io.
the class HttpInputSourceTest method testConstructorAllowsOnlyDefaultProtocols.
@Test
public void testConstructorAllowsOnlyDefaultProtocols() {
new HttpInputSource(ImmutableList.of(URI.create("http:///")), "myName", new DefaultPasswordProvider("myPassword"), new HttpInputSourceConfig(null));
new HttpInputSource(ImmutableList.of(URI.create("https:///")), "myName", new DefaultPasswordProvider("myPassword"), new HttpInputSourceConfig(null));
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Only [http, https] protocols are allowed");
new HttpInputSource(ImmutableList.of(URI.create("my-protocol:///")), "myName", new DefaultPasswordProvider("myPassword"), new HttpInputSourceConfig(null));
}
Aggregations