fastify-basic-auth
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -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" | ||
} | ||
} |
34
test.js
@@ -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') | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
12835
2
333
0
- Removedfast-json-stringify@^1.5.3
- Removedajv@6.12.6(transitive)
- Removeddeepmerge@4.3.1(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedfast-json-stringify@1.21.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedstring-similarity@4.0.4(transitive)
- Removeduri-js@4.4.1(transitive)