Skip to content

Commit

Permalink
fix: return error in authorize publish (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando authored Jul 20, 2020
1 parent 834434a commit 84b1cbb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/authorizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Authorizer.prototype.authenticate = function () {
Authorizer.prototype.authorizePublish = function () {
var that = this
return function (client, packet, cb) {
cb(null, minimatch(packet.topic, that._users.get(client.user).authorizePublish || defaultGlob))
cb(minimatch(packet.topic, that._users.get(client.user).authorizePublish || defaultGlob) ? null : Error('Publish not authorized'))
}
}

Expand Down
13 changes: 8 additions & 5 deletions test/authorizer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ test('add user and authenticate/authorize', async function (t) {
var notAllowed = { topic: 'not/allowed' }
var allowed = { topic: 'allowed/topic/1' }

res = await authorizePub(client, notAllowed)
t.equal(res, false, 'should not authorize pub on not allowed topics')

res = await authorizePub(client, allowed)
t.equal(res, true, 'should authorize pub on allowed topics')
try {
res = await authorizePub(client, notAllowed)
} catch (error) {
t.equal(error.message, 'Publish not authorized', 'should not authorize pub on not allowed topics')
}

await authorizePub(client, allowed)
t.pass('should authorize pub on allowed topics')

res = await authorizeSub(client, notAllowed)
t.equal(res, null, 'should not authorize sub on not allowed topics')
Expand Down

0 comments on commit 84b1cbb

Please sign in to comment.