Skip to content

Commit

Permalink
Improved error handling on unsupported ACL expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
epessina committed Dec 14, 2023
1 parent e8bf1d8 commit 43d0ec6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- Development dependencies updated

### Changed

- Improved error handling on unsupported ACL expressions

## [3.0.5] - 2023-10-02

### Versioning
Expand Down
7 changes: 6 additions & 1 deletion src/sdk/evaluate-acl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ const buildPluginFunction = (plugin: FilterableObject) => {
const evaluatePluginExpression = (userGroupsObject: UserGroupsObject, userPermissionsObject: UserPermissionsObject) => {
return (plugin: FilterableObject): boolean => {
const expressionEvaluationFunction = buildPluginFunction(plugin)
return expressionEvaluationFunction(userGroupsObject, userPermissionsObject) as boolean

try {
return expressionEvaluationFunction(userGroupsObject, userPermissionsObject) as boolean
} catch (err) {
throw new Error(`Error evaluating expression "${plugin.aclExpression}"`)
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/sdk/test/evaluate-acl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,9 @@ describe('Evaluate ACL', () => {
expect(result).to.deep.equal(expected)
})
})

it('should throw if expression is invalid', () => {
expect(() => evaluateAcl({ aclExpression: 'invalid-expression' }, [], []))
.to.throw('Error evaluating expression "invalid-expression"')
})
})

0 comments on commit 43d0ec6

Please sign in to comment.