2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-30 15:24:11 +03:00

Better tests for btoa

This commit is contained in:
Matt Zabriskie
2015-12-14 12:16:57 -07:00
parent 77b8966b47
commit 9ede644b98
4 changed files with 82 additions and 81 deletions
+10 -41
View File
@@ -1,52 +1,21 @@
var axios = require('../../index');
var setupBasicAuthTest = require('./__setupBasicAuthTest');
var window_btoa;
describe('basicAuth with btoa polyfill', function () {
beforeAll(function() {
this.original_btoa = window.btoa;
window_btoa = window.btoa;
window.btoa = undefined;
})
});
afterAll(function() {
window.btoa = this.original_btoa;
})
beforeEach(function () {
jasmine.Ajax.install();
window.btoa = window_btoa;
window_btoa = undefined;
});
afterEach(function () {
jasmine.Ajax.uninstall();
it('should not have native window.btoa', function () {
expect(window.btoa).toEqual(undefined);
});
it('should accept HTTP Basic auth with username/password', function (done) {
axios({
url: '/foo',
auth: {
username: 'Aladdin',
password: 'open sesame'
}
});
setTimeout(function () {
var request = jasmine.Ajax.requests.mostRecent();
expect(request.requestHeaders['Authorization']).toEqual('Basic: QWxhZGRpbjpvcGVuIHNlc2FtZQ==');
done();
}, 0);
});
it('should fail to encode HTTP Basic auth credentials with non-Latin1 characters', function (done) {
axios({
url: '/foo',
auth: {
username: 'Aladßç£☃din',
password: 'open sesame'
}
}).then(function(response) {
done(new Error('Should not succeed to make a HTTP Basic auth request with non-latin1 chars in credentials.'))
}).catch(function(error) {
expect(error.message).toEqual('\'btoa\' failed: The string to be encoded contains characters outside of the Latin1 range.')
done()
});
});
setupBasicAuthTest();
});