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 (
@@ -426,7 +430,7 @@ public void testFilesEntitlementsWithExclusive() {
426430 List .of (
427431 new FilesEntitlement (
428432 List .of (
429- FilesEntitlement .FileData .ofPath (Path . of ( "/tmp/test" ) , FilesEntitlement .Mode .READ )
433+ FilesEntitlement .FileData .ofPath (testPath1 , FilesEntitlement .Mode .READ )
430434 .withExclusive (true )
431435 )
432436 )
@@ -443,7 +447,7 @@ public void testFilesEntitlementsWithExclusive() {
443447 List .of (
444448 new FilesEntitlement (
445449 List .of (
446- FilesEntitlement .FileData .ofPath (Path . of ( "/tmp/test" ) , FilesEntitlement .Mode .READ )
450+ FilesEntitlement .FileData .ofPath (testPath1 , FilesEntitlement .Mode .READ )
447451 .withExclusive (true )
448452 )
449453 )
@@ -460,7 +464,7 @@ public void testFilesEntitlementsWithExclusive() {
460464 )
461465 );
462466 assertTrue (iae .getMessage ().contains ("duplicate/overlapping exclusive paths found in files entitlements:" ));
463- assertTrue (iae .getMessage ().contains ("[test] [/tmp/test ]]" ));
467+ assertTrue (iae .getMessage ().contains (Strings . format ( "[test] [%s ]]" , testPath1 . toString ()) ));
464468
465469 iae = expectThrows (
466470 IllegalArgumentException .class ,
@@ -473,9 +477,9 @@ public void testFilesEntitlementsWithExclusive() {
473477 List .of (
474478 new FilesEntitlement (
475479 List .of (
476- FilesEntitlement .FileData .ofPath (Path . of ( "/tmp/test/foo" ) , FilesEntitlement .Mode .READ )
480+ FilesEntitlement .FileData .ofPath (testPath2 , FilesEntitlement .Mode .READ )
477481 .withExclusive (true ),
478- FilesEntitlement .FileData .ofPath (Path . of ( "/tmp/" ) , FilesEntitlement .Mode .READ )
482+ FilesEntitlement .FileData .ofPath (baseTestPath , FilesEntitlement .Mode .READ )
479483 )
480484 )
481485 )
@@ -493,7 +497,7 @@ public void testFilesEntitlementsWithExclusive() {
493497 List .of (
494498 new FilesEntitlement (
495499 List .of (
496- FilesEntitlement .FileData .ofPath (Path . of ( "/tmp/test" ) , FilesEntitlement .Mode .READ )
500+ FilesEntitlement .FileData .ofPath (testPath1 , FilesEntitlement .Mode .READ )
497501 .withExclusive (true )
498502 )
499503 )
@@ -510,8 +514,8 @@ public void testFilesEntitlementsWithExclusive() {
510514 )
511515 );
512516 assertEquals (
513- "duplicate/overlapping exclusive paths found in files entitlements: "
514- + "[[plugin1] [test] [/tmp/test ]] and [[(server)] [test] [/tmp/test/foo ]]" ,
517+ Strings . format ( "duplicate/overlapping exclusive paths found in files entitlements: "
518+ + "[[plugin1] [test] [%s ]] and [[(server)] [test] [%s ]]" , testPath1 , testPath2 ) ,
515519 iae .getMessage ()
516520 );
517521 }
0 commit comments