Skip to content
Open
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 @@ -332,15 +332,15 @@ private UpdateResult readAndUpdate(File certFile, File keyFile, long oldKeyTime,
try {
X509Certificate[] certs = CertificateUtils.getX509Certificates(certInputStream);
updateIdentityCredentials(certs, key);
return new UpdateResult(true, newKeyTime, newCertTime);
return new UpdateResult(true, newCertTime, newKeyTime);
} finally {
certInputStream.close();
}
} finally {
keyInputStream.close();
}
}
return new UpdateResult(false, oldKeyTime, oldCertTime);
return new UpdateResult(false, oldCertTime, oldKeyTime);
}

/**
Expand Down
23 changes: 23 additions & 0 deletions util/src/test/java/io/grpc/util/AdvancedTlsX509KeyManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,29 @@ public void updateTrustCredentials_replacesIssuers() throws Exception {
assertArrayEquals(serverCert0, serverKeyManager.getCertificateChain(alias4));
}

@Test
public void scheduledReload_doesNotReloadWhenFilesAreUnchanged() throws Exception {
FakeClock fakeClock = new FakeClock();
AdvancedTlsX509KeyManager serverKeyManager = new AdvancedTlsX509KeyManager();

// Give the cert and key files distinct modification times, which is the normal case for two
// files written at different instants.
serverCert0File.setLastModified(TimeUnit.SECONDS.toMillis(1000));
serverKey0File.setLastModified(TimeUnit.SECONDS.toMillis(2000));

serverKeyManager.updateIdentityCredentials(serverCert0File, serverKey0File, 1, TimeUnit.MINUTES,
fakeClock.getScheduledExecutorService());

// Let one refresh cycle run; the scheduled reloader starts from a zero baseline, so it reloads
// once and rotates the alias.
fakeClock.forwardTime(1, TimeUnit.MINUTES);
String aliasAfterFirstCycle = serverKeyManager.chooseEngineServerAlias(null, null, null);

// Subsequent cycles with the files untouched must not reload, so the alias must stay the same.
fakeClock.forwardTime(5, TimeUnit.MINUTES);
assertEquals(aliasAfterFirstCycle, serverKeyManager.chooseEngineServerAlias(null, null, null));
}

@Test
public void allAliasMethods_returnNullBeforeCredentialsLoaded() {
AdvancedTlsX509KeyManager keyManager = new AdvancedTlsX509KeyManager();
Expand Down
Loading