http-auth
Version:
Node.js package for HTTP basic and digest access authentication.
69 lines (54 loc) • 1.92 kB
text/coffeescript
request = require 'request'
express = require 'express'
auth = require '../gensrc/http-auth'
module.exports =
setUp: (callback) ->
basic = auth.basic {
realm: "Private Area.",
file: __dirname + "/../data/users.htpasswd"
}
app = express()
app.use(auth.connect basic)
app.get '/', (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 - gevorg!"
test.done()
(request.get 'http://127.0.0.1:1337', callback).auth 'gevorg', 'gpass'
testSuccessPlain: (test) ->
callback = (error, response, body) ->
test.equals body, "Hello from express - Sarah!"
test.done()
(request.get 'http://127.0.0.1:1337', callback).auth 'Sarah', 'testpass'
testWrongPassword: (test) ->
callback = (error, response, body) ->
test.equals body, "401 Unauthorized"
test.done()
(request.get 'http://127.0.0.1:1337', callback).auth 'gevorg', 'duck'
testWrongUser: (test) ->
callback = (error, response, body) ->
test.equals body, "401 Unauthorized"
test.done()
(request.get 'http://127.0.0.1:1337', callback).auth 'solomon', 'gpass'