Skip to content

Commit

Permalink
Add ability to match more than one wildcard
Browse files Browse the repository at this point in the history
  • Loading branch information
backspace committed Jul 19, 2019
1 parent de12248 commit d949352
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ui/app/abilities/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export default Ability.extend({
const matchingNamespaceName = globNamespaceNames.reduce(
(mostMatching, namespaceName) => {
// TODO what kind of protection/sanitisation is needed here, if any?
// and, can there be more than one *?
const namespaceNameRegExp = new RegExp(namespaceName.replace('*', '.*'));
// and, is * the only matchable character?
const namespaceNameRegExp = new RegExp(namespaceName.replace(/\*/g, '.*'));
const characterDifference = activeNamespace.length - namespaceName.length;

if (
Expand Down
6 changes: 6 additions & 0 deletions ui/tests/unit/abilities/job-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ module('Unit | Ability | job run FIXME just for ease of filtering', function(hoo
'*-more-suffixed': {
policy: 'deny',
},
'*-abc-*': {
policy: 'write',
},
},
},
},
Expand Down Expand Up @@ -163,5 +166,8 @@ module('Unit | Ability | job run FIXME just for ease of filtering', function(hoo
jobAbility.canRun,
'expected the namespace with the greatest number of matched characters to be chosen'
);

systemService.set('activeNamespace.name', '000-abc-999');
assert.ok(jobAbility.canRun, 'expected to be able to match against more than one wildcard');
});
});

0 comments on commit d949352

Please sign in to comment.