http-auth
Version:
Node.js package for HTTP basic and digest access authentication.
65 lines (51 loc) • 1.91 kB
text/coffeescript
request = require 'request'
http = require 'http'
auth = require '../gensrc/http-auth'
module.exports =
setUp: (callback) ->
digest = auth.digest {
realm: "Simon Area.",
file: __dirname + "/../data/users.htdigest"
}
@server = http.createServer digest, (req, res) ->
res.end "Welcome to private area - #{req.user}!"
@server.listen 1337
callback()
tearDown: (callback) ->
@server.close()
callback()
testSuccess: (test) ->
callback = (error, response, body) ->
test.equals body, "Welcome to private area - vivi!"
test.done()
(request.get 'http://127.0.0.1:1337', callback).auth 'vivi', 'anna', false
testSuccessSpecialURI: (test) ->
callback = (error, response, body) ->
test.equals body, "Welcome to private area - vivi!"
test.done()
(request.get 'http://127.0.0.1:1337/?coffee=rocks', callback).auth 'vivi', 'anna', false
testWrongPassword: (test) ->
callback = (error, response, body) ->
test.equals body, "401 Unauthorized"
test.done()
(request.get 'http://127.0.0.1:1337', callback).auth 'vivi', 'goose', false
testWrongUser: (test) ->
callback = (error, response, body) ->
test.equals body, "401 Unauthorized"
test.done()
(request.get 'http://127.0.0.1:1337', callback).auth 'brad', 'anna', false