Skip to content

Commit

Permalink
fix(resourcebasedstatement): return true in matchNotPrincipals
Browse files Browse the repository at this point in the history
when notPrincipal is an object and principalType is undefined, false should be returned
  • Loading branch information
roggervalf committed Oct 18, 2020
1 parent 061afe2 commit f78553e
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 101 deletions.
40 changes: 17 additions & 23 deletions dist/main.es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/main.es.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 17 additions & 23 deletions dist/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/main.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/IdentityBasedPolicy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ describe('IdentityBasedPolicy Class', () => {
expect(
new IdentityBasedPolicy([
{
resource: 'some:glob:*:string/word',
action: ['read', 'write']
notResource: ['some:glob:*:string/word'],
notAction: ['read', 'write']
}
])
).toBeInstanceOf(IdentityBasedPolicy);
Expand Down
26 changes: 19 additions & 7 deletions src/ResourceBasedPolicy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ describe('ResourceBasedPolicy Class', () => {
new ResourceBasedPolicy([
{
notPrincipal: 'rogger',
resource: 'some:glob:*:string/example',
action: ['read', 'write']
notResource: 'some:glob:*:string/example',
notAction: ['read', 'write']
}
])
).toBeInstanceOf(ResourceBasedPolicy);
Expand Down Expand Up @@ -102,12 +102,12 @@ describe('ResourceBasedPolicy Class', () => {
it('returns true or false', () => {
const policy = new ResourceBasedPolicy([
{
notPrincipal: 'andre',
notPrincipal: { id: 'andre' },
resource: 'books:horror:*',
action: ['read']
},
{
notPrincipal: { id: 'rogger' },
notPrincipal: { id: ['rogger'] },
resource: 'secrets:admin:*',
action: 'read'
}
Expand All @@ -119,7 +119,7 @@ describe('ResourceBasedPolicy Class', () => {
action: 'read',
resource: 'books:horror:The Call of Cthulhu'
})
).toBe(false);
).toBe(true);
expect(
policy.evaluate({
principal: 'rogger',
Expand Down Expand Up @@ -150,9 +150,14 @@ describe('ResourceBasedPolicy Class', () => {
it('returns true or false', () => {
const policy = new ResourceBasedPolicy([
{
principal: { id: '123' },
principal: { id: ['123'] },
resource: ['books:horror:*'],
action: ['read']
},
{
notPrincipal: ['124'],
resource: ['books:science:*'],
action: ['write']
}
]);

Expand All @@ -172,6 +177,13 @@ describe('ResourceBasedPolicy Class', () => {
principalType: 'id'
})
).toBe(false);
expect(
policy.evaluate({
principal: '125',
action: 'write',
resource: 'books:science:Chemistry'
})
).toBe(true);
});
});

Expand Down Expand Up @@ -236,7 +248,7 @@ describe('ResourceBasedPolicy Class', () => {
const policy = new ResourceBasedPolicy([
{
principal: ['rogger', 'andre'],
notResource: 'books:horror:*',
notResource: ['books:horror:*'],
action: ['read']
}
]);
Expand Down

0 comments on commit f78553e

Please sign in to comment.