Skip to content

Commit

Permalink
Fix test LdapSessionFactoryTests testSslTrustIsReloaded (#69001)
Browse files Browse the repository at this point in the history
LdapSessionFactoryTests#testSslTrustIsReloaded relies on the resource watcher
to detect the cert file overwriting. Resource watcher detects changes by only
inspecting the file size on disk and the last access timestamp.
For the last access timestamp, the resolution can be as low as one second depending
on the JDK and the FS type. It is thus preferable to rely on file size differences in tests.

Closes #68995
  • Loading branch information
albertzaharovits authored Feb 16, 2021
1 parent 52da411 commit fce5207
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,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/68995")
public void testSslTrustIsReloaded() throws Exception {
InMemoryDirectoryServer ldapServer = randomFrom(ldapServers);
InetAddress listenAddress = ldapServer.getListenAddress("ldaps");
Expand All @@ -239,8 +238,11 @@ public void testSslTrustIsReloaded() throws Exception {
.put(buildLdapSettings(ldapUrl, userTemplates, groupSearchBase, LdapSearchScope.SUB_TREE))
.build();

// !!!make sure that the file size on disk for the two pem CAs is different!!!
// otherwise, the resource watcher has to rely on the last modified timestamp to detect changes,
// and the resolution for that can be as low as a second, and the test would spuriously fail
final Path realCa = getDataPath("/org/elasticsearch/xpack/security/authc/ldap/support/ldap-ca.crt");
final Path fakeCa = getDataPath("/org/elasticsearch/xpack/security/authc/ldap/support/smb_ca.crt");
final Path fakeCa = getDataPath("/org/elasticsearch/xpack/security/authc/ldap/support/ad.crt");

final Environment environment = TestEnvironment.newEnvironment(settings);
RealmConfig config = new RealmConfig("ldap_realm", settings, globalSettings, environment, new ThreadContext(settings));
Expand All @@ -252,6 +254,7 @@ public void testSslTrustIsReloaded() throws Exception {
new SSLConfigurationReloader(environment, sslService, resourceWatcher);

Files.copy(fakeCa, ldapCaPath, StandardCopyOption.REPLACE_EXISTING);
// resourceWatcher looks at the file size and last access timestamp to detect changes
resourceWatcher.notifyNow(ResourceWatcherService.Frequency.HIGH);

UncategorizedExecutionException e =
Expand Down

0 comments on commit fce5207

Please sign in to comment.