Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rjernst committed Mar 6, 2025
1 parent 6c4e402 commit 381dc70
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ static List<ExclusivePath> buildExclusivePathList(List<ExclusiveFileEntitlement>
throw new IllegalArgumentException(
"Path ["
+ normalizedPath
+ "] is exclusive to "
+ efe.componentName()
+ "/"
+ efe.moduleName()
+ " and "
+ "] is already exclusive to ["
+ exclusivePath.componentName()
+ "/"
+ "]"
+ exclusivePath.moduleNames
+ ", cannot add exclusive access for ["
+ efe.componentName()
+ "]["
+ efe.moduleName
+ "]"
);
}
exclusivePath.moduleNames.add(efe.moduleName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,24 +411,12 @@ public void testDuplicateExclusivePaths() {
new ExclusivePath(original.componentName(), Set.of("module2"), originalExclusivePath.path()),
new ExclusivePath(original.componentName(), Set.of(original.moduleName()), normalizePath(path("/c/d")))
);
assertEquals(
"Distinct elements should not be combined",
distinctPaths,
var iae = expectThrows(IllegalArgumentException.class,
() ->
buildExclusivePathList(distinctEntitlements, TEST_PATH_LOOKUP)
);

// Do merge things we should

List<ExclusiveFileEntitlement> interleavedEntitlements = new ArrayList<>();
distinctEntitlements.forEach(e -> {
interleavedEntitlements.add(e);
interleavedEntitlements.add(original);
});
assertEquals(
"Identical elements should be combined wherever they are in the list",
distinctPaths,
buildExclusivePathList(interleavedEntitlements, TEST_PATH_LOOKUP)
);
assertThat(iae.getMessage(),
equalTo("Path [/a/b] is already exclusive to [component1][module1], cannot add exclusive access for [component2][module1]"));

var equivalentEntitlements = List.of(original, differentMode, differentPlatform);
var equivalentPaths = List.of(originalExclusivePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import static org.elasticsearch.entitlement.runtime.policy.PolicyManager.ALL_UNNAMED;
import static org.elasticsearch.entitlement.runtime.policy.PolicyManager.SERVER_COMPONENT_NAME;
import static org.hamcrest.Matchers.aMapWithSize;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.sameInstance;

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

iae = expectThrows(
IllegalArgumentException.class,
Expand Down

0 comments on commit 381dc70

Please sign in to comment.