Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow permissions service to match on glob path that may end with a slash #6301

Merged
merged 1 commit into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ui/app/services/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ export default Service.extend({
hasMatchingGlobPath(pathName, capability) {
const globPaths = this.get('globPaths');
if (globPaths) {
const matchingPath = Object.keys(globPaths).find(k => pathName.includes(k));
const matchingPath = Object.keys(globPaths).find(k => {
return pathName.includes(k) || pathName.includes(k.replace(/\/$/, ''));
});
const hasMatchingPath =
(matchingPath && !this.isDenied(globPaths[matchingPath])) || globPaths.hasOwnProperty('');

Expand Down
10 changes: 10 additions & 0 deletions ui/tests/unit/services/permissions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const PERMISSIONS_RESPONSE = {
'baz/biz': {
capabilities: ['read'],
},
'ends/in/slash/': {
capabilities: ['list'],
},
},
},
};
Expand Down Expand Up @@ -76,6 +79,13 @@ module('Unit | Service | permissions', function(hooks) {
assert.equal(service.hasPermission('boo'), false);
});

test('it returns true if passed path does not end in a slash but globPath does', function(assert) {
let service = this.owner.lookup('service:permissions');
service.set('globPaths', PERMISSIONS_RESPONSE.data.glob_paths);
assert.equal(service.hasPermission('ends/in/slash'), true, 'matches without slash');
assert.equal(service.hasPermission('ends/in/slash/'), true, 'matches with slash');
});

test('it returns false if a policy does not includes access to a path', function(assert) {
let service = this.owner.lookup('service:permissions');
assert.equal(service.hasPermission('danger'), false);
Expand Down