Skip to content

Commit

Permalink
fix: Applied RBAC authorisation to sendTaskFailure. Switched from FAI…
Browse files Browse the repository at this point in the history
…LED to NOAUTH status is not al
  • Loading branch information
jezhiggins committed Jun 26, 2018
1 parent eb8b316 commit 311425c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
22 changes: 18 additions & 4 deletions lib/plugin/components/services/statebox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,23 @@ class StateboxService {
this.statebox.sendTaskHeartbeat(executionName, output, executionOptions, callback)
}

sendTaskFailure (executionName, output, executionOptions, callback) {
return promiseOrCallback(this.statebox.sendTaskFailure(executionName, output), callback)
}
async sendTaskFailure (executionName, output, executionOptions, callback) {
if (callback) {
return promiseOrCallback(this.statebox.sendTaskFailure(executionName, output), callback)
}

const executionDescription = await this.statebox.describeExecution(executionName, executionOptions)
const [authOk, errExecDesc] = await this.authorisationCheck(
executionOptions.userId,
executionDescription.stateMachineName,
executionDescription.executionOptions,
'update'
)

return (authOk)
? this.statebox.sendTaskFailure(executionName, output)
: errExecDesc
} // sendTaskFailure

waitUntilStoppedRunning (executionName, callback) {
const p = this.statebox.waitUntilStoppedRunning(executionName)
Expand Down Expand Up @@ -179,7 +193,7 @@ class StateboxService {
return [
false,
{
status: 'FAILED',
status: 'NOAUTH',
stateMachineName: stateMachineName,
errorCode: '401',
errorMessage: `'${(typeof userId === 'string') ? userId : null}' can not perform '${action}' on '${stateMachineName}'`
Expand Down
18 changes: 16 additions & 2 deletions test/statebox-service-acl-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ const heartBeatTests = [
{ userId: user}
),
status: 'SUCCEEDED'
},
{
label: 'sendTaskFailure',
testFn: (statebox, executionName, user) => statebox.sendTaskFailure(
executionName,
{
error: 'FAIL',
cause: 'Brexit'
},
{ userId: user}
),
status: 'FAILED'
}
]

Expand Down Expand Up @@ -139,7 +151,7 @@ describe('Statebox service RBAC authorisation', function () {
userId: disallowed
}
)
expect(execDesc.status).to.eql('FAILED')
expect(execDesc.status).to.eql('NOAUTH')
expect(execDesc.stateMachineName).to.eql(test.blueprint)
expect(execDesc.errorCode).to.eql('401')
})
Expand Down Expand Up @@ -200,7 +212,9 @@ describe('Statebox service RBAC authorisation', function () {
it('stopExecution', async () => {
const execDesc = await testAction.testFn(statebox, executionName, disallowed)

expect(execDesc.status).to.eql('FAILED')
expect(execDesc.status).to.eql('NOAUTH')
expect(execDesc.stateMachineName).to.eql(test.blueprint)
expect(execDesc.errorCode).to.eql('401')
})
})
} // for disallowed ...
Expand Down

0 comments on commit 311425c

Please sign in to comment.