http-auth
Version:
Node.js package for HTTP basic and digest access authentication.
87 lines (67 loc) • 2.51 kB
text/coffeescript
request = require 'request'
http = require 'http'
auth = require '../gensrc/http-auth'
htpasswd = require 'htpasswd'
module.exports =
setUp: (callback) ->
basic = auth.basic {
realm: "Private Area.",
file: __dirname + "/../data/users.htpasswd"
}
@server = http.createServer basic, (req, res) ->
res.end "Welcome to private area - #{req.user}!"
@server.listen 1337
callback()
tearDown: (callback) ->
@server.close()
callback()
testSuccessSHA1: (test) ->
callback = (error, response, body) ->
test.equals body, "Welcome to private area - gevorg!"
test.done()
(request.get 'http://127.0.0.1:1337', callback).auth 'gevorg', 'gpass'
testSuccessCrypt: (test) ->
callback = (error, response, body) ->
test.equals body, "Welcome to private area - vera!"
test.done()
(request.get 'http://127.0.0.1:1337', callback).auth 'vera', 'kruta'
testSuccessMD5: (test) ->
callback = (error, response, body) ->
test.equals body, "Welcome to private area - hera!"
test.done()
(request.get 'http://127.0.0.1:1337', callback).auth 'hera', 'gnu'
testSuccessPlain: (test) ->
callback = (error, response, body) ->
test.equals body, "Welcome to private area - 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'