Skip to content

Commit 958352f

Browse files
authored
Fix FileAccessTreeTests#testDuplicateExclusivePaths to work on windows (#124430)
1 parent a80402b commit 958352f

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

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

+13-8
Original file line numberDiff line numberDiff line change
@@ -365,17 +365,17 @@ public void testDuplicatePrunedPaths() {
365365

366366
public void testDuplicateExclusivePaths() {
367367
// Bunch o' handy definitions
368-
var originalFileData = FileData.ofPath(path("/a/b"), READ).withExclusive(true);
369-
var fileDataWithWriteMode = FileData.ofPath(path("/a/b"), READ_WRITE).withExclusive(true);
368+
var pathAB = path("/a/b");
369+
var pathCD = path("/c/d");
370+
var originalFileData = FileData.ofPath(pathAB, READ).withExclusive(true);
371+
var fileDataWithWriteMode = FileData.ofPath(pathAB, READ_WRITE).withExclusive(true);
370372
var original = new ExclusiveFileEntitlement("component1", "module1", new FilesEntitlement(List.of(originalFileData)));
371373
var differentComponent = new ExclusiveFileEntitlement("component2", original.moduleName(), original.filesEntitlement());
372374
var differentModule = new ExclusiveFileEntitlement(original.componentName(), "module2", original.filesEntitlement());
373375
var differentPath = new ExclusiveFileEntitlement(
374376
original.componentName(),
375377
original.moduleName(),
376-
new FilesEntitlement(
377-
List.of(FileData.ofPath(path("/c/d"), originalFileData.mode()).withExclusive(originalFileData.exclusive()))
378-
)
378+
new FilesEntitlement(List.of(FileData.ofPath(pathCD, originalFileData.mode()).withExclusive(originalFileData.exclusive())))
379379
);
380380
var differentMode = new ExclusiveFileEntitlement(
381381
original.componentName(),
@@ -387,7 +387,7 @@ public void testDuplicateExclusivePaths() {
387387
original.moduleName(),
388388
new FilesEntitlement(List.of(originalFileData.withPlatform(WINDOWS)))
389389
);
390-
var originalExclusivePath = new ExclusivePath("component1", Set.of("module1"), normalizePath(path("/a/b")));
390+
var originalExclusivePath = new ExclusivePath("component1", Set.of("module1"), normalizePath(pathAB));
391391

392392
// Some basic tests
393393

@@ -409,12 +409,17 @@ public void testDuplicateExclusivePaths() {
409409
originalExclusivePath,
410410
new ExclusivePath("component2", Set.of(original.moduleName()), originalExclusivePath.path()),
411411
new ExclusivePath(original.componentName(), Set.of("module2"), originalExclusivePath.path()),
412-
new ExclusivePath(original.componentName(), Set.of(original.moduleName()), normalizePath(path("/c/d")))
412+
new ExclusivePath(original.componentName(), Set.of(original.moduleName()), normalizePath(pathCD))
413413
);
414414
var iae = expectThrows(IllegalArgumentException.class, () -> buildExclusivePathList(distinctEntitlements, TEST_PATH_LOOKUP));
415+
var pathABString = pathAB.toAbsolutePath().toString();
415416
assertThat(
416417
iae.getMessage(),
417-
equalTo("Path [/a/b] is already exclusive to [component1][module1], cannot add exclusive access for [component2][module1]")
418+
equalTo(
419+
"Path ["
420+
+ pathABString
421+
+ "] is already exclusive to [component1][module1], cannot add exclusive access for [component2][module1]"
422+
)
418423
);
419424

420425
var equivalentEntitlements = List.of(original, differentMode, differentPlatform);

muted-tests.yml

-3
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,6 @@ tests:
360360
- class: org.elasticsearch.entitlement.runtime.policy.PolicyManagerTests
361361
method: testFilesEntitlementsWithExclusive
362362
issue: https://github.com/elastic/elasticsearch/issues/124420
363-
- class: org.elasticsearch.entitlement.runtime.policy.FileAccessTreeTests
364-
method: testDuplicateExclusivePaths
365-
issue: https://github.com/elastic/elasticsearch/issues/124437
366363
- class: org.elasticsearch.xpack.restart.FullClusterRestartIT
367364
method: testWatcherWithApiKey {cluster=UPGRADED}
368365
issue: https://github.com/elastic/elasticsearch/issues/124159

0 commit comments

Comments
 (0)