Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ public void run() {
private long readAndUpdate(File trustCertFile, long oldTime)
throws IOException, GeneralSecurityException {
long newTime = checkNotNull(trustCertFile, "trustCertFile").lastModified();
if (newTime == 0) {
throw new IOException(
"Certificate file not found or not readable: " + trustCertFile.getAbsolutePath());
}
if (newTime == oldTime) {
return oldTime;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ record -> record.getMessage().contains("Default value of "));
}
}

@Test
public void missingFile_throwsFileNotFoundException() throws Exception {
AdvancedTlsX509TrustManager trustManager = AdvancedTlsX509TrustManager.newBuilder().build();
File nonExistentFile = new File("missing_cert.pem");
Exception thrown =
assertThrows(Exception.class, () -> trustManager.updateTrustCredentials(nonExistentFile));
assertNotNull(thrown);
assertEquals(thrown.getMessage(),
"Certificate file not found or not readable: " + nonExistentFile.getAbsolutePath());
}

@Test
public void clientTrustedWithSocketTest() throws Exception {
AdvancedTlsX509TrustManager trustManager = AdvancedTlsX509TrustManager.newBuilder()
Expand Down