Skip to content

Commit fce5207

Browse files
Fix test LdapSessionFactoryTests testSslTrustIsReloaded (#69001)
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
1 parent 52da411 commit fce5207

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/ldap/LdapSessionFactoryTests.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ public void testGroupLookupBase() throws Exception {
222222
* If the realm's CA path is monitored for changes and the underlying SSL context is reloaded, then we will get two different outcomes
223223
* (one failure, one success) depending on which file content is in place.
224224
*/
225-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/68995")
226225
public void testSslTrustIsReloaded() throws Exception {
227226
InMemoryDirectoryServer ldapServer = randomFrom(ldapServers);
228227
InetAddress listenAddress = ldapServer.getListenAddress("ldaps");
@@ -239,8 +238,11 @@ public void testSslTrustIsReloaded() throws Exception {
239238
.put(buildLdapSettings(ldapUrl, userTemplates, groupSearchBase, LdapSearchScope.SUB_TREE))
240239
.build();
241240

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

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

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

257260
UncategorizedExecutionException e =

0 commit comments

Comments
 (0)