Skip to content

Commit 31b3f7d

Browse files
authored
Fix PolicyManagerTests testFilesEntitlementsWithExclusive failing (#123856)
1 parent 24c5e5c commit 31b3f7d

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

libs/entitlement/src/test/java/org/elasticsearch/entitlement/runtime/policy/PolicyManagerTests.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.elasticsearch.entitlement.runtime.policy;
1111

1212
import org.elasticsearch.common.settings.Settings;
13+
import org.elasticsearch.core.Strings;
1314
import org.elasticsearch.entitlement.runtime.policy.PolicyManager.ModuleEntitlements;
1415
import org.elasticsearch.entitlement.runtime.policy.agent.TestAgent;
1516
import org.elasticsearch.entitlement.runtime.policy.agent.inner.TestInnerAgent;
@@ -411,6 +412,9 @@ public void testDuplicateEntitlements() {
411412
}
412413

413414
public void testFilesEntitlementsWithExclusive() {
415+
var baseTestPath = Path.of("/tmp").toAbsolutePath();
416+
var testPath1 = Path.of("/tmp/test").toAbsolutePath();
417+
var testPath2 = Path.of("/tmp/test/foo").toAbsolutePath();
414418
var iae = expectThrows(
415419
IllegalArgumentException.class,
416420
() -> new PolicyManager(
@@ -425,10 +429,7 @@ public void testFilesEntitlementsWithExclusive() {
425429
"test",
426430
List.of(
427431
new FilesEntitlement(
428-
List.of(
429-
FilesEntitlement.FileData.ofPath(Path.of("/tmp/test"), FilesEntitlement.Mode.READ)
430-
.withExclusive(true)
431-
)
432+
List.of(FilesEntitlement.FileData.ofPath(testPath1, FilesEntitlement.Mode.READ).withExclusive(true))
432433
)
433434
)
434435
)
@@ -442,10 +443,7 @@ public void testFilesEntitlementsWithExclusive() {
442443
"test",
443444
List.of(
444445
new FilesEntitlement(
445-
List.of(
446-
FilesEntitlement.FileData.ofPath(Path.of("/tmp/test"), FilesEntitlement.Mode.READ)
447-
.withExclusive(true)
448-
)
446+
List.of(FilesEntitlement.FileData.ofPath(testPath1, FilesEntitlement.Mode.READ).withExclusive(true))
449447
)
450448
)
451449
)
@@ -460,7 +458,7 @@ public void testFilesEntitlementsWithExclusive() {
460458
)
461459
);
462460
assertTrue(iae.getMessage().contains("duplicate/overlapping exclusive paths found in files entitlements:"));
463-
assertTrue(iae.getMessage().contains("[test] [/tmp/test]]"));
461+
assertTrue(iae.getMessage().contains(Strings.format("[test] [%s]]", testPath1.toString())));
464462

465463
iae = expectThrows(
466464
IllegalArgumentException.class,
@@ -473,9 +471,8 @@ public void testFilesEntitlementsWithExclusive() {
473471
List.of(
474472
new FilesEntitlement(
475473
List.of(
476-
FilesEntitlement.FileData.ofPath(Path.of("/tmp/test/foo"), FilesEntitlement.Mode.READ)
477-
.withExclusive(true),
478-
FilesEntitlement.FileData.ofPath(Path.of("/tmp/"), FilesEntitlement.Mode.READ)
474+
FilesEntitlement.FileData.ofPath(testPath2, FilesEntitlement.Mode.READ).withExclusive(true),
475+
FilesEntitlement.FileData.ofPath(baseTestPath, FilesEntitlement.Mode.READ)
479476
)
480477
)
481478
)
@@ -492,10 +489,7 @@ public void testFilesEntitlementsWithExclusive() {
492489
"test",
493490
List.of(
494491
new FilesEntitlement(
495-
List.of(
496-
FilesEntitlement.FileData.ofPath(Path.of("/tmp/test"), FilesEntitlement.Mode.READ)
497-
.withExclusive(true)
498-
)
492+
List.of(FilesEntitlement.FileData.ofPath(testPath1, FilesEntitlement.Mode.READ).withExclusive(true))
499493
)
500494
)
501495
)
@@ -510,8 +504,12 @@ public void testFilesEntitlementsWithExclusive() {
510504
)
511505
);
512506
assertEquals(
513-
"duplicate/overlapping exclusive paths found in files entitlements: "
514-
+ "[[plugin1] [test] [/tmp/test]] and [[(server)] [test] [/tmp/test/foo]]",
507+
Strings.format(
508+
"duplicate/overlapping exclusive paths found in files entitlements: "
509+
+ "[[plugin1] [test] [%s]] and [[(server)] [test] [%s]]",
510+
testPath1,
511+
testPath2
512+
),
515513
iae.getMessage()
516514
);
517515
}

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,6 @@ tests:
329329
- class: org.elasticsearch.action.admin.cluster.node.tasks.CancellableTasksIT
330330
method: testChildrenTasksCancelledOnTimeout
331331
issue: https://github.com/elastic/elasticsearch/issues/123568
332-
- class: org.elasticsearch.entitlement.runtime.policy.PolicyManagerTests
333-
method: testFilesEntitlementsWithExclusive
334-
issue: https://github.com/elastic/elasticsearch/issues/123657
335332
- class: org.elasticsearch.test.rest.yaml.RcsCcsCommonYamlTestSuiteIT
336333
method: test {p0=search.vectors/41_knn_search_bbq_hnsw/Test knn search}
337334
issue: https://github.com/elastic/elasticsearch/issues/123727

0 commit comments

Comments
 (0)