Skip to content

Commit

Permalink
tests fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
benzekrimaha committed Oct 30, 2023
1 parent 39988e5 commit 1dade50
Showing 1 changed file with 18 additions and 77 deletions.
95 changes: 18 additions & 77 deletions tests/unit/policyEvaluator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const fakeTimers = require('@sinonjs/fake-timers');
const evaluator = require('../../lib/policyEvaluator/evaluator');
const evaluatePolicy = evaluator.evaluatePolicy;
const evaluateAllPolicies = evaluator.evaluateAllPolicies;
const evaluateAllPoliciesNew = evaluator.evaluateAllPoliciesNew;
const StandardEvaluateAllPolicies = evaluator.StandardEvaluateAllPolicies;
const handleWildcards =
require('../../lib/policyEvaluator/utils/wildcards').handleWildcards;
const substituteVariables =
Expand Down Expand Up @@ -1457,7 +1457,7 @@ describe('policyEvaluator', () => {
'my_favorite_bucket', undefined,
undefined, undefined, 'bucketDelete', 's3');
requestContext.setRequesterInfo({});
const result = evaluateAllPoliciesNew(requestContext,
const result = StandardEvaluateAllPolicies(requestContext,

Check warning on line 1460 in tests/unit/policyEvaluator.spec.js

View workflow job for this annotation

GitHub Actions / test

A function with a name starting with an uppercase letter should only be used as a constructor
[samples['arn:aws:iam::aws:policy/AmazonS3FullAccess'],
samples['Deny Bucket Policy']], log);
assert.deepStrictEqual(result, {
Expand All @@ -1471,7 +1471,7 @@ describe('policyEvaluator', () => {
'notVeryPrivate', undefined,
undefined, undefined, 'bucketDelete', 's3');
requestContext.setRequesterInfo({});
const result = evaluateAllPoliciesNew(requestContext,
const result = StandardEvaluateAllPolicies(requestContext,

Check warning on line 1474 in tests/unit/policyEvaluator.spec.js

View workflow job for this annotation

GitHub Actions / test

A function with a name starting with an uppercase letter should only be used as a constructor
[samples['Multi-Statement Policy'],
samples['Variable Bucket Policy']], log);
assert.deepStrictEqual(result, {
Expand All @@ -1485,7 +1485,7 @@ describe('policyEvaluator', () => {
'notbucket', undefined,
undefined, undefined, 'objectGet', 's3');
requestContext.setRequesterInfo({});
const result = evaluateAllPoliciesNew(requestContext, [
const result = StandardEvaluateAllPolicies(requestContext, [

Check warning on line 1488 in tests/unit/policyEvaluator.spec.js

View workflow job for this annotation

GitHub Actions / test

A function with a name starting with an uppercase letter should only be used as a constructor
samples['Multi-Statement Policy'],
samples['Variable Bucket Policy'],
], log);
Expand Down Expand Up @@ -1548,7 +1548,7 @@ describe('policyEvaluator', () => {
},
};

const TestMatrixV2 = [
const TestMatrix = [
{
policiesToEvaluate: [],
expectedPolicyEvaluation: {
Expand Down Expand Up @@ -1605,6 +1605,13 @@ describe('policyEvaluator', () => {
isImplicit: true,
},
},
{
policiesToEvaluate: ['Neutral', 'Deny'],
expectedPolicyEvaluation: {
verdict: 'Deny',
isImplicit: false,
},
},
{
policiesToEvaluate: ['Allow', 'Deny'],
expectedPolicyEvaluation: {
Expand Down Expand Up @@ -1663,102 +1670,36 @@ describe('policyEvaluator', () => {
},
];

TestMatrixV2.forEach(testCase => {
TestMatrix.forEach(testCase => {
it(`policies evaluating individually to [${testCase.policiesToEvaluate.join(', ')}] `
+ `should return ${testCase.expectedPolicyEvaluation}`, () => {
requestContext = new RequestContext({}, {},
'my_favorite_bucket', undefined,
undefined, undefined, 'objectGet', 's3');
requestContext.setRequesterInfo({});
const result = evaluateAllPoliciesNew(
const result = EvaluateAllPolicies(

Check warning on line 1680 in tests/unit/policyEvaluator.spec.js

View workflow job for this annotation

GitHub Actions / test

A function with a name starting with an uppercase letter should only be used as a constructor

Check failure on line 1680 in tests/unit/policyEvaluator.spec.js

View workflow job for this annotation

GitHub Actions / test

'EvaluateAllPolicies' is not defined
requestContext,
testCase.policiesToEvaluate.map(policyName => TestMatrixPolicies[policyName]),
log);
assert.deepStrictEqual(result, testCase.expectedPolicyEvaluation);
assert.StrictEqual(result, testCase.expectedPolicyEvaluation.verdict);

Check warning on line 1684 in tests/unit/policyEvaluator.spec.js

View workflow job for this annotation

GitHub Actions / test

A function with a name starting with an uppercase letter should only be used as a constructor
});
});

const TestMatrix = [
{
policiesToEvaluate: [],
expectedPolicyEvaluation: 'Deny',
},
{
policiesToEvaluate: ['Allow'],
expectedPolicyEvaluation: 'Allow',
},
{
policiesToEvaluate: ['Neutral'],
expectedPolicyEvaluation: 'Deny',
},
{
policiesToEvaluate: ['Deny'],
expectedPolicyEvaluation: 'Deny',
},
{
policiesToEvaluate: ['Allow', 'Allow'],
expectedPolicyEvaluation: 'Allow',
},
{
policiesToEvaluate: ['Allow', 'Neutral'],
expectedPolicyEvaluation: 'Allow',
},
{
policiesToEvaluate: ['Neutral', 'Allow'],
expectedPolicyEvaluation: 'Allow',
},
{
policiesToEvaluate: ['Neutral', 'Neutral'],
expectedPolicyEvaluation: 'Deny',
},
{
policiesToEvaluate: ['Allow', 'Deny'],
expectedPolicyEvaluation: 'Deny',
},
{
policiesToEvaluate: ['AllowWithTagCondition'],
expectedPolicyEvaluation: 'NeedTagConditionEval',
},
{
policiesToEvaluate: ['Allow', 'AllowWithTagCondition'],
expectedPolicyEvaluation: 'Allow',
},
{
policiesToEvaluate: ['DenyWithTagCondition'],
expectedPolicyEvaluation: 'Deny',
},
{
policiesToEvaluate: ['Allow', 'DenyWithTagCondition'],
expectedPolicyEvaluation: 'NeedTagConditionEval',
},
{
policiesToEvaluate: ['AllowWithTagCondition', 'DenyWithTagCondition'],
expectedPolicyEvaluation: 'NeedTagConditionEval',
},
{
policiesToEvaluate: ['AllowWithTagCondition', 'DenyWithTagCondition', 'Deny'],
expectedPolicyEvaluation: 'Deny',
},
{
policiesToEvaluate: ['DenyWithTagCondition', 'AllowWithTagCondition', 'Allow'],
expectedPolicyEvaluation: 'NeedTagConditionEval',
},
];

TestMatrix.forEach(testCase => {
it(`policies evaluating individually to [${testCase.policiesToEvaluate.join(', ')}] `
+ `should return ${testCase.expectedPolicyEvaluation}`, () => {
requestContext = new RequestContext({}, {},
'my_favorite_bucket', undefined,
undefined, undefined, 'objectGet', 's3');
requestContext.setRequesterInfo({});
const result = evaluateAllPolicies(
const result = StandardEvaluateAllPolicies(

Check warning on line 1695 in tests/unit/policyEvaluator.spec.js

View workflow job for this annotation

GitHub Actions / test

A function with a name starting with an uppercase letter should only be used as a constructor
requestContext,
testCase.policiesToEvaluate.map(policyName => TestMatrixPolicies[policyName]),
log);
assert.strictEqual(result, testCase.expectedPolicyEvaluation);
assert.deepStrictEqual(result, testCase.expectedPolicyEvaluation);
});
});

Check failure on line 1701 in tests/unit/policyEvaluator.spec.js

View workflow job for this annotation

GitHub Actions / test

Block must not be padded by blank lines

});
});

Expand Down

0 comments on commit 1dade50

Please sign in to comment.