@@ -9,6 +9,16 @@ import {
99import { listGatewayMethods } from "./server-methods-list.js" ;
1010import { coreGatewayHandlers } from "./server-methods.js" ;
1111
12+ const RESERVED_ADMIN_PLUGIN_METHOD = "config.plugin.inspect" ;
13+
14+ function setPluginGatewayMethodScope ( method : string , scope : "operator.read" | "operator.write" ) {
15+ const registry = createEmptyPluginRegistry ( ) ;
16+ registry . gatewayMethodScopes = {
17+ [ method ] : scope ,
18+ } ;
19+ setActivePluginRegistry ( registry ) ;
20+ }
21+
1222afterEach ( ( ) => {
1323 setActivePluginRegistry ( createEmptyPluginRegistry ( ) ) ;
1424} ) ;
@@ -52,13 +62,9 @@ describe("method scope resolution", () => {
5262 } ) ;
5363
5464 it ( "keeps reserved admin namespaces admin-only even if a plugin scope is narrower" , ( ) => {
55- const registry = createEmptyPluginRegistry ( ) ;
56- registry . gatewayMethodScopes = {
57- "config.plugin.inspect" : "operator.read" ,
58- } ;
59- setActivePluginRegistry ( registry ) ;
65+ setPluginGatewayMethodScope ( RESERVED_ADMIN_PLUGIN_METHOD , "operator.read" ) ;
6066
61- expect ( resolveLeastPrivilegeOperatorScopesForMethod ( "config.plugin.inspect" ) ) . toEqual ( [
67+ expect ( resolveLeastPrivilegeOperatorScopesForMethod ( RESERVED_ADMIN_PLUGIN_METHOD ) ) . toEqual ( [
6268 "operator.admin" ,
6369 ] ) ;
6470 } ) ;
@@ -119,13 +125,11 @@ describe("operator scope authorization", () => {
119125 } ) ;
120126
121127 it ( "requires admin for reserved admin namespaces even if a plugin registered a narrower scope" , ( ) => {
122- const registry = createEmptyPluginRegistry ( ) ;
123- registry . gatewayMethodScopes = {
124- "config.plugin.inspect" : "operator.read" ,
125- } ;
126- setActivePluginRegistry ( registry ) ;
128+ setPluginGatewayMethodScope ( RESERVED_ADMIN_PLUGIN_METHOD , "operator.read" ) ;
127129
128- expect ( authorizeOperatorScopesForMethod ( "config.plugin.inspect" , [ "operator.read" ] ) ) . toEqual ( {
130+ expect (
131+ authorizeOperatorScopesForMethod ( RESERVED_ADMIN_PLUGIN_METHOD , [ "operator.read" ] ) ,
132+ ) . toEqual ( {
129133 allowed : false ,
130134 missingScope : "operator.admin" ,
131135 } ) ;
0 commit comments