diff --git a/test/specs/basicAuth.spec.js b/test/specs/basicAuth.spec.js new file mode 100644 index 0000000..4816e43 --- /dev/null +++ b/test/specs/basicAuth.spec.js @@ -0,0 +1,87 @@ +var axios = require('../../index'); + +describe('options', function () { + beforeEach(function () { + jasmine.Ajax.install(); + }); + + afterEach(function () { + jasmine.Ajax.uninstall(); + }); + + it('should accept HTTP Basic auth with user/pass', function (done) { + var request; + + axios({ + url: '/foo', + auth: { + user: 'Aladdin', + pass: 'open sesame' + } + }); + + setTimeout(function () { + request = jasmine.Ajax.requests.mostRecent(); + + expect(request.requestHeaders['Authorization']).toEqual('Basic: QWxhZGRpbjpvcGVuIHNlc2FtZQ=='); + done(); + }, 0); + }); + + it('should accept HTTP Basic auth with username/pass', function (done) { + var request; + + axios({ + url: '/foo', + auth: { + username: 'Aladdin', + pass: 'open sesame' + } + }); + + setTimeout(function () { + request = jasmine.Ajax.requests.mostRecent(); + + expect(request.requestHeaders['Authorization']).toEqual('Basic: QWxhZGRpbjpvcGVuIHNlc2FtZQ=='); + done(); + }, 0); + }); + + it('should accept HTTP Basic auth with user/password', function (done) { + var request; + + axios({ + url: '/foo', + auth: { + user: 'Aladdin', + password: 'open sesame' + } + }); + + setTimeout(function () { + request = jasmine.Ajax.requests.mostRecent(); + + expect(request.requestHeaders['Authorization']).toEqual('Basic: QWxhZGRpbjpvcGVuIHNlc2FtZQ=='); + done(); + }, 0); + }); + + it('should accept HTTP Basic auth with username/password', function (done) { + var request; + + axios({ + url: '/foo', + auth: { + username: 'Aladdin', + password: 'open sesame' + } + }); + + setTimeout(function () { + request = jasmine.Ajax.requests.mostRecent(); + + expect(request.requestHeaders['Authorization']).toEqual('Basic: QWxhZGRpbjpvcGVuIHNlc2FtZQ=='); + done(); + }, 0); + }); +});