Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameters encoded to base 64 should be decoded as UTF-8, not ASCII. #1496

Merged
merged 1 commit into from Mar 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/helpers.js
Expand Up @@ -74,7 +74,7 @@ function isReadStream (rs) {
}

function toBase64 (str) {
return (new Buffer(str || '', 'ascii')).toString('base64')
return (new Buffer(str || '', 'utf8')).toString('base64')
}

exports.isFunction = isFunction
Expand Down
27 changes: 25 additions & 2 deletions tests/test-basic-auth.js
Expand Up @@ -22,6 +22,8 @@ tape('setup', function(t) {
ok = true
} else if ( req.headers.authorization === 'Basic ' + new Buffer(':pass').toString('base64')) {
ok = true
} else if ( req.headers.authorization === 'Basic ' + new Buffer('user:pâss').toString('base64')) {
ok = true
} else {
// Bad auth header, don't send back WWW-Authenticate header
ok = false
Expand Down Expand Up @@ -155,14 +157,35 @@ tape('pass - undefined', function(t) {
})
})


tape('pass - utf8', function(t) {
t.doesNotThrow( function() {
var r = request({
'method': 'GET',
'uri': 'http://localhost:6767/allow_undefined_password/',
'auth': {
'user': 'user',
'pass': 'pâss',
'sendImmediately': false
}
}, function(error, res, body ) {
t.equal(r._auth.user, 'user')
t.equal(r._auth.pass, 'pâss')
t.equal(res.statusCode, 200)
t.equal(numBasicRequests, 12)
t.end()
})
})
})

tape('auth method', function(t) {
var r = request
.get('http://localhost:6767/test/')
.auth('user','',false)
.on('response', function (res) {
t.equal(r._auth.user, 'user')
t.equal(res.statusCode, 200)
t.equal(numBasicRequests, 12)
t.equal(numBasicRequests, 14)
t.end()
})
})
Expand All @@ -179,7 +202,7 @@ tape('get method', function(t) {
t.equal(r._auth.user, 'user')
t.equal(err, null)
t.equal(res.statusCode, 200)
t.equal(numBasicRequests, 14)
t.equal(numBasicRequests, 16)
t.end()
})
})
Expand Down