mirror of
https://github.com/tenrok/axios.git
synced 2026-06-23 20:40:40 +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
|
// HTTP basic authentication
|
||||||
if (config.auth) {
|
if (config.auth) {
|
||||||
var username = config.auth.username || '';
|
var username = config.auth.username || '';
|
||||||
var password = config.auth.password || '';
|
var password = unescape(encodeURIComponent(config.auth.password)) || '';
|
||||||
requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
|
requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+18
-1
@@ -76,7 +76,24 @@ setupBasicAuthTest = function setupBasicAuthTest() {
|
|||||||
}, 100);
|
}, 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', {
|
axios('/foo', {
|
||||||
auth: {
|
auth: {
|
||||||
username: 'Aladßç£☃din',
|
username: 'Aladßç£☃din',
|
||||||
|
|||||||
Reference in New Issue
Block a user