@fastify/basic-auth
Advanced tools
Comparing version 5.1.0 to 5.1.1
@@ -133,3 +133,6 @@ 'use strict' | ||
if (err.statusCode === 401) { | ||
reply.header('WWW-Authenticate', authenticateHeader(req)) | ||
const header = authenticateHeader(req) | ||
if (header) { | ||
reply.header('WWW-Authenticate', header) | ||
} | ||
} | ||
@@ -136,0 +139,0 @@ next(err) |
{ | ||
"name": "@fastify/basic-auth", | ||
"version": "5.1.0", | ||
"version": "5.1.1", | ||
"description": "Fastify basic auth plugin", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -465,2 +465,50 @@ 'use strict' | ||
test('WWW-Authenticate (authenticate: false)', t => { | ||
t.plan(6) | ||
const fastify = Fastify() | ||
const authenticate = false | ||
fastify.register(basicAuth, { validate, authenticate, utf8: false }) | ||
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: '/', | ||
preHandler: fastify.basicAuth, | ||
handler: (req, reply) => { | ||
reply.send({ hello: 'world' }) | ||
} | ||
}) | ||
}) | ||
fastify.inject({ | ||
url: '/', | ||
method: 'GET' | ||
}, (err, res) => { | ||
t.error(err) | ||
t.equal(res.headers['www-authenticate'], undefined) | ||
t.equal(res.statusCode, 401) | ||
}) | ||
fastify.inject({ | ||
url: '/', | ||
method: 'GET', | ||
headers: { | ||
authorization: basicAuthHeader('user', 'pwd') | ||
} | ||
}, (err, res) => { | ||
t.error(err) | ||
t.equal(res.headers['www-authenticate'], undefined) | ||
t.equal(res.statusCode, 200) | ||
}) | ||
}) | ||
test('WWW-Authenticate Realm (authenticate: {realm: "example"}, utf8: false)', t => { | ||
@@ -467,0 +515,0 @@ t.plan(6) |
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
49908
1503