Skip to content

Commit 4820a5a

Browse files
committed
Apply suggestions from code review
1 parent 967734c commit 4820a5a

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
lines changed

spec/inputs/http_spec.rb

+29-4
Original file line numberDiff line numberDiff line change
@@ -798,12 +798,20 @@ def setup_server_client(url = self.url)
798798
end
799799

800800
context "with ssl_truststore_path set" do
801-
let(:config) { super().merge("ssl_truststore_path" => [certificate_path( 'server_from_root.p12')], "ssl_truststore_password" => "12345678") }
801+
let(:config) { super().merge("ssl_truststore_path" => certificate_path('truststore.jks'), "ssl_truststore_password" => "12345678") }
802802

803803
it "raise a configuration error" do
804804
expect {subject.register}.to raise_error(LogStash::ConfigurationError, "The configuration of `ssl_truststore_path` requires setting `ssl_client_authentication` to `optional` or 'required'")
805805
end
806806
end
807+
808+
context "with ssl_truststore_path set with no trusted certificate" do
809+
let(:config) { super().merge("ssl_truststore_path" => certificate_path('server_from_root.p12'), "ssl_truststore_password" => "12345678") }
810+
811+
it "doesn't raise a configuration error" do
812+
expect {subject.register}.not_to raise_error
813+
end
814+
end
807815
end
808816

809817
context "configured to 'required'" do
@@ -821,13 +829,22 @@ def setup_server_client(url = self.url)
821829
end
822830
end
823831

824-
context "with ssl_truststore_path set" do
825-
let(:config) { super().merge("ssl_truststore_path" => [certificate_path( 'server_from_root.p12')], "ssl_truststore_password" => "12345678") }
832+
context "with ssl_truststore_path set to a valid truststore" do
833+
let(:config) { super().merge("ssl_truststore_path" => certificate_path('truststore.jks'), "ssl_truststore_password" => "12345678") }
826834

827835
it "doesn't raise a configuration error" do
828836
expect {subject.register}.not_to raise_error
829837
end
830838
end
839+
840+
context "with ssl_truststore_path set with no trusted certificate" do
841+
let(:truststore_path) { certificate_path('server_from_root.p12') }
842+
let(:config) { super().merge("ssl_truststore_path" => truststore_path, "ssl_truststore_password" => "12345678") }
843+
844+
it "raise a configuration error" do
845+
expect {subject.register}.to raise_error(LogStash::ConfigurationError, "The provided Trust Store file does not contains any trusted certificate entry: #{truststore_path}")
846+
end
847+
end
831848
end
832849

833850
context "configured to 'optional'" do
@@ -846,7 +863,15 @@ def setup_server_client(url = self.url)
846863
end
847864

848865
context "with ssl_truststore_path set" do
849-
let(:config) { super().merge("ssl_truststore_path" => [certificate_path( 'server_from_root.p12')], "ssl_truststore_password" => "12345678") }
866+
let(:config) { super().merge("ssl_truststore_path" => certificate_path('truststore.jks'), "ssl_truststore_password" => "12345678") }
867+
868+
it "doesn't raise a configuration error" do
869+
expect {subject.register}.not_to raise_error
870+
end
871+
end
872+
873+
context "with ssl_truststore_path set with no trusted certificate" do
874+
let(:config) { super().merge("ssl_truststore_path" => certificate_path('server_from_root.p12'), "ssl_truststore_password" => "12345678") }
850875

851876
it "doesn't raise a configuration error" do
852877
expect {subject.register}.not_to raise_error

src/main/java/org/logstash/plugins/inputs/http/util/SslSimpleBuilder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ public SslSimpleBuilder setTrustStore(String trustStoreType, String trustStoreFi
188188
formatJksPassword(trustStorePassword)
189189
);
190190

191-
if (!hasTrustStoreEntry(this.trustStore)) {
192-
logger.warn("The provided Trust Store file does not contains any trusted certificate entry: {}. Please confirm this is the correct certificate and the password is correct", trustStoreFile);
191+
if (!hasTrustStoreEntry(this.trustStore) && isClientAuthenticationRequired()) {
192+
throw new IllegalArgumentException(String.format("The provided Trust Store file does not contains any trusted certificate entry: %s", trustStoreFile));
193193
}
194194

195195
return this;

src/test/java/org/logstash/plugins/inputs/http/util/SslSimpleBuilderTest.java

+11
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,17 @@ void testSetTrustStoreWithNullTrustStoreType() throws Exception {
211211
assertEquals(TRUSTSTORE_TYPE, sslSimpleBuilder.getTrustStore().getType());
212212
}
213213

214+
@Test
215+
void testSetTrustStoreWithNoTrustedCertificate() {
216+
assertThrows(
217+
IllegalArgumentException.class,
218+
() -> createPemSslSimpleBuilder()
219+
.setClientAuthentication(SslClientVerifyMode.REQUIRED)
220+
.setTrustStore(KEYSTORE_TYPE, KEYSTORE, KEYSTORE_PASSWORD),
221+
String.format("The provided Trust Store file does not contains any trusted certificate entry: %s", KEYSTORE)
222+
);
223+
}
224+
214225
@Test
215226
void testDefaultVerifyModeIsNone() {
216227
final SslSimpleBuilder sslSimpleBuilder = createPemSslSimpleBuilder();

0 commit comments

Comments
 (0)