Skip to content

Commit 12ea8fb

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 f429fd9 commit 12ea8fb

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import com.unboundid.ldap.sdk.LDAPException;
1111
import com.unboundid.ldap.sdk.LDAPURL;
1212
import com.unboundid.ldap.sdk.SimpleBindRequest;
13-
import org.apache.lucene.util.LuceneTestCase;
1413
import org.elasticsearch.common.network.NetworkAddress;
1514
import org.elasticsearch.common.settings.SecureString;
1615
import org.elasticsearch.common.settings.Settings;
@@ -245,7 +244,6 @@ public void testGroupLookupBase() throws Exception {
245244
* If the realm's CA path is monitored for changes and the underlying SSL context is reloaded, then we will get two different outcomes
246245
* (one failure, one success) depending on which file content is in place.
247246
*/
248-
@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/68995")
249247
public void testSslTrustIsReloaded() throws Exception {
250248
assumeFalse("NPE thrown in BCFIPS JSSE - addressed in " +
251249
"https://github.com/bcgit/bc-java/commit/5aed687e17a3cd63f34373cafe92699b90076fb6#diff-8e5d8089bc0d504d93194a1e484d3950R179",
@@ -265,8 +263,11 @@ public void testSslTrustIsReloaded() throws Exception {
265263
.put(buildLdapSettings(ldapUrl, userTemplates, groupSearchBase, LdapSearchScope.SUB_TREE))
266264
.build();
267265

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

271272
final Environment environment = TestEnvironment.newEnvironment(settings);
272273
RealmConfig config = new RealmConfig(REALM_IDENTIFIER, settings,
@@ -279,6 +280,7 @@ public void testSslTrustIsReloaded() throws Exception {
279280
new SSLConfigurationReloader(environment, resourceWatcher, SSLService.getSSLConfigurations(environment.settings()).values())
280281
.setSSLService(sslService);
281282
Files.copy(fakeCa, ldapCaPath, StandardCopyOption.REPLACE_EXISTING);
283+
// resourceWatcher looks at the file size and last access timestamp to detect changes
282284
resourceWatcher.notifyNow(ResourceWatcherService.Frequency.HIGH);
283285

284286
UncategorizedExecutionException e =

0 commit comments

Comments
 (0)