Parse = ParseBasicAuth = require '../../src/parse-basic-auth'

parse = Parse()

module.exports =
    'can ignore normal requests': (test) ->
        req = {}
        parse req, {}, ->
            test.deepEqual req, {}
            test.done()

    'can set default credentials': (test) ->
        req = {}
        defaultCredentials = username: '', password: ''
        parseWithDefault = Parse defaultCredentials
        parseWithDefault req, {}, ->
            test.equal req.credentials, defaultCredentials
            test.done()

    'can parse Authorization header': (test) ->
        credentials =
            user: 'Aladdin'
            password: 'open sesame'
        req =
            headers: authorization: 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='
        parse req, {}, ->
            test.deepEqual req.credentials, credentials
            test.done()

    'can parse a password with a special character': (test) ->
        req =
            headers: authorization: "Basic #{new Buffer("user:pass:word").toString('base64')}"
        parse req, {}, ->
            test.equal 'pass:word', req.credentials.password
            test.done()
