http-auth
Version:
Node.js package for HTTP basic and digest access authentication.
66 lines (50 loc) • 1.71 kB
text/coffeescript
request = require 'request'
express = require 'express'
auth = require '../gensrc/http-auth'
passport = require 'passport'
module.exports =
setUp: (callback) ->
digest = auth.digest {
realm: "Simon Area.",
file: __dirname + "/../data/users.htdigest"
}
app = express()
passport.use(auth.passport(digest));
app.get '/', passport.authenticate('http', { session: false }), (req, res) ->
res.send "Hello from express - #{req.user}!"
@server = app.listen 1337
callback()
tearDown: (callback) ->
@server.close()
callback()
testSuccess: (test) ->
callback = (error, response, body) ->
test.equals body, "Hello from express - vivi!"
test.done()
(request.get 'http://127.0.0.1:1337', callback).auth 'vivi', 'anna', false
testWrongPassword: (test) ->
callback = (error, response, body) ->
test.equals body, "Unauthorized"
test.done()
(request.get 'http://127.0.0.1:1337', callback).auth 'vivi', 'duck', false
testWrongUser: (test) ->
callback = (error, response, body) ->
test.equals body, "Unauthorized"
test.done()
(request.get 'http://127.0.0.1:1337', callback).auth 'solomon', 'gpass', false