Skip to content

Commit aa975b2

Browse files
committed
use better assertion
1 parent b92439d commit aa975b2

File tree

2 files changed

+37
-37
lines changed

2 files changed

+37
-37
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import java.nio.file.Paths;
2424
import java.util.ArrayList;
2525
import java.util.Arrays;
26+
import java.util.HashMap;
2627
import java.util.HashSet;
27-
import java.util.LinkedHashMap;
2828
import java.util.List;
2929
import java.util.Map;
3030
import java.util.Objects;
@@ -55,7 +55,7 @@ public String toString() {
5555
}
5656

5757
static List<ExclusivePath> buildExclusivePathList(List<ExclusiveFileEntitlement> exclusiveFileEntitlements, PathLookup pathLookup) {
58-
Map<String, ExclusivePath> exclusivePaths = new LinkedHashMap<>();
58+
Map<String, ExclusivePath> exclusivePaths = new HashMap<>();
5959
for (ExclusiveFileEntitlement efe : exclusiveFileEntitlements) {
6060
for (FilesEntitlement.FileData fd : efe.filesEntitlement().filesData()) {
6161
if (fd.exclusive()) {

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

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import static org.elasticsearch.entitlement.runtime.policy.PolicyManager.ALL_UNNAMED;
4040
import static org.elasticsearch.entitlement.runtime.policy.PolicyManager.SERVER_COMPONENT_NAME;
4141
import static org.hamcrest.Matchers.aMapWithSize;
42+
import static org.hamcrest.Matchers.allOf;
43+
import static org.hamcrest.Matchers.containsString;
4244
import static org.hamcrest.Matchers.equalTo;
4345
import static org.hamcrest.Matchers.is;
4446
import static org.hamcrest.Matchers.sameInstance;
@@ -449,45 +451,41 @@ public void testFilesEntitlementsWithExclusive() {
449451
var baseTestPath = Path.of("/base").toAbsolutePath();
450452
var testPath1 = Path.of("/base/test").toAbsolutePath();
451453
var testPath2 = Path.of("/base/test/foo").toAbsolutePath();
452-
var plugins = new LinkedHashMap<String, Policy>();
453-
plugins.put(
454-
"plugin1",
455-
new Policy(
456-
"test",
457-
List.of(
458-
new Scope(
459-
"test.module1",
454+
var iae = expectThrows(
455+
IllegalArgumentException.class,
456+
() -> new PolicyManager(
457+
createEmptyTestServerPolicy(),
458+
List.of(),
459+
Map.of(
460+
"plugin1",
461+
new Policy(
462+
"test",
460463
List.of(
461-
new FilesEntitlement(
462-
List.of(FilesEntitlement.FileData.ofPath(testPath1, FilesEntitlement.Mode.READ).withExclusive(true))
464+
new Scope(
465+
"test.module1",
466+
List.of(
467+
new FilesEntitlement(
468+
List.of(FilesEntitlement.FileData.ofPath(testPath1, FilesEntitlement.Mode.READ).withExclusive(true))
469+
)
470+
)
463471
)
464472
)
465-
)
466-
)
467-
)
468-
);
469-
plugins.put(
470-
"plugin2",
471-
new Policy(
472-
"test",
473-
List.of(
474-
new Scope(
475-
"test.module2",
473+
),
474+
"plugin2",
475+
new Policy(
476+
"test",
476477
List.of(
477-
new FilesEntitlement(
478-
List.of(FilesEntitlement.FileData.ofPath(testPath1, FilesEntitlement.Mode.READ).withExclusive(true))
478+
new Scope(
479+
"test.module2",
480+
List.of(
481+
new FilesEntitlement(
482+
List.of(FilesEntitlement.FileData.ofPath(testPath1, FilesEntitlement.Mode.READ).withExclusive(true))
483+
)
484+
)
479485
)
480486
)
481487
)
482-
)
483-
)
484-
);
485-
var iae = expectThrows(
486-
IllegalArgumentException.class,
487-
() -> new PolicyManager(
488-
createEmptyTestServerPolicy(),
489-
List.of(),
490-
plugins,
488+
),
491489
c -> "",
492490
Map.of("plugin1", Path.of("modules", "plugin1"), "plugin2", Path.of("modules", "plugin2")),
493491
TEST_AGENTS_PACKAGE_NAME,
@@ -498,9 +496,11 @@ public void testFilesEntitlementsWithExclusive() {
498496
);
499497
assertThat(
500498
iae.getMessage(),
501-
equalTo(
502-
"Path [/base/test] is already exclusive to [plugin1][test.module1],"
503-
+ " cannot add exclusive access for [plugin2][test.module2]"
499+
allOf(
500+
containsString("Path [/base/test] is already exclusive"),
501+
containsString("[plugin1][test.module1]"),
502+
containsString("[plugin2][test.module2]"),
503+
containsString("cannot add exclusive access")
504504
)
505505
);
506506

0 commit comments

Comments
 (0)