UNPKG

dl

Version:

DreamLab Libs

781 lines (756 loc) 37.6 kB
var UidManager = require('../../lib/uid/UidManager.js').UidManager, UidProfile = require('../../lib/uid/UidProfile.js').UidProfile, Request = require('core').http.Request, Response = require('core').http.Response, Event = require('core').event.Event, ErrorEvent = require('core').event.ErrorEvent, Loader = require('core').http.Loader, BinaryData = require('core').data.BinaryData, JsonRpcResponse = require('core').jsonrpc.JsonRpcResponse, OpalLoader = require('../../lib/opal/OpalLoader.js').OpalLoader, OpalResponse = require('../../lib/opal/OpalResponse.js').OpalResponse; describe('UidManager', function () { describe('getProfile', function () { it('should throw new Error(UidManager.Exception.UNAUTHORIZED) and redirect', function () { var request = new Request({ url: 'http://test.onet/' }), response = new Response(), instance = new UidManager(request, response), callback = jasmine.createSpy('callback'); expect(function () { instance.getProfile('http://test.onet/auth.html?param1=1&param2=2', 'test', callback); }).toThrow(new Error(UidManager.Exception.UNAUTHORIZED)); expect(response.getStatusCode()).toEqual(302); expect(response.getHeader('location').indexOf(UidManager.AUTHORIZATION_ENDPOINT)).toEqual(0); expect(response.getHeader('location')).toMatch(/[?&]response_type=code([&#]|$)/); expect(response.getHeader('location')).toMatch(/[?&]client_id=test\.onet([&#]|$)/); expect(response.getHeader('location')).toMatch( /[?&]redirect_uri=http%3A%2F%2Ftest\.onet%2Fauth.html%3Fparam1%3D1%26param2%3D2([&#]|$)/ ); expect(response.getHeader('location')).toMatch(/[?&]state=test([&#]|$)/); expect(response.getHeader('last-modified')).toEqual(new Date().toUTCString()); expect(new Date(response.getHeader('expires'))).toBeLessThan(new Date()); expect(response.getHeader('cache-control')).toEqual([ 'no-store, no-cache, must-revalidate', 'post-check=0, pre-check=0' ]); expect(response.getHeader('pragma')).toEqual('no-cache'); expect(response.getHeader('x-onet-squid')).toBeNull(); }); it('should throw new Error(UidManager.Exception.UNAUTHORIZED) and not redirect', function () { var request = new Request({ url: 'http://test.onet/' }), response = new Response(), instance = new UidManager(request, response), callback = jasmine.createSpy('callback'); expect(function () { instance.getProfile(callback); }).toThrow(new Error(UidManager.Exception.UNAUTHORIZED)); expect(response.getStatusCode()).not.toEqual(302); expect(response.getHeader('location')).toBeNull(); }); it('should throw new URIError(UidManager.Exception.INVALID_URL)', function () { var request = new Request({ url: 'http://test.onet/', headers: { cookie: 'onet_uid=test' } }), response = new Response(), instance = new UidManager(request, response), callback = jasmine.createSpy('callback'); expect(function () { instance.getProfile('http://example.com/', callback); }).toThrow(new URIError(UidManager.Exception.INVALID_URL)); }); it('should return UidProfile instance', function () { var request = new Request({ url: 'http://test.onet/', headers: { cookie: 'onet_uid=test' } }), response = new Response(), instance = new UidManager(request, response), callback = jasmine.createSpy('callback'); spyOn(OpalLoader.prototype, 'load').andCallFake(function () { var body = JSON.parse(this._request.getBody().toString()); expect(this._request.getConnectionHost()).toEqual(UidManager.TOKEN_ENDPOINT); expect(this._request.getUrl()).toEqual('http://' + UidManager.TOKEN_ENDPOINT + '/'); expect(this._request.getHeader('authorization')).toEqual('Bearer test'); expect(body.method).toEqual('get_profile'); expect(body.params.portal_id).toEqual('ONET'); expect(body.params.client_id).toEqual('test.onet'); process.nextTick(function () { this.dispatchEvent(new Event(OpalLoader.Event.JSON_RESPONSE, new OpalResponse({ body: new JsonRpcResponse({ id: 'test', result: { usr_uuid: '00000000-0000-0000-0000-000000000000', usr_email: 'test@example.com' } }) }))); }.bind(this)); }); expect(instance.getProfile('http://test.onet/', callback)).toBe(instance); waitsFor(function () { return callback.callCount > 0; }); runs(function () { expect(OpalLoader.prototype.load).toHaveBeenCalled(); expect(callback).toHaveBeenCalledWith(null, new UidProfile({ usr_uuid: '00000000-0000-0000-0000-000000000000', usr_email: 'test@example.com' })); callback = jasmine.createSpy('callback'); instance.getProfile('http://test.onet/', callback); expect(OpalLoader.prototype.load.callCount).toEqual(1); expect(callback).toHaveBeenCalledWith(null, new UidProfile({ usr_uuid: '00000000-0000-0000-0000-000000000000', usr_email: 'test@example.com' })); }); }); it('should return UidProfile instance created from HTTP response', function () { var request = new Request({ url: 'http://test.onet/', headers: { cookie: 'onet_uid=test' } }), response = new Response(), instance = new UidManager(request, response), callback = jasmine.createSpy('callback'), opalConnectionHost = UidManager.OPAL_CONNECTION_HOST; UidManager.OPAL_CONNECTION_HOST = 'test.onet'; spyOn(OpalLoader.prototype, 'load').andCallFake(function () { expect(this._request.getConnectionHost()).toEqual('test.onet'); process.nextTick(function () { this.dispatchEvent(new Event(OpalLoader.Event.HTTP_RESPONSE, new OpalResponse({ body: new Response({ body: new BinaryData(JSON.stringify({ id: 'test', result: { usr_uuid: '00000000-0000-0000-0000-000000000000', usr_email: 'test@example.com' } }), BinaryData.Encoding.TEXT, BinaryData.CharacterEncoding.UTF8) }) }))); }.bind(this)); }); expect(instance.getProfile('http://test.onet/', callback)).toBe(instance); waitsFor(function () { return callback.callCount > 0; }); runs(function () { expect(OpalLoader.prototype.load).toHaveBeenCalled(); expect(callback).toHaveBeenCalledWith(null, new UidProfile({ usr_uuid: '00000000-0000-0000-0000-000000000000', usr_email: 'test@example.com' })); UidManager.OPAL_CONNECTION_HOST = opalConnectionHost; }); }); it('should return error', function () { var request = new Request({ url: 'http://test.onet/', headers: { cookie: 'onet_uid=test' } }), response = new Response(), instance = new UidManager(request, response), callback = jasmine.createSpy('callback').andCallFake(function (err) { expect(err.type).toEqual(Loader.Event.ERROR); expect(err.code).toEqual(-1); expect(err.message).toEqual('Test'); expect(err.data).toEqual({}); }); spyOn(OpalLoader.prototype, 'load').andCallFake(function () { var body = JSON.parse(this._request.getBody().toString()); expect(body.params.portal_id).toEqual('TEST'); expect(body.params.client_id).toEqual('test'); process.nextTick(function () { this.dispatchEvent(new Event(OpalLoader.Event.JSON_RESPONSE, new OpalResponse({ body: new JsonRpcResponse({ id: 'test', error: { code: -1, message: 'Test', data: {} } }) }))); }.bind(this)); }); expect(instance.setPortalId('TEST')).toBe(instance); expect(instance.setClientId('test')).toBe(instance); instance.getProfile('http://test.onet/', callback); waitsFor(function () { return callback.callCount > 0; }); runs(function () { expect(callback).toHaveBeenCalledWith(jasmine.any(ErrorEvent)); expect(response.getHeader('location')).toBeNull(); }); }); it('should return error created from HTTP response', function () { var request = new Request({ url: 'http://test.onet/', headers: { cookie: 'onet_uid=test' } }), response = new Response(), instance = new UidManager(request, response), callback = jasmine.createSpy('callback').andCallFake(function (err) { expect(err.type).toEqual(Loader.Event.ERROR); expect(err.code).toEqual(-1); expect(err.message).toEqual('Test'); });; spyOn(OpalLoader.prototype, 'load').andCallFake(function () { process.nextTick(function () { this.dispatchEvent(new Event(OpalLoader.Event.HTTP_RESPONSE, new OpalResponse({ body: new Response({ body: new BinaryData(JSON.stringify({ id: 'test', error: { code: -1, message: 'Test' } }), BinaryData.Encoding.TEXT, BinaryData.CharacterEncoding.UTF8) }) }))); }.bind(this)); }); expect(instance.getProfile('http://test.onet/', callback)).toBe(instance); waitsFor(function () { return callback.callCount > 0; }); runs(function () { expect(callback).toHaveBeenCalledWith(jasmine.any(ErrorEvent)); expect(response.getHeader('location')).toBeNull(); }); }); it('should return error created from HTTP response containing invalid JSON', function () { var request = new Request({ url: 'http://test.onet/', headers: { cookie: 'onet_uid=test' } }), response = new Response(), instance = new UidManager(request, response), callback = jasmine.createSpy('callback').andCallFake(function (err) { expect(err.type).toEqual(Loader.Event.ERROR); expect(err.code).toEqual(-4); expect(err.message).toEqual('JSON parse error'); expect(err.data.json).toEqual('{'); expect(err.data.error).toEqual(jasmine.any(String)); });; spyOn(OpalLoader.prototype, 'load').andCallFake(function () { process.nextTick(function () { this.dispatchEvent(new Event(OpalLoader.Event.HTTP_RESPONSE, new OpalResponse({ body: new Response({ body: new BinaryData('{', BinaryData.Encoding.TEXT, BinaryData.CharacterEncoding.UTF8) }) }))); }.bind(this)); }); expect(instance.getProfile('http://test.onet/', callback)).toBe(instance); waitsFor(function () { return callback.callCount > 0; }); runs(function () { expect(callback).toHaveBeenCalledWith(jasmine.any(ErrorEvent)); expect(response.getHeader('location')).toBeNull(); }); }); it('should return error, remove cookie and redirect', function () { var request = new Request({ url: 'http://test.onet/', headers: { cookie: 'onet_test=test' } }), response = new Response(), instance = new UidManager(request, response, { name: 'onet_test', path: '/test/', domain: 'onet.pl', secure: true, httponly: false }), callback = jasmine.createSpy('callback'); spyOn(OpalLoader.prototype, 'load').andCallFake(function () { process.nextTick(function () { this.dispatchEvent(new Event(OpalLoader.Event.JSON_RESPONSE, new OpalResponse({ body: new JsonRpcResponse({ id: 'test', error: { code: UidManager.Error.INVALID_TOKEN, message: 'Test' } }) }))); }.bind(this)); }); instance.getProfile('//test.onet/auth.html?param1=1&param2=2', '/?&=#', callback); waitsFor(function () { return callback.callCount > 0; }); runs(function () { expect(callback).toHaveBeenCalledWith(jasmine.any(ErrorEvent)); expect(response.getStatusCode()).toEqual(302); expect(response.getHeader('location').indexOf(UidManager.AUTHORIZATION_ENDPOINT)).toEqual(0); expect(response.getHeader('location')).toMatch( /[?&]redirect_uri=http%3A%2F%2Ftest\.onet%2Fauth.html%3Fparam1%3D1%26param2%3D2([&#]|$)/ ); expect(response.getHeader('location')).toMatch(/[?&]state=%2F%3F%26%3D%23([&#]|$)/ ); expect(response.getHeader('p3p')).toEqual( 'CP="ALL DSP COR IVD IVA PSD PSA TEL TAI CUS ADM CUR CON SAM OUR IND"' ); expect(response.getHeader('set-cookie')).toMatch( /^onet_test=; expires=[^;]+; path=\/test\/; domain=onet\.pl; secure$/ ); expect(new Date(response.getHeader('set-cookie').match(/ expires=([^;]+)/)[0])).toBeLessThan( new Date() ); }); }); it('should return error and not redirect', function () { var request = new Request({ url: 'http://test.onet/', headers: { cookie: 'onet_test=test' } }), response = new Response(), instance = new UidManager(request, response, { name: 'onet_test', path: '/test/', domain: 'onet.pl', secure: true, httponly: false }), callback = jasmine.createSpy('callback'); spyOn(OpalLoader.prototype, 'load').andCallFake(function () { process.nextTick(function () { this.dispatchEvent(new Event(OpalLoader.Event.JSON_RESPONSE, new OpalResponse({ body: new JsonRpcResponse({ id: 'test', error: { code: UidManager.Error.INVALID_TOKEN, message: 'Test' } }) }))); }.bind(this)); }); instance.getProfile(callback); waitsFor(function () { return callback.callCount > 0; }); runs(function () { expect(callback).toHaveBeenCalledWith(jasmine.any(ErrorEvent)); expect(response.getStatusCode()).not.toEqual(302); expect(response.getHeader('location')).toBeNull(); }); }); }); describe('oauthExchangeToken', function () { it('should throw new ReferenceError(UidManager.Exception.INVALID_ACCESS_TOKEN_REQUEST)', function () { var request = new Request({ url: 'http://test.onet/' }), response = new Response(), instance = new UidManager(request, response), callback = jasmine.createSpy('callback'); expect(function () { instance.oauthExchangeToken(callback); }).toThrow(new ReferenceError(UidManager.Exception.INVALID_ACCESS_TOKEN_REQUEST)); expect(response.getHeader('last-modified')).toEqual(new Date().toUTCString()); expect(new Date(response.getHeader('expires'))).toBeLessThan(new Date()); expect(response.getHeader('cache-control')).toEqual([ 'no-store, no-cache, must-revalidate', 'post-check=0, pre-check=0' ]); expect(response.getHeader('pragma')).toEqual('no-cache'); expect(response.getHeader('x-onet-squid')).toBeNull(); }); it('should set cookie', function () { var request = new Request({ url: 'http://test.onet/?code=code' }), response = new Response(), instance = new UidManager(request, response), callback = jasmine.createSpy('callback'); spyOn(OpalLoader.prototype, 'load').andCallFake(function () { var body = JSON.parse(this._request.getBody().toString()); expect(this._request.getUrl()).toEqual('http://' + UidManager.TOKEN_ENDPOINT + '/'); expect(body.method).toEqual('oauth_exchange_token'); expect(body.params.portal_id).toEqual('ONET'); expect(body.params.client_id).toEqual('test.onet'); expect(body.params.grant_type).toEqual('authorization_code'); expect(body.params.code).toEqual('code'); process.nextTick(function () { this.dispatchEvent(new Event(OpalLoader.Event.JSON_RESPONSE, new OpalResponse({ body: new JsonRpcResponse({ id: 'test', result: { access_token: 'test', expires_in: 3600 } }) }))); }.bind(this)); }); expect(instance.oauthExchangeToken(callback)).toBe(instance); waitsFor(function () { return callback.callCount > 0; }); runs(function () { expect(OpalLoader.prototype.load).toHaveBeenCalled(); expect(callback).toHaveBeenCalledWith(null, { access_token: 'test', expires_in: 3600 }); expect(response.getHeader('p3p')).toEqual( 'CP="ALL DSP COR IVD IVA PSD PSA TEL TAI CUS ADM CUR CON SAM OUR IND"' ); expect(response.getHeader('set-cookie')).toMatch( /^onet_uid=test; expires=[^;]+; path=\/; domain=test\.onet; httponly$/ ); expect(new Date(response.getHeader('set-cookie').match(/ expires=([^;]+)/)[0])).toBeGreaterThan( new Date() ); }); }); it('should return error', function () { var request = new Request({ url: 'http://test.onet/?code=code' }), response = new Response(), instance = new UidManager(request, response), callback = jasmine.createSpy('callback').andCallFake(function (err) { expect(err.type).toEqual(Loader.Event.ERROR); expect(err.code).toEqual(-1); expect(err.message).toEqual('Test'); expect(err.data).toEqual({}); }); spyOn(OpalLoader.prototype, 'load').andCallFake(function () { var body = JSON.parse(this._request.getBody().toString()); expect(body.params.portal_id).toEqual('TEST'); expect(body.params.client_id).toEqual('test'); process.nextTick(function () { this.dispatchEvent(new Event(OpalLoader.Event.JSON_RESPONSE, new OpalResponse({ body: new JsonRpcResponse({ id: 'test', error: { code: -1, message: 'Test', data: {} } }) }))); }.bind(this)); }); expect(instance.setPortalId('TEST')).toBe(instance); expect(instance.setClientId('test')).toBe(instance); instance.oauthExchangeToken(callback); waitsFor(function () { return callback.callCount > 0; }); runs(function () { expect(callback).toHaveBeenCalledWith(jasmine.any(ErrorEvent)); expect(response.getHeader('set-cookie')).toBeNull(); }); }); }); describe('logout', function () { it('should throw new Error(UidManager.Exception.UNAUTHORIZED)', function () { var request = new Request({ url: 'http://test.onet/' }), response = new Response(), instance = new UidManager(request, response), callback = jasmine.createSpy('callback'); expect(function () { instance.logout(callback); }).toThrow(new Error(UidManager.Exception.UNAUTHORIZED)); expect(response.getHeader('last-modified')).toEqual(new Date().toUTCString()); expect(new Date(response.getHeader('expires'))).toBeLessThan(new Date()); expect(response.getHeader('cache-control')).toEqual([ 'no-store, no-cache, must-revalidate', 'post-check=0, pre-check=0' ]); expect(response.getHeader('pragma')).toEqual('no-cache'); expect(response.getHeader('x-onet-squid')).toBeNull(); }); it('should remove cookie', function () { var request = new Request({ url: 'http://test.onet/', headers: { cookie: 'onet_uid=test' } }), response = new Response(), instance = new UidManager(request, response), callback = jasmine.createSpy('callback'); spyOn(OpalLoader.prototype, 'load').andCallFake(function () { var body = JSON.parse(this._request.getBody().toString()); expect(this._request.getUrl()).toEqual('http://' + UidManager.TOKEN_ENDPOINT + '/'); expect(this._request.getHeader('authorization')).toEqual('Bearer test'); expect(body.method).toEqual('logout'); expect(body.params.portal_id).toEqual('ONET'); expect(body.params.client_id).toEqual('test.onet'); process.nextTick(function () { this.dispatchEvent(new Event(OpalLoader.Event.JSON_RESPONSE, new OpalResponse({ body: new JsonRpcResponse({ id: 'test', result: {} }) }))); }.bind(this)); }); expect(instance.logout(callback)).toBe(instance); waitsFor(function () { return callback.callCount > 0; }); runs(function () { expect(OpalLoader.prototype.load).toHaveBeenCalled(); expect(callback).toHaveBeenCalledWith(null, {}); expect(response.getHeader('p3p')).toEqual( 'CP="ALL DSP COR IVD IVA PSD PSA TEL TAI CUS ADM CUR CON SAM OUR IND"' ); expect(response.getHeader('set-cookie')).toMatch( /^onet_uid=; expires=[^;]+; path=\/; domain=test\.onet; httponly$/ ); expect(new Date(response.getHeader('set-cookie').match(/ expires=([^;]+)/)[0])).toBeLessThan( new Date() ); }); }); it('should return error', function () { var request = new Request({ url: 'http://test.onet/', headers: { cookie: 'onet_uid=test' } }), response = new Response(), instance = new UidManager(request, response), callback = jasmine.createSpy('callback').andCallFake(function (err) { expect(err.type).toEqual(Loader.Event.ERROR); expect(err.code).toEqual(-1); expect(err.message).toEqual('Test'); expect(err.data).toEqual({}); }); spyOn(OpalLoader.prototype, 'load').andCallFake(function () { var body = JSON.parse(this._request.getBody().toString()); expect(body.params.portal_id).toEqual('TEST'); expect(body.params.client_id).toEqual('test'); process.nextTick(function () { this.dispatchEvent(new Event(OpalLoader.Event.JSON_RESPONSE, new OpalResponse({ body: new JsonRpcResponse({ id: 'test', error: { code: -1, message: 'Test', data: {} } }) }))); }.bind(this)); }); expect(instance.setPortalId('TEST')).toBe(instance); expect(instance.setClientId('test')).toBe(instance); instance.logout(callback); waitsFor(function () { return callback.callCount > 0; }); runs(function () { expect(callback).toHaveBeenCalledWith(jasmine.any(ErrorEvent)); expect(response.getHeader('set-cookie')).toBeNull(); }); }); }); describe('identifyByEmail', function () { it('should throw new Error(UidManager.Exception.INVALID_EMAIL)', function () { var request = new Request({ url: 'http://test.onet/' }), response = new Response(), instance = new UidManager(request, response), callback = jasmine.createSpy('callback'); expect(function () { instance.identifyByEmail('test', 'http://test.onet/auth.html?param1=1&param2=2', callback); }).toThrow(new Error(UidManager.Exception.INVALID_EMAIL)); }); it('should throw new URIError(UidManager.Exception.INVALID_URL)', function () { var request = new Request({ url: 'http://test.onet/' }), response = new Response(), instance = new UidManager(request, response), callback = jasmine.createSpy('callback'); expect(function () { instance.identifyByEmail('test@example.com', 'http://example.com/', callback); }).toThrow(new URIError(UidManager.Exception.INVALID_URL)); }); it('should call API', function () { var request = new Request({ url: 'http://test.onet/' }), response = new Response(), instance = new UidManager(request, response), callback = jasmine.createSpy('callback'); spyOn(OpalLoader.prototype, 'load').andCallFake(function () { var body = JSON.parse(this._request.getBody().toString()); expect(this._request.getUrl()).toEqual('http://' + UidManager.TOKEN_ENDPOINT + '/'); expect(body.method).toEqual('identify_by_email'); expect(body.params.portal_id).toEqual('ONET'); expect(body.params.client_id).toEqual('test.onet'); expect(body.params.email).toEqual('test@example.com'); expect(body.params.redirect_uri).toEqual('http://test.onet/auth.html?param1=1&param2=2'); process.nextTick(function () { this.dispatchEvent(new Event(OpalLoader.Event.JSON_RESPONSE, new OpalResponse({ body: new JsonRpcResponse({ id: 'test', result: {} }) }))); }.bind(this)); }); expect(instance.identifyByEmail('test@example.com', '/auth.html?param1=1&param2=2', callback)).toBe( instance ); waitsFor(function () { return callback.callCount > 0; }); runs(function () { expect(OpalLoader.prototype.load).toHaveBeenCalled(); expect(callback).toHaveBeenCalledWith(null, {}); }); }); it('should return error', function () { var request = new Request({ url: 'http://test.onet/' }), response = new Response(), instance = new UidManager(request, response), callback = jasmine.createSpy('callback').andCallFake(function (err) { expect(err.type).toEqual(Loader.Event.ERROR); expect(err.code).toEqual(-1); expect(err.message).toEqual('Test'); expect(err.data).toEqual({}); }); spyOn(OpalLoader.prototype, 'load').andCallFake(function () { var body = JSON.parse(this._request.getBody().toString()); expect(body.params.portal_id).toEqual('TEST'); expect(body.params.client_id).toEqual('test'); process.nextTick(function () { this.dispatchEvent(new Event(OpalLoader.Event.JSON_RESPONSE, new OpalResponse({ body: new JsonRpcResponse({ id: 'test', error: { code: -1, message: 'Test', data: {} } }) }))); }.bind(this)); }); expect(instance.setPortalId('TEST')).toBe(instance); expect(instance.setClientId('test')).toBe(instance); instance.identifyByEmail('test@example.com', '/auth.html?param1=1&param2=2', callback); waitsFor(function () { return callback.callCount > 0; }); runs(function () { expect(callback).toHaveBeenCalledWith(jasmine.any(ErrorEvent)); }); }); }); describe('getFacebookLoginURL', function () { it('should throw new URIError(UidManager.Exception.INVALID_URL)', function () { var request = new Request({ url: 'http://test.onet/' }), response = new Response(), instance = new UidManager(request, response); expect(function () { instance.getFacebookLoginURL('http://example.com/'); }).toThrow(new URIError(UidManager.Exception.INVALID_URL)); }); it('should return URL', function () { var request = new Request({ url: 'http://test.onet/test.html?arg1=1&arg2=2' }), response = new Response(), instance = new UidManager(request, response), url = instance.getFacebookLoginURL('?param1=1&param2=2'), escapeRegExp = function (text) { return text.replace(/[\^$*+?.()|{}[\]]/g, '\\$&'); }; expect(url.indexOf(UidManager.FACEBOOK_AUTHORIZATION_ENDPOINT)).toEqual(0); expect(url).toMatch(new RegExp( '[?&]client_id=' + escapeRegExp(UidManager.FACEBOOK_CLIENT_ID) + '([&#]|$)' )); expect(url).toMatch(new RegExp( '[?&]redirect_uri=' + escapeRegExp(encodeURIComponent(UidManager.FACEBOOK_REDIRECT_URI)) + '[^&#]*([&#]|$)' )); expect(url).toMatch(/(%3F|%26)client_id%3Dtest\.onet(%26|[&#]|$)/); expect(url).toMatch(/(%3F|%26)response_type%3Dcode(%26|[&#]|$)/); expect(url).toMatch( /(%3F|%26)redirect_uri%3Dhttp%253A%252F%252Ftest\.onet%252Ftest\.html%253Fparam1%253D1%2526param2%253D2(%26|[&#]|$)/ ); expect(url).toMatch(/[?&]scope=email([&#]|$)/); expect(url).toMatch(/[?&]response_type=code([&#]|$)/); expect(url).toMatch(/[?&]auth_type=rerequest([&#]|$)/); }); it('should return popup URL with state', function() { var request = new Request({ url: 'http://test.onet/test.html?arg1=1&arg2=2' }), response = new Response(), instance = new UidManager(request, response), url = instance.getFacebookLoginURL('#test', '/?&=#', {display: 'popup'}); expect(url).toMatch( /(%3F|%26)redirect_uri%3Dhttp%253A%252F%252Ftest\.onet%252Ftest\.html%253Farg1%253D1%2526arg2%253D2%2523test(%26|[&#]|$)/ ); expect(url).toMatch(/(%3F|%26)state%3D%252F%253F%2526%253D%2523(%26|[&#]|$)/); expect(url).toMatch(/[?&]display=popup([&#]|$)/); expect(url).toMatch(/[?&]auth_type=rerequest([&#]|$)/); }); it('should return URL with auth_type based on relative path', function() { var request = new Request({ url: 'http://test.onet/dir/test.html?arg1=1&arg2=2' }), response = new Response(), instance = new UidManager(request, response), url = instance.getFacebookLoginURL('auth.html?param1=1&param2=2#test', null, {auth_type: 'rerequest'}); expect(url).toMatch( /(%3F|%26)redirect_uri%3Dhttp%253A%252F%252Ftest\.onet%252Fdir%252Fauth\.html%253Fparam1%253D1%2526param2%253D2%2523test(%26|[&#]|$)/ ); expect(url).toMatch(/[?&]auth_type=rerequest([&#]|$)/); }); it('should return URL with auth_type list', function () { var request = new Request({ url: 'http://test.onet/test.html?arg1=1&arg2=2' }), response = new Response(), instance = new UidManager(request, response), url = instance.getFacebookLoginURL('#test', '/?&=#', {auth_type: 'reauthenticate'}); expect(url).toMatch(/[?&]auth_type=(reauthenticate%2Crerequest|rerequest%2Creauthenticate)([&#]|$)/); }); }); });