1010package org .elasticsearch .entitlement .runtime .policy ;
1111
1212import org .elasticsearch .common .settings .Settings ;
13+ import org .elasticsearch .core .Strings ;
1314import org .elasticsearch .entitlement .runtime .policy .PolicyManager .ModuleEntitlements ;
1415import org .elasticsearch .entitlement .runtime .policy .agent .TestAgent ;
1516import org .elasticsearch .entitlement .runtime .policy .agent .inner .TestInnerAgent ;
@@ -411,6 +412,9 @@ public void testDuplicateEntitlements() {
411412 }
412413
413414 public void testFilesEntitlementsWithExclusive () {
415+ var baseTestPath = Path .of ("/tmp" ).toAbsolutePath ();
416+ var testPath1 = Path .of ("/tmp/test" ).toAbsolutePath ();
417+ var testPath2 = Path .of ("/tmp/test/foo" ).toAbsolutePath ();
414418 var iae = expectThrows (
415419 IllegalArgumentException .class ,
416420 () -> new PolicyManager (
@@ -425,10 +429,7 @@ public void testFilesEntitlementsWithExclusive() {
425429 "test" ,
426430 List .of (
427431 new FilesEntitlement (
428- List .of (
429- FilesEntitlement .FileData .ofPath (Path .of ("/tmp/test" ), FilesEntitlement .Mode .READ )
430- .withExclusive (true )
431- )
432+ List .of (FilesEntitlement .FileData .ofPath (testPath1 , FilesEntitlement .Mode .READ ).withExclusive (true ))
432433 )
433434 )
434435 )
@@ -442,10 +443,7 @@ public void testFilesEntitlementsWithExclusive() {
442443 "test" ,
443444 List .of (
444445 new FilesEntitlement (
445- List .of (
446- FilesEntitlement .FileData .ofPath (Path .of ("/tmp/test" ), FilesEntitlement .Mode .READ )
447- .withExclusive (true )
448- )
446+ List .of (FilesEntitlement .FileData .ofPath (testPath1 , FilesEntitlement .Mode .READ ).withExclusive (true ))
449447 )
450448 )
451449 )
@@ -460,7 +458,7 @@ public void testFilesEntitlementsWithExclusive() {
460458 )
461459 );
462460 assertTrue (iae .getMessage ().contains ("duplicate/overlapping exclusive paths found in files entitlements:" ));
463- assertTrue (iae .getMessage ().contains ("[test] [/tmp/test ]]" ));
461+ assertTrue (iae .getMessage ().contains (Strings . format ( "[test] [%s ]]" , testPath1 . toString ()) ));
464462
465463 iae = expectThrows (
466464 IllegalArgumentException .class ,
@@ -473,9 +471,8 @@ public void testFilesEntitlementsWithExclusive() {
473471 List .of (
474472 new FilesEntitlement (
475473 List .of (
476- FilesEntitlement .FileData .ofPath (Path .of ("/tmp/test/foo" ), FilesEntitlement .Mode .READ )
477- .withExclusive (true ),
478- FilesEntitlement .FileData .ofPath (Path .of ("/tmp/" ), FilesEntitlement .Mode .READ )
474+ FilesEntitlement .FileData .ofPath (testPath2 , FilesEntitlement .Mode .READ ).withExclusive (true ),
475+ FilesEntitlement .FileData .ofPath (baseTestPath , FilesEntitlement .Mode .READ )
479476 )
480477 )
481478 )
@@ -492,10 +489,7 @@ public void testFilesEntitlementsWithExclusive() {
492489 "test" ,
493490 List .of (
494491 new FilesEntitlement (
495- List .of (
496- FilesEntitlement .FileData .ofPath (Path .of ("/tmp/test" ), FilesEntitlement .Mode .READ )
497- .withExclusive (true )
498- )
492+ List .of (FilesEntitlement .FileData .ofPath (testPath1 , FilesEntitlement .Mode .READ ).withExclusive (true ))
499493 )
500494 )
501495 )
@@ -510,8 +504,12 @@ public void testFilesEntitlementsWithExclusive() {
510504 )
511505 );
512506 assertEquals (
513- "duplicate/overlapping exclusive paths found in files entitlements: "
514- + "[[plugin1] [test] [/tmp/test]] and [[(server)] [test] [/tmp/test/foo]]" ,
507+ Strings .format (
508+ "duplicate/overlapping exclusive paths found in files entitlements: "
509+ + "[[plugin1] [test] [%s]] and [[(server)] [test] [%s]]" ,
510+ testPath1 ,
511+ testPath2
512+ ),
515513 iae .getMessage ()
516514 );
517515 }
0 commit comments