Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fastify-basic-auth

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-basic-auth - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

2

index.js

@@ -19,3 +19,3 @@ 'use strict'

if (credentials == null) {
done(new Error('Access denied'))
done(new Error('Missing or bad formatted authorization header'))
} else {

@@ -22,0 +22,0 @@ var result = validate(credentials.name, credentials.pass, req, reply, done)

{
"name": "fastify-basic-auth",
"version": "0.1.0",
"version": "0.1.1",
"description": "Fastify basic auth plugin",

@@ -34,5 +34,4 @@ "main": "index.js",

"basic-auth": "^2.0.0",
"fast-json-stringify": "^1.5.3",
"fastify-plugin": "^1.0.1"
}
}

@@ -308,4 +308,38 @@ 'use strict'

test('Missing header', t => {
t.plan(2)
const fastify = Fastify()
fastify.register(basicAuth, { validate })
function validate (username, password, req, res, done) {
if (username === 'user' && password === 'pwd') {
done()
} else {
done(new Error('Unauthorized'))
}
}
fastify.after(() => {
fastify.route({
method: 'GET',
url: '/',
beforeHandler: fastify.basicAuth,
handler: (req, reply) => {
reply.send({ hello: 'world' })
}
})
})
fastify.inject({
url: '/',
method: 'GET'
}, (err, res) => {
t.error(err)
t.strictEqual(res.statusCode, 401)
})
})
function basicAuthHeader (username, password) {
return 'Basic ' + Buffer.from(`${username}:${password}`).toString('base64')
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc