Skip to content

Commit 932d1e4

Browse files
committed
Added additional debug logs for InflatableX509ExtendedTrustManager
1 parent 6af6057 commit 932d1e4

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

ayza/src/main/java/nl/altindag/ssl/trustmanager/InflatableX509ExtendedTrustManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,18 @@ public InflatableX509ExtendedTrustManager(Path trustStorePath,
8989

9090
if (trustStorePath != null && StringUtils.isNotBlank(trustStoreType)) {
9191
if (Files.exists(trustStorePath)) {
92+
LOGGER.debug(String.format("Trying to load the trust store from [%s]", trustStorePath));
9293
trustStore = KeyStoreUtils.loadKeyStore(trustStorePath, trustStorePassword, trustStoreType);
94+
LOGGER.debug("Trust store loaded successfully");
9395
if (KeyStoreUtils.containsTrustMaterial(trustStore)) {
9496
setTrustManager(TrustManagerUtils.createTrustManager(trustStore));
9597
}
9698
} else {
99+
LOGGER.debug(String.format("Creating an empty trust store with the requested truststore type [%s] and password", trustStoreType));
97100
trustStore = KeyStoreUtils.createKeyStore(trustStoreType, trustStorePassword);
98101
}
99102
} else {
103+
LOGGER.debug("No trust store path has been specified. Creating an empty in-memory trust store");
100104
trustStore = KeyStoreUtils.createKeyStore();
101105
}
102106
} finally {

ayza/src/test/java/nl/altindag/ssl/trustmanager/InflatableX509ExtendedTrustManagerShould.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void trustManagerWillNotBeReloadedIfNullIsProvidedAsNewCertificate() {
116116
assertThat(trustManager.getInnerTrustManager()).isInstanceOf(DummyX509ExtendedTrustManager.class);
117117

118118
assertThat(trustManager.getAcceptedIssuers()).isEmpty();
119-
assertThat(logCaptor.getLogs()).isEmpty();
119+
assertThat(logCaptor.getLogs()).containsExactly("No trust store path has been specified. Creating an empty in-memory trust store");
120120
}
121121

122122
@Test
@@ -130,7 +130,7 @@ void trustManagerWillNotBeReloadedIfEmptyListIsProvidedAsNewCertificate() {
130130
assertThat(trustManager.getInnerTrustManager()).isInstanceOf(DummyX509ExtendedTrustManager.class);
131131

132132
assertThat(trustManager.getAcceptedIssuers()).isEmpty();
133-
assertThat(logCaptor.getLogs()).isEmpty();
133+
assertThat(logCaptor.getLogs()).containsExactly("No trust store path has been specified. Creating an empty in-memory trust store");
134134
}
135135

136136
@Test
@@ -156,9 +156,11 @@ void errorLogIfItCanNotSaveNewlyAddedTrustedCertificatesToTheInMemoryTrustStore(
156156
trustManager.addCertificates(Arrays.asList(trustedCerts));
157157

158158
List<LogEvent> logEvents = logCaptor.getLogEvents();
159-
assertThat(logEvents).hasSize(1);
160-
assertThat(logEvents.get(0).getLevel()).isEqualTo("ERROR");
161-
assertThat(logEvents.get(0).getFormattedMessage()).contains("Cannot add certificate");
159+
assertThat(logEvents).hasSize(2);
160+
assertThat(logEvents.get(0).getFormattedMessage()).contains("No trust store path has been specified. Creating an empty in-memory trust store");
161+
162+
assertThat(logEvents.get(1).getLevel()).isEqualTo("ERROR");
163+
assertThat(logEvents.get(1).getFormattedMessage()).contains("Cannot add certificate");
162164
}
163165
}
164166

@@ -564,9 +566,12 @@ void wrapKeyStoreExceptionIntoGenericKeyStoreExceptionWhenCallingGenerateAlias()
564566
assertThat(trustManager.getAcceptedIssuers()).hasSize(1);
565567

566568
List<LogEvent> logEvents = logCaptor.getLogEvents();
567-
assertThat(logEvents).hasSize(1);
569+
assertThat(logEvents).hasSize(3);
570+
571+
assertThat(logEvents.get(0).getMessage()).contains("Trying to load the trust store from");
572+
assertThat(logEvents.get(1).getMessage()).contains("Trust store loaded successfully");
568573

569-
LogEvent logEvent = logEvents.get(0);
574+
LogEvent logEvent = logEvents.get(2);
570575
assertThat(logEvent.getLevel()).isEqualTo("ERROR");
571576
assertThat(logEvent.getMessage()).isEqualTo("Cannot add certificate");
572577
assertThat(logEvent.getThrowable()).isPresent();

0 commit comments

Comments
 (0)