permission-node: rename and adjust policy return type to reduce nesting

Signed-off-by: MT Lewis <mtlewis@users.noreply.github.com>
This commit is contained in:
MT Lewis
2021-11-30 14:48:56 +00:00
parent 0d568fb4f1
commit e7851efa9e
8 changed files with 49 additions and 49 deletions
@@ -161,12 +161,10 @@ describe('createRouter', () => {
beforeEach(() => {
policy.handle.mockReturnValueOnce({
result: AuthorizeResult.CONDITIONAL,
pluginId: 'test-plugin',
resourceType: 'test-resource-1',
conditions: {
pluginId: 'test-plugin',
resourceType: 'test-resource-1',
conditions: {
anyOf: [{ rule: 'test-rule', params: ['abc'] }],
},
anyOf: [{ rule: 'test-rule', params: ['abc'] }],
},
});
});
@@ -265,11 +263,9 @@ describe('createRouter', () => {
it('returns a 500 error if the policy returns a different resourceType', async () => {
policy.handle.mockReturnValueOnce({
result: AuthorizeResult.CONDITIONAL,
conditions: {
pluginId: 'test-plugin',
resourceType: 'test-resource-2',
conditions: {},
},
pluginId: 'test-plugin',
resourceType: 'test-resource-2',
conditions: {},
});
const response = await request(app)
@@ -80,7 +80,7 @@ const handleRequest = async (
if (response.result === AuthorizeResult.CONDITIONAL) {
// Sanity check that any resource provided matches the one expected by the permission
if (request.permission.resourceType !== response.conditions.resourceType) {
if (request.permission.resourceType !== response.resourceType) {
throw new Error(
`Invalid resource conditions returned from permission policy for permission ${request.permission.name}`,
);
@@ -92,7 +92,9 @@ const handleRequest = async (
...(await permissionIntegrationClient.applyConditions(
{
resourceRef,
...response.conditions,
pluginId: response.pluginId,
resourceType: response.resourceType,
conditions: response.conditions,
},
authHeader,
)),
@@ -102,10 +104,7 @@ const handleRequest = async (
return {
id,
result: AuthorizeResult.CONDITIONAL,
// TODO(mtlewis): this .conditions.conditions situation is a bit awkward. I think it's
// worth exploring a bit of reorganization of the ConditionalPolicyResult type so that
// the naming of property chains like this makes a bit more sense.
conditions: response.conditions.conditions,
conditions: response.conditions,
};
}