Skip to content

Commit

Permalink
ARSN-375: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Toozs committed Nov 27, 2023
1 parent 0459fa4 commit c137c69
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 38 deletions.
4 changes: 3 additions & 1 deletion lib/auth/backends/ChainBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@ export default class ChainBackend extends BaseBackend {
const policyRes: any = {
isAllowed: policyMap[key].isAllowed,
action: policyMap[key].action,
isImplicit: policyMap[key].isImplicit
};
if (typeof policyMap[key].isImplicit === 'boolean') {
policyRes.isImplicit = policyMap[key].isImplicit;
}
if (policyMap[key].arn !== '') {
policyRes.arn = policyMap[key].arn;
}
Expand Down
94 changes: 57 additions & 37 deletions tests/unit/auth/chainBackend.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ describe('Auth Backend: Chain Backend', () => {
it('should return an error if any of the clients fails', done => {
const backend = new ChainBackend('chain', [
new TestBackend('test1', null, {
message: { body: [{ isAllowed: false, arn: 'arn:aws:s3:::policybucket/obj1' }] },
message: { body: [{ action: "PutObject", isAllowed: false, isImplicit: false, arn: 'arn:aws:s3:::policybucket/obj1' }] },

Check failure on line 195 in tests/unit/auth/chainBackend.spec.js

View workflow job for this annotation

GitHub Actions / test

This line has a length of 141. Maximum allowed is 120

Check warning on line 195 in tests/unit/auth/chainBackend.spec.js

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote
}),
new TestBackend('test2', testError, null),
new TestBackend('test3', null, {
message: { body: [{ isAllowed: true, arn: 'arn:aws:s3:::policybucket/obj1' }] },
message: { body: [{ action: "PutObject", isAllowed: true, isImplicit: false, arn: 'arn:aws:s3:::policybucket/obj1' }] },

Check failure on line 199 in tests/unit/auth/chainBackend.spec.js

View workflow job for this annotation

GitHub Actions / test

This line has a length of 140. Maximum allowed is 120

Check warning on line 199 in tests/unit/auth/chainBackend.spec.js

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote
}),
]);

Expand All @@ -209,23 +209,25 @@ describe('Auth Backend: Chain Backend', () => {
it('should merge results from clients into a single response object', done => {
const backend = new ChainBackend('chain', [
new TestBackend('test1', null, {
message: { body: [{ isAllowed: false, arn: 'arn:aws:s3:::policybucket/obj1' }] },
message: { body: [{ action: "PutObject", isAllowed: false, isImplicit: false, arn: 'arn:aws:s3:::policybucket/obj1' }] },

Check failure on line 212 in tests/unit/auth/chainBackend.spec.js

View workflow job for this annotation

GitHub Actions / test

This line has a length of 141. Maximum allowed is 120

Check warning on line 212 in tests/unit/auth/chainBackend.spec.js

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote
}),
new TestBackend('test2', null, {
message: { body: [{ isAllowed: true, arn: 'arn:aws:s3:::policybucket/obj2' }] },
message: { body: [{ action: "PutObject", isAllowed: true, isImplicit: false, arn: 'arn:aws:s3:::policybucket/obj2' }] },

Check failure on line 215 in tests/unit/auth/chainBackend.spec.js

View workflow job for this annotation

GitHub Actions / test

This line has a length of 140. Maximum allowed is 120

Check warning on line 215 in tests/unit/auth/chainBackend.spec.js

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote
}),
new TestBackend('test3', null, {
message: { body: [{ isAllowed: true, arn: 'arn:aws:s3:::policybucket/obj1' }] },
message: { body: [{ action: "PutObject", isAllowed: true, isImplicit: false, arn: 'arn:aws:s3:::policybucket/obj1' }] },

Check failure on line 218 in tests/unit/auth/chainBackend.spec.js

View workflow job for this annotation

GitHub Actions / test

This line has a length of 140. Maximum allowed is 120

Check warning on line 218 in tests/unit/auth/chainBackend.spec.js

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote
}),
]);

backend.checkPolicies(null, null, null, (err, res) => {
assert.ifError(err);
assert.deepStrictEqual(res, {
message: { body: [
{ isAllowed: true, arn: 'arn:aws:s3:::policybucket/obj1' },
{ isAllowed: true, arn: 'arn:aws:s3:::policybucket/obj2' },
] },
message: {
body: [
{ action: "PutObject", isAllowed: true, isImplicit: false, arn: 'arn:aws:s3:::policybucket/obj1' },

Check failure on line 227 in tests/unit/auth/chainBackend.spec.js

View workflow job for this annotation

GitHub Actions / test

This line has a length of 127. Maximum allowed is 120

Check warning on line 227 in tests/unit/auth/chainBackend.spec.js

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote
{ action: "PutObject", isAllowed: true, isImplicit: false, arn: 'arn:aws:s3:::policybucket/obj2' },

Check failure on line 228 in tests/unit/auth/chainBackend.spec.js

View workflow job for this annotation

GitHub Actions / test

This line has a length of 127. Maximum allowed is 120

Check warning on line 228 in tests/unit/auth/chainBackend.spec.js

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote
]

Check failure on line 229 in tests/unit/auth/chainBackend.spec.js

View workflow job for this annotation

GitHub Actions / test

Missing trailing comma
},
});
done();
});
Expand Down Expand Up @@ -264,45 +266,63 @@ describe('Auth Backend: Chain Backend', () => {
describe('::_mergePolicies', () => {
it('should correctly merge policies', () => {
const policyResps = [
{ message: { body: [
{ isAllowed: false, arn: 'arn:aws:s3:::policybucket/true1' },
{ isAllowed: true, arn: 'arn:aws:s3:::policybucket/true2' },
{ isAllowed: false, arn: 'arn:aws:s3:::policybucket/false1' },
] } },
{ message: { body: [
{ isAllowed: true, arn: 'arn:aws:s3:::policybucket/true1' },
{ isAllowed: false, arn: 'arn:aws:s3:::policybucket/true2' },
{ isAllowed: false, arn: 'arn:aws:s3:::policybucket/false2' },
] } },
{
message: {
body: [
{ action: 'GetObject', isAllowed: false, isImplicit: false, arn: 'arn:aws:s3:::policybucket/true1' },

Check failure on line 272 in tests/unit/auth/chainBackend.spec.js

View workflow job for this annotation

GitHub Actions / test

This line has a length of 129. Maximum allowed is 120
{ action: 'GetObject', isAllowed: true, isImplicit: false, arn: 'arn:aws:s3:::policybucket/true2' },

Check failure on line 273 in tests/unit/auth/chainBackend.spec.js

View workflow job for this annotation

GitHub Actions / test

This line has a length of 128. Maximum allowed is 120
{ action: 'GetObject', isAllowed: false, isImplicit: false, arn: 'arn:aws:s3:::policybucket/false1' },
{ action: 'GetObject', isAllowed: false, isImplicit: true, arn: 'arn:aws:s3:::policybucket/false2' },
]
}
},
{
message: {
body: [
{ action: 'GetObject', isAllowed: true, isImplicit: false, arn: 'arn:aws:s3:::policybucket/true1' },
{ action: 'GetObject', isAllowed: false, isImplicit: false, arn: 'arn:aws:s3:::policybucket/true2' },
{ action: 'GetObject', isAllowed: false, isImplicit: true, arn: 'arn:aws:s3:::policybucket/false1' },
{ action: 'GetObject', isAllowed: false, isImplicit: false, arn: 'arn:aws:s3:::policybucket/false2' },
]
}
},
];
assert.deepStrictEqual(
ChainBackend._mergePolicies(policyResps),
[
{ isAllowed: true, arn: 'arn:aws:s3:::policybucket/true1' },
{ isAllowed: true, arn: 'arn:aws:s3:::policybucket/true2' },
{ isAllowed: false, arn: 'arn:aws:s3:::policybucket/false1' },
{ isAllowed: false, arn: 'arn:aws:s3:::policybucket/false2' },
{ action: 'GetObject', isAllowed: true, isImplicit: false, arn: 'arn:aws:s3:::policybucket/true1' },
{ action: 'GetObject', isAllowed: true, isImplicit: false, arn: 'arn:aws:s3:::policybucket/true2' },
{ action: 'GetObject', isAllowed: false, isImplicit: true, arn: 'arn:aws:s3:::policybucket/false1' },
{ action: 'GetObject', isAllowed: false, isImplicit: false, arn: 'arn:aws:s3:::policybucket/false2' },
],
);
const policyRespsNested = [
{ message: { body: [
[
{ isAllowed: false, arn: 'arn:aws:s3:::policybucket/true1' },
{ isAllowed: true, arn: 'arn:aws:s3:::policybucket/true2' },
],
] } },
{ message: { body: [
[
{ isAllowed: true, arn: 'arn:aws:s3:::policybucket/true1' },
{ isAllowed: true, arn: 'arn:aws:s3:::policybucket/true2' },
],
] } },
{
message: {
body: [
[
{ action: 'GetObject', isAllowed: false, isImplicit: false, arn: 'arn:aws:s3:::policybucket/true1' },
{ action: 'GetObject', isAllowed: true, isImplicit: false, arn: 'arn:aws:s3:::policybucket/true2' },
],
]
}
},
{
message: {
body: [
[
{ action: 'GetObject', isAllowed: true, isImplicit: false, arn: 'arn:aws:s3:::policybucket/true1' },
{ action: 'GetObject', isAllowed: true, isImplicit: false, arn: 'arn:aws:s3:::policybucket/true2' },
],
]
}
},
];
assert.deepStrictEqual(
ChainBackend._mergePolicies(policyRespsNested),
[
{ isAllowed: true, arn: 'arn:aws:s3:::policybucket/true1' },
{ isAllowed: true, arn: 'arn:aws:s3:::policybucket/true2' },
{ action: 'GetObject', isAllowed: true, isImplicit: false, arn: 'arn:aws:s3:::policybucket/true1' },
{ action: 'GetObject', isAllowed: true, isImplicit: false, arn: 'arn:aws:s3:::policybucket/true2' },
],
);
});
Expand Down

0 comments on commit c137c69

Please sign in to comment.