mirror of
https://github.com/tenrok/axios.git
synced 2026-06-11 18:02:32 +03:00
Fixing password encoding with special characters in basic authentication (#1492)
* Fixing password encoding with special characters in basic authentication * Adding test to check if password with non-Latin1 characters pass Co-authored-by: petr.mares <petr.mares@linecorp.com> Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
+1
-1
@@ -23,7 +23,7 @@ module.exports = function xhrAdapter(config) {
|
||||
// HTTP basic authentication
|
||||
if (config.auth) {
|
||||
var username = config.auth.username || '';
|
||||
var password = config.auth.password || '';
|
||||
var password = unescape(encodeURIComponent(config.auth.password)) || '';
|
||||
requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
|
||||
}
|
||||
|
||||
|
||||
+18
-1
@@ -76,7 +76,24 @@ setupBasicAuthTest = function setupBasicAuthTest() {
|
||||
}, 100);
|
||||
});
|
||||
|
||||
it('should fail to encode HTTP Basic auth credentials with non-Latin1 characters', function (done) {
|
||||
it('should accept HTTP Basic auth credentials with non-Latin1 characters in password', function (done) {
|
||||
axios('/foo', {
|
||||
auth: {
|
||||
username: 'Aladdin',
|
||||
password: 'open ßç£☃sesame'
|
||||
}
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
var request = jasmine.Ajax.requests.mostRecent();
|
||||
console.log(request.requestHeaders['Authorization'], '\n\n\n');
|
||||
|
||||
expect(request.requestHeaders['Authorization']).toEqual('Basic QWxhZGRpbjpvcGVuIMOfw6fCo+KYg3Nlc2FtZQ==');
|
||||
done();
|
||||
}, 100);
|
||||
});
|
||||
|
||||
it('should fail to encode HTTP Basic auth credentials with non-Latin1 characters in username', function (done) {
|
||||
axios('/foo', {
|
||||
auth: {
|
||||
username: 'Aladßç£☃din',
|
||||
|
||||
Reference in New Issue
Block a user