Skip to content

Commit

Permalink
[TEST] Ensure copied file has updated timestamp (#84749) (#84853)
Browse files Browse the repository at this point in the history
This test relies on the resource watcher service detecting a change in
the configured CA path. However the old and the new file both have the
same size (1200 bytes) so the change is only detected if the file's
modification time changes.

This commit forces that modification time to be different after the file
is replaced, so that the resource watcher will trigger a reload.

Resolves: #83560
  • Loading branch information
tvernum committed Mar 10, 2022
1 parent 01ad19c commit e9cb448
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.FileTime;
import java.security.GeneralSecurityException;
import java.util.List;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -281,7 +282,6 @@ public void testGroupLookupBase() throws Exception {
* If the realm's CA path is monitored for changes and the underlying SSL context is reloaded, then we will get two different outcomes
* (one failure, one success) depending on which file content is in place.
*/
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/83560")
public void testSslTrustIsReloaded() throws Exception {
assumeFalse(
"NPE thrown in BCFIPS JSSE - addressed in https://github.com/bcgit/bc-java/commit/"
Expand Down Expand Up @@ -321,7 +321,14 @@ public void testSslTrustIsReloaded() throws Exception {

try (ResourceWatcherService resourceWatcher = new ResourceWatcherService(settings, threadPool)) {
new SSLConfigurationReloader(resourceWatcher, SSLService.getSSLConfigurations(environment).values()).setSSLService(sslService);

final FileTime oldModifiedTime = Files.getLastModifiedTime(ldapCaPath);
Files.copy(fakeCa, ldapCaPath, StandardCopyOption.REPLACE_EXISTING);

// Force the modified file to have a different modified time
// Depending on the granularity of the filesystem it could otherwise be possible the newly copied file looks identical to the
// old file (certificates commonly have the same file size)
Files.setLastModifiedTime(ldapCaPath, FileTime.fromMillis(oldModifiedTime.toMillis() + 5_000));
resourceWatcher.notifyNow(ResourceWatcherService.Frequency.HIGH);

UncategorizedExecutionException e = expectThrows(
Expand Down

0 comments on commit e9cb448

Please sign in to comment.