3939
4040import static java .util .Map .entry ;
4141import static org .elasticsearch .entitlement .runtime .policy .PolicyManager .ALL_UNNAMED ;
42- import static org .elasticsearch .entitlement .runtime .policy .PolicyManager .APM_AGENT_COMPONENT_NAME ;
43- import static org .elasticsearch .entitlement .runtime .policy .PolicyManager .SERVER_COMPONENT_NAME ;
42+ import static org .elasticsearch .entitlement .runtime .policy .PolicyManager .ComponentKind .SERVER ;
4443import static org .hamcrest .Matchers .aMapWithSize ;
4544import static org .hamcrest .Matchers .allOf ;
4645import static org .hamcrest .Matchers .containsString ;
@@ -91,7 +90,7 @@ public void testGetEntitlementsThrowsOnMissingPluginUnnamedModule() {
9190 createEmptyTestServerPolicy (),
9291 List .of (),
9392 Map .of ("plugin1" , createPluginPolicy ("plugin.module" )),
94- c -> new PolicyScope ("plugin1" , moduleName (c )),
93+ c -> PolicyScope . plugin ("plugin1" , moduleName (c )),
9594 Map .of ("plugin1" , plugin1SourcePath ),
9695 NO_ENTITLEMENTS_MODULE ,
9796 TEST_PATH_LOOKUP ,
@@ -120,7 +119,7 @@ public void testGetEntitlementsThrowsOnMissingPolicyForPlugin() {
120119 createEmptyTestServerPolicy (),
121120 List .of (),
122121 Map .of (),
123- c -> new PolicyScope ("plugin1" , moduleName (c )),
122+ c -> PolicyScope . plugin ("plugin1" , moduleName (c )),
124123 Map .of ("plugin1" , plugin1SourcePath ),
125124 NO_ENTITLEMENTS_MODULE ,
126125 TEST_PATH_LOOKUP ,
@@ -149,7 +148,7 @@ public void testGetEntitlementsFailureIsCached() {
149148 createEmptyTestServerPolicy (),
150149 List .of (),
151150 Map .of (),
152- c -> new PolicyScope ("plugin1" , moduleName (c )),
151+ c -> PolicyScope . plugin ("plugin1" , moduleName (c )),
153152 Map .of ("plugin1" , plugin1SourcePath ),
154153 NO_ENTITLEMENTS_MODULE ,
155154 TEST_PATH_LOOKUP ,
@@ -187,7 +186,7 @@ public void testGetEntitlementsReturnsEntitlementsForPluginUnnamedModule() {
187186 createEmptyTestServerPolicy (),
188187 List .of (),
189188 Map .ofEntries (entry ("plugin2" , createPluginPolicy (ALL_UNNAMED ))),
190- c -> new PolicyScope ("plugin2" , moduleName (c )),
189+ c -> PolicyScope . plugin ("plugin2" , moduleName (c )),
191190 Map .of ("plugin2" , Path .of ("modules" , "plugin2" )),
192191 NO_ENTITLEMENTS_MODULE ,
193192 TEST_PATH_LOOKUP ,
@@ -206,7 +205,7 @@ public void testGetEntitlementsReturnsDefaultOnMissingPolicyForServer() throws C
206205 createTestServerPolicy ("example" ),
207206 List .of (),
208207 Map .of (),
209- c -> new PolicyScope ( SERVER_COMPONENT_NAME , moduleName (c )),
208+ c -> PolicyScope . server ( moduleName (c )),
210209 Map .of (),
211210 NO_ENTITLEMENTS_MODULE ,
212211 TEST_PATH_LOOKUP ,
@@ -222,12 +221,12 @@ public void testGetEntitlementsReturnsDefaultOnMissingPolicyForServer() throws C
222221
223222 assertEquals (
224223 "No policy for this module in server" ,
225- policyManager .defaultEntitlements (SERVER_COMPONENT_NAME , mockServerSourcePath , httpserverModuleName ),
224+ policyManager .defaultEntitlements (SERVER . componentName , mockServerSourcePath , httpserverModuleName ),
226225 policyManager .getEntitlements (mockServerClass )
227226 );
228227
229228 assertEquals (
230- Map .of (requestingModule , policyManager .defaultEntitlements (SERVER_COMPONENT_NAME , mockServerSourcePath , httpserverModuleName )),
229+ Map .of (requestingModule , policyManager .defaultEntitlements (SERVER . componentName , mockServerSourcePath , httpserverModuleName )),
231230 policyManager .moduleEntitlementsMap
232231 );
233232 }
@@ -238,7 +237,7 @@ public void testGetEntitlementsReturnsEntitlementsForServerModule() throws Class
238237 createTestServerPolicy (httpserverModuleName ),
239238 List .of (),
240239 Map .of (),
241- c -> new PolicyScope ( SERVER_COMPONENT_NAME , moduleName (c )),
240+ c -> PolicyScope . server ( moduleName (c )),
242241 Map .of (),
243242 NO_ENTITLEMENTS_MODULE ,
244243 TEST_PATH_LOOKUP ,
@@ -263,7 +262,7 @@ public void testGetEntitlementsReturnsEntitlementsForPluginModule() throws IOExc
263262 createEmptyTestServerPolicy (),
264263 List .of (),
265264 Map .of ("mock-plugin" , createPluginPolicy ("org.example.plugin" )),
266- c -> new PolicyScope ("mock-plugin" , moduleName (c )),
265+ c -> PolicyScope . plugin ("mock-plugin" , moduleName (c )),
267266 Map .of ("mock-plugin" , Path .of ("modules" , "mock-plugin" )),
268267 NO_ENTITLEMENTS_MODULE ,
269268 TEST_PATH_LOOKUP ,
@@ -283,7 +282,7 @@ public void testGetEntitlementsResultIsCached() {
283282 createEmptyTestServerPolicy (),
284283 List .of (),
285284 Map .ofEntries (entry ("plugin2" , createPluginPolicy (ALL_UNNAMED ))),
286- c -> new PolicyScope ("plugin2" , moduleName (c )),
285+ c -> PolicyScope . plugin ("plugin2" , moduleName (c )),
287286 Map .of ("plugin2" , Path .of ("modules" , "plugin2" )),
288287 NO_ENTITLEMENTS_MODULE ,
289288 TEST_PATH_LOOKUP ,
@@ -347,8 +346,8 @@ public void testAgentsEntitlements() throws IOException, ClassNotFoundException
347346 List .of (new CreateClassLoaderEntitlement ()),
348347 Map .of (),
349348 c -> c .getPackageName ().startsWith (TEST_AGENTS_PACKAGE_NAME )
350- ? new PolicyScope ( APM_AGENT_COMPONENT_NAME , "test.agent.module" )
351- : new PolicyScope ("test" , "test.plugin.module" ),
349+ ? PolicyScope . apmAgent ( "test.agent.module" )
350+ : PolicyScope . plugin ("test" , "test.plugin.module" ),
352351 Map .of (),
353352 NO_ENTITLEMENTS_MODULE ,
354353 TEST_PATH_LOOKUP ,
@@ -377,7 +376,7 @@ public void testDuplicateEntitlements() {
377376 ),
378377 List .of (),
379378 Map .of (),
380- c -> new PolicyScope ("test" , moduleName (c )),
379+ c -> PolicyScope . plugin ("test" , moduleName (c )),
381380 Map .of (),
382381 NO_ENTITLEMENTS_MODULE ,
383382 TEST_PATH_LOOKUP ,
@@ -395,7 +394,7 @@ public void testDuplicateEntitlements() {
395394 createEmptyTestServerPolicy (),
396395 List .of (new CreateClassLoaderEntitlement (), new CreateClassLoaderEntitlement ()),
397396 Map .of (),
398- c -> new PolicyScope ("test" , moduleName (c )),
397+ c -> PolicyScope . plugin ("test" , moduleName (c )),
399398 Map .of (),
400399 NO_ENTITLEMENTS_MODULE ,
401400 TEST_PATH_LOOKUP ,
@@ -433,7 +432,7 @@ public void testDuplicateEntitlements() {
433432 )
434433 )
435434 ),
436- c -> new PolicyScope ("plugin1" , moduleName (c )),
435+ c -> PolicyScope . plugin ("plugin1" , moduleName (c )),
437436 Map .of ("plugin1" , Path .of ("modules" , "plugin1" )),
438437 NO_ENTITLEMENTS_MODULE ,
439438 TEST_PATH_LOOKUP ,
@@ -485,7 +484,7 @@ public void testFilesEntitlementsWithExclusive() {
485484 )
486485 )
487486 ),
488- c -> new PolicyScope ("" , moduleName (c )),
487+ c -> PolicyScope . plugin ("" , moduleName (c )),
489488 Map .of ("plugin1" , Path .of ("modules" , "plugin1" ), "plugin2" , Path .of ("modules" , "plugin2" )),
490489 NO_ENTITLEMENTS_MODULE ,
491490 TEST_PATH_LOOKUP ,
@@ -538,7 +537,7 @@ public void testFilesEntitlementsWithExclusive() {
538537 )
539538 )
540539 ),
541- c -> new PolicyScope ("" , moduleName (c )),
540+ c -> PolicyScope . plugin ("" , moduleName (c )),
542541 Map .of (),
543542 NO_ENTITLEMENTS_MODULE ,
544543 TEST_PATH_LOOKUP ,
@@ -564,7 +563,7 @@ public void testPluginResolverOverridesAgents() {
564563 createEmptyTestServerPolicy (),
565564 List .of (new CreateClassLoaderEntitlement ()),
566565 Map .of (),
567- c -> new PolicyScope ("test" , moduleName (c )), // Insist that the class is in a plugin
566+ c -> PolicyScope . plugin ("test" , moduleName (c )), // Insist that the class is in a plugin
568567 Map .of (),
569568 NO_ENTITLEMENTS_MODULE ,
570569 TEST_PATH_LOOKUP ,
@@ -586,7 +585,7 @@ private static PolicyManager policyManager(Module entitlementsModule) {
586585 createEmptyTestServerPolicy (),
587586 List .of (),
588587 Map .of (),
589- c -> new PolicyScope ("test" , moduleName (c )),
588+ c -> PolicyScope . plugin ("test" , moduleName (c )),
590589 Map .of (),
591590 entitlementsModule ,
592591 TEST_PATH_LOOKUP ,
0 commit comments