3939import static org .elasticsearch .entitlement .runtime .policy .PolicyManager .ALL_UNNAMED ;
4040import static org .elasticsearch .entitlement .runtime .policy .PolicyManager .SERVER_COMPONENT_NAME ;
4141import static org .hamcrest .Matchers .aMapWithSize ;
42+ import static org .hamcrest .Matchers .allOf ;
43+ import static org .hamcrest .Matchers .containsString ;
4244import static org .hamcrest .Matchers .equalTo ;
4345import static org .hamcrest .Matchers .is ;
4446import 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