/** * Config mocha */ mocha.timeout(60000); mocha.globals(['jQuery*', '__auth0jp*']); /** * XHR support variables */ var xhrSupport = !(new Auth0({clientID: 'clientID', domain: 'domain'}))._useJSONP; var xhrSupportPrefix = xhrSupport ? '' : 'not '; /** * Test User and Password */ describe('Auth0 - User And Passwords', function () { var auth0 = new Auth0({ domain: 'mdocs.auth0.com', callbackURL: 'http://localhost:3000/', clientID: 'ptR6URmXef0OfBDHK0aCIy7iPKpdCG4t' }); describe('Login', function () { describe('with resource owner', function () { it('should call the callback when user/pass is wrong', function (done) { auth0.login({ connection: 'tests', username: 'testttt@wrong.com', password: '12345', sso: false }, function (err, profile) { expect(err.status).to.equal(401); expect(err.details.code).to.equal('invalid_user_password'); expect(profile).not.to.be.ok(); done(); }); }); // Fails on IE8. Some bug with errors on XMLHttpRequest handling // XXX: Fix it! it.skip('should call the callback with err when the connection doesn\'t exists', function (done) { auth0.login({ connection: 'testsw3eeasdsadsa', username: 'testttt@wrong.com', password: '12345', sso: false }, function (err, result) { expect(err.status).to.equal(400); expect(err.message).to.equal('invalid_connection'); expect(result).not.to.be.ok(); done(); }); }); it('should return the authentication result after successfull authentication', function (done) { auth0.login({ connection: 'tests', username: 'johnfoo@gmail.com', password: '12345', sso: false }, function (err, result) { // expect(profile.name).to.eql('John Foo'); // expect(profile.foo).to.eql('bar'); // expect(profile.identities.length).to.eql(1); expect(result.idToken).to.exist; expect(result.accessToken).to.exist; done(); }); }); it('should return refresh_token after successfull authentication with offline_mode', function (done) { auth0.login({ connection: 'tests', username: 'johnfoo+1@gmail.com', password: '12345', offline_mode: true, sso: false }, function (err, result) { // expect(profile.name).to.eql('John Foo'); // expect(profile.foo).to.eql('bar'); // expect(profile.identities.length).to.eql(1); expect(result.idToken).to.exist; expect(result.refreshToken).to.exist; expect(result.accessToken).to.exist; done(); }); }); it('should trim username before login', function (done) { auth0.login({ connection: 'tests', username: ' johnfoo+2@gmail.com ', password: '12345', sso: false }, function (err, result) { // expect(profile.name).to.eql('John Foo'); // expect(profile.foo).to.eql('bar'); // expect(profile.identities.length).to.eql(1); expect(result.idToken).to.exist; expect(result.accessToken).to.exist; done(); }); }); }); describe('with wsfed', function () { it('should call the callback when user/pass is wrong', function (done) { auth0.login({ connection: 'tests', username: 'testttt@wrong.com', password: '12345', nonce: '1234' }, function (err) { expect(err.status).to.equal(401); expect(err.details.code).to.equal('invalid_user_password'); done(); }); }); it('should call the callback with err when the connection doesn\'t exists', function (done) { auth0.login({ connection: 'testsw3eeasdsadsa', username: 'testtttt@wrong.com', password: '12345', nonce: '12345' }, function (err) { expect(err.status).to.equal(404); expect(err.message).to.match(/connection not found/ig); done(); }); }); it('should render wsfed form after successfull authentication', function (done) { auth0._renderAndSubmitWSFedForm = function (options, htmlForm) { expect(htmlForm).to.match(/