PermissionEvaluator: rename query to authorizeConditional
Signed-off-by: Vincenzo Scamporlino <me@vinzscam.dev>
This commit is contained in:
@@ -137,7 +137,7 @@ describe('ServerPermissionClient', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('query', () => {
|
||||
describe('authorizeConditional', () => {
|
||||
let mockAuthorizeHandler: jest.Mock;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -162,7 +162,9 @@ describe('ServerPermissionClient', () => {
|
||||
tokenManager: ServerTokenManager.noop(),
|
||||
});
|
||||
|
||||
await client.query([{ permission: testResourcePermission }]);
|
||||
await client.authorizeConditional([
|
||||
{ permission: testResourcePermission },
|
||||
]);
|
||||
|
||||
expect(mockAuthorizeHandler).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -174,9 +176,12 @@ describe('ServerPermissionClient', () => {
|
||||
tokenManager,
|
||||
});
|
||||
|
||||
await client.query([{ permission: testResourcePermission }], {
|
||||
token: (await tokenManager.getToken()).token,
|
||||
});
|
||||
await client.authorizeConditional(
|
||||
[{ permission: testResourcePermission }],
|
||||
{
|
||||
token: (await tokenManager.getToken()).token,
|
||||
},
|
||||
);
|
||||
|
||||
expect(mockAuthorizeHandler).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -188,9 +193,12 @@ describe('ServerPermissionClient', () => {
|
||||
tokenManager,
|
||||
});
|
||||
|
||||
await client.query([{ permission: testResourcePermission }], {
|
||||
token: 'a-user-token',
|
||||
});
|
||||
await client.authorizeConditional(
|
||||
[{ permission: testResourcePermission }],
|
||||
{
|
||||
token: 'a-user-token',
|
||||
},
|
||||
);
|
||||
|
||||
expect(mockAuthorizeHandler).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -78,12 +78,13 @@ export class ServerPermissionClient implements PermissionEvaluator {
|
||||
this.tokenManager = options.tokenManager;
|
||||
this.permissionEnabled = options.permissionEnabled;
|
||||
}
|
||||
async query(
|
||||
|
||||
async authorizeConditional(
|
||||
queries: QueryPermissionRequest[],
|
||||
options?: EvaluatorRequestOptions,
|
||||
): Promise<PolicyDecision[]> {
|
||||
return (await this.isEnabled(options?.token))
|
||||
? this.permissionClient.query(queries, options)
|
||||
? this.permissionClient.authorizeConditional(queries, options)
|
||||
: queries.map(_ => ({ result: AuthorizeResult.ALLOW }));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user