Skip to content

Commit

Permalink
XPackAuth - certInfo requirement removed (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfoltyns committed Jan 21, 2019
1 parent 9cfc44d commit 3d31e48
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,13 @@ protected XPackAuth(Credentials<HttpClientConfig.Builder> credentials, CertInfo<

@Override
public void configure(HttpClientConfig.Builder builder) {

credentials.applyTo(builder);
certInfo.applyTo(builder);

if (certInfo != null) {
certInfo.applyTo(builder);
}

}

@PluginBuilderFactory
Expand All @@ -63,18 +68,17 @@ public static class Builder implements org.apache.logging.log4j.core.util.Builde
private Credentials credentials;

@PluginElement("certInfo")
@Required(message = "No certInfo provided for " + XPackAuth.PLUGIN_NAME)
private CertInfo certInfo;

@Override
public XPackAuth build() {

if (credentials == null) {
throw new ConfigurationException("No credentials provided for " + XPackAuth.PLUGIN_NAME);
}
if (certInfo == null) {
throw new ConfigurationException("No certInfo provided for " + XPackAuth.PLUGIN_NAME);
}

return new XPackAuth(credentials, certInfo);

}

public Builder withCredentials(Credentials credentials) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

@RunWith(MockitoJUnitRunner.class)
public class XPackAuthTest {

Expand Down Expand Up @@ -84,7 +89,7 @@ public void appliesCredentialsIfConfigured() {
xPackAuth.configure(settingsBuilder);

// then
Mockito.verify(credentials).applyTo(builderArgumentCaptor.capture());
verify(credentials).applyTo(builderArgumentCaptor.capture());
Assert.assertEquals(settingsBuilder, builderArgumentCaptor.getValue());

}
Expand Down Expand Up @@ -120,24 +125,27 @@ public void appliesCertInfoIfConfigured() {
xPackAuth.configure(settingsBuilder);

// then
Mockito.verify(certInfo).applyTo(builderArgumentCaptor.capture());
verify(certInfo).applyTo(builderArgumentCaptor.capture());
Assert.assertEquals(settingsBuilder, builderArgumentCaptor.getValue());

}

@Test
public void throwsIfCertInfoNotConfigured() {
public void doesntApplyCertInfoIfNotConfigured() {

// given
XPackAuth.Builder builder = createTestBuilder()
.withCertInfo(null);
XPackAuth auth = createTestBuilder()
.withCertInfo(null)
.build();

expectedException.expect(ConfigurationException.class);
expectedException.expectMessage("certInfo");
HttpClientConfig.Builder settingsBuilder = spy(createDefaultClientConfigBuilder());

// when
builder.build();
auth.configure(settingsBuilder);

// then
verify(settingsBuilder, never()).sslSocketFactory(any());
verify(settingsBuilder, never()).httpsIOSessionStrategy(any());
}

}

0 comments on commit 3d31e48

Please sign in to comment.