Skip to content

Commit 381dc70

Browse files
committed
tests
1 parent 6c4e402 commit 381dc70

File tree

3 files changed

+14
-24
lines changed

3 files changed

+14
-24
lines changed

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/FileAccessTree.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,15 @@ static List<ExclusivePath> buildExclusivePathList(List<ExclusiveFileEntitlement>
6969
throw new IllegalArgumentException(
7070
"Path ["
7171
+ normalizedPath
72-
+ "] is exclusive to "
73-
+ efe.componentName()
74-
+ "/"
75-
+ efe.moduleName()
76-
+ " and "
72+
+ "] is already exclusive to ["
7773
+ exclusivePath.componentName()
78-
+ "/"
74+
+ "]"
7975
+ exclusivePath.moduleNames
76+
+ ", cannot add exclusive access for ["
77+
+ efe.componentName()
78+
+ "]["
79+
+ efe.moduleName
80+
+ "]"
8081
);
8182
}
8283
exclusivePath.moduleNames.add(efe.moduleName());

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -411,24 +411,12 @@ public void testDuplicateExclusivePaths() {
411411
new ExclusivePath(original.componentName(), Set.of("module2"), originalExclusivePath.path()),
412412
new ExclusivePath(original.componentName(), Set.of(original.moduleName()), normalizePath(path("/c/d")))
413413
);
414-
assertEquals(
415-
"Distinct elements should not be combined",
416-
distinctPaths,
414+
var iae = expectThrows(IllegalArgumentException.class,
415+
() ->
417416
buildExclusivePathList(distinctEntitlements, TEST_PATH_LOOKUP)
418417
);
419-
420-
// Do merge things we should
421-
422-
List<ExclusiveFileEntitlement> interleavedEntitlements = new ArrayList<>();
423-
distinctEntitlements.forEach(e -> {
424-
interleavedEntitlements.add(e);
425-
interleavedEntitlements.add(original);
426-
});
427-
assertEquals(
428-
"Identical elements should be combined wherever they are in the list",
429-
distinctPaths,
430-
buildExclusivePathList(interleavedEntitlements, TEST_PATH_LOOKUP)
431-
);
418+
assertThat(iae.getMessage(),
419+
equalTo("Path [/a/b] is already exclusive to [component1][module1], cannot add exclusive access for [component2][module1]"));
432420

433421
var equivalentEntitlements = List.of(original, differentMode, differentPlatform);
434422
var equivalentPaths = List.of(originalExclusivePath);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import static org.elasticsearch.entitlement.runtime.policy.PolicyManager.ALL_UNNAMED;
3939
import static org.elasticsearch.entitlement.runtime.policy.PolicyManager.SERVER_COMPONENT_NAME;
4040
import static org.hamcrest.Matchers.aMapWithSize;
41-
import static org.hamcrest.Matchers.containsString;
41+
import static org.hamcrest.Matchers.equalTo;
4242
import static org.hamcrest.Matchers.is;
4343
import static org.hamcrest.Matchers.sameInstance;
4444

@@ -458,7 +458,8 @@ public void testFilesEntitlementsWithExclusive() {
458458
Set.of()
459459
)
460460
);
461-
assertThat(iae.getMessage(), containsString("Path [/base/test] is exclusive to plugin2/test.module2 and plugin1/[test.module1]"));
461+
assertThat(iae.getMessage(), equalTo("Path [/base/test] is already exclusive to [plugin1][test.module1]," +
462+
" cannot add exclusive access for [plugin2][test.module2]"));
462463

463464
iae = expectThrows(
464465
IllegalArgumentException.class,

0 commit comments

Comments
 (0)