Skip to content

Commit

Permalink
update capabilities logic for sudo prefixes (#5647)
Browse files Browse the repository at this point in the history
update capabilities logic to determine need for sudo based on sudo prefix paths
  • Loading branch information
madalynrose authored Oct 31, 2018
1 parent ea69d16 commit 6576251
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ui/app/models/capabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const computedCapability = function(capability) {
return false;
}
// if the path is sudo protected, they'll need sudo + the appropriate capability
if (SUDO_PATHS.includes(path) || SUDO_PATH_PREFIXES.find(item => item.startsWith(path))) {
if (SUDO_PATHS.includes(path) || SUDO_PATH_PREFIXES.find(item => path.startsWith(item))) {
return capabilities.includes('sudo') && capabilities.includes(capability);
}
return capabilities.includes(capability);
Expand Down
42 changes: 42 additions & 0 deletions ui/tests/unit/models/capabilities-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,46 @@ module('Unit | Model | capabilities', function(hooks) {
assert.notOk(model.get('canDelete'));
assert.notOk(model.get('canList'));
});

test('it does not require sudo on sys/leases/revoke if update capability is present and path is not fully a sudo prefix', function(assert) {
let model = run(() =>
this.owner.lookup('service:store').createRecord('capabilities', {
path: 'sys/leases/revoke',
capabilities: ['update', 'read'],
})
);
assert.ok(model.get('canRead'));
assert.notOk(model.get('canCreate'), 'sudo requires the capability to be set as well');
assert.ok(model.get('canUpdate'), 'should not require sudo if it has update');
assert.notOk(model.get('canDelete'));
assert.notOk(model.get('canList'));
});

test('it requires sudo on prefix path even if capability is present', function(assert) {
let model = run(() =>
this.owner.lookup('service:store').createRecord('capabilities', {
path: SUDO_PATH_PREFIXES[0] + '/aws',
capabilities: ['update', 'read'],
})
);
assert.notOk(model.get('canRead'));
assert.notOk(model.get('canCreate'));
assert.notOk(model.get('canUpdate'), 'should still require sudo');
assert.notOk(model.get('canDelete'));
assert.notOk(model.get('canList'));
});

test('it does not require sudo on prefix path if both update and sudo capabilities are present', function(assert) {
let model = run(() =>
this.owner.lookup('service:store').createRecord('capabilities', {
path: SUDO_PATH_PREFIXES[0] + '/aws',
capabilities: ['sudo', 'update', 'read'],
})
);
assert.ok(model.get('canRead'));
assert.notOk(model.get('canCreate'));
assert.ok(model.get('canUpdate'), 'should not require sudo');
assert.notOk(model.get('canDelete'));
assert.notOk(model.get('canList'));
});
});

0 comments on commit 6576251

Please sign in to comment.