2
0
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:
Petr Mares
2020-05-27 00:32:03 +08:00
committed by GitHub
parent a98755c00a
commit 5effc0827e
2 changed files with 19 additions and 2 deletions
+1 -1
View File
@@ -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
View File
@@ -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',