Skip to content

Commit

Permalink
chore: [email protected] and other deps (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando authored Oct 20, 2023
1 parent 68f7b3c commit e9a7806
Show file tree
Hide file tree
Showing 7 changed files with 17,368 additions and 13,725 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14, 16, 18]
node-version: [18, 20]
db: [mongodb, redis]
include:
- db: mongodb
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,6 @@ dist

.vscode

credentials.json
credentials.json

.tap
16 changes: 6 additions & 10 deletions .taprc
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# vim: set filetype=yaml :
jobs: 1
no-ts: true
no-jsx: true
no-flow: true
coverage: true
browser: false
coverage-report: html
lines: 85
statements: 80
functions: 55
branches: 55
coverage-report:
- html
plugin:
- "!@tapjs/typescript"
allow-incomplete-coverage: true
41 changes: 32 additions & 9 deletions lib/authorizer.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
'use strict'

const hasher = require('./hasher')
const minimatch = require('minimatch')
const { minimatch } = require('minimatch')
const defaultGlob = '**'

const mapToObj = m => {
const mapToObj = (m) => {
return Array.from(m).reduce((obj, [key, value]) => {
obj[key] = value
return obj
}, {})
}

// polyfill for Map
Object.entries = typeof Object.entries === 'function' ? Object.entries : obj => Object.keys(obj).map(k => [k, obj[k]])
Object.entries =
typeof Object.entries === 'function'
? Object.entries
: (obj) => Object.keys(obj).map((k) => [k, obj[k]])

/**
* Authorizer's responsibility is to give an implementation
Expand Down Expand Up @@ -47,7 +50,14 @@ Authorizer.prototype.authenticate = function () {
Authorizer.prototype.authorizePublish = function () {
const that = this
return function (client, packet, cb) {
cb(minimatch(packet.topic, that._users.get(client.user).authorizePublish || defaultGlob) ? null : Error('Publish not authorized'))
cb(
minimatch(
packet.topic,
that._users.get(client.user).authorizePublish || defaultGlob
)
? null
: Error('Publish not authorized')
)
}
}

Expand All @@ -59,7 +69,15 @@ Authorizer.prototype.authorizePublish = function () {
Authorizer.prototype.authorizeSubscribe = function () {
const that = this
return function (client, sub, cb) {
cb(null, minimatch(sub.topic, that._users.get(client.user).authorizeSubscribe || defaultGlob) ? sub : null)
cb(
null,
minimatch(
sub.topic,
that._users.get(client.user).authorizeSubscribe || defaultGlob
)
? sub
: null
)
}
}

Expand All @@ -81,8 +99,9 @@ Authorizer.prototype._authenticate = function (client, user, pass, cb) {
client.user = user
user = this._users.get(user)

hasher.verifyPassword(user, pass.toString())
.then(success => cb(null, success))
hasher
.verifyPassword(user, pass.toString())
.then((success) => cb(null, success))
.catch((err) => {
cb(err)
})
Expand All @@ -99,8 +118,12 @@ Authorizer.prototype._authenticate = function (client, user, pass, cb) {
* @param {String} authorizeSubscribe The authorizeSubscribe pattern
* (optional)
*/
Authorizer.prototype.addUser = async function (user, pass, authorizePublish,
authorizeSubscribe) {
Authorizer.prototype.addUser = async function (
user,
pass,
authorizePublish,
authorizeSubscribe
) {
if (!authorizePublish) {
authorizePublish = defaultGlob
}
Expand Down
Loading

0 comments on commit e9a7806

Please sign in to comment.