auth0-lock
Version:
Auth0 Lock
121 lines (118 loc) • 5.55 kB
JavaScript
;
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
var _immutable = _interopRequireDefault(require("immutable"));
var _actions = require("../../../connection/enterprise/actions");
var l = _interopRequireWildcard(require("../../../core/index"));
var _index2 = require("../../../field/index");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
jest.mock('connection/database/index', function () {
return {
databaseLogInWithEmail: jest.fn(function () {
return true;
}),
databaseUsernameValue: jest.fn()
};
});
jest.mock('store/index', function () {
return {
read: jest.fn(function () {
return 'model';
}),
getEntity: 'getEntity',
swap: jest.fn(),
updateEntity: 'updateEntity'
};
});
jest.mock('connection/enterprise', function () {
return {
matchConnection: jest.fn(),
enterpriseActiveFlowConnection: jest.fn(),
isHRDActive: jest.fn(),
isEnterpriseDomain: jest.fn()
};
});
jest.mock('core/actions', function () {
return {
logIn: jest.fn()
};
});
describe('Login with connection scopes', function () {
var lock;
beforeEach(function () {
lock = _immutable.default.fromJS({
id: '__lock__'
});
require('store/index').read.mockReturnValue(lock);
});
afterEach(function () {
jest.resetAllMocks();
});
describe('for an SSO connection', function () {
it('passes connectionScopes to the connection', function () {
lock = l.setup('__lock__', 'client', 'domain', {
auth: {
connectionScopes: {
'sso-connection': ['offline_access']
}
}
});
lock = (0, _index2.setField)(lock, 'email', 'test@test.com');
require('store/index').read.mockReturnValue(lock);
require('connection/enterprise').matchConnection.mockReturnValue(_immutable.default.fromJS({
name: 'sso-connection'
}));
var coreActions = require('core/actions');
(0, _actions.logIn)('__lock__');
expect(coreActions.logIn).toHaveBeenCalledWith('__lock__', ['email'], {
connection_scope: ['offline_access'],
connection: 'sso-connection',
login_hint: 'test@test.com'
});
});
it('should not throw an error if the captcha was not completed', function () {
lock = l.setup('__lock__', 'client', 'domain', {});
lock = (0, _index2.setField)(lock, 'email', 'test@test.com');
// This will be specified in the response from the /challenge endpoint if the
// dashboard settings have Captcha as 'required', regardless of connection being used.
lock = l.setCaptcha(lock, {
required: true,
provider: 'recaptcha_v2'
});
require('store/index').read.mockReturnValue(lock);
require('connection/enterprise').matchConnection.mockReturnValue(_immutable.default.fromJS({
name: 'sso-connection'
}));
var coreActions = require('core/actions');
(0, _actions.logIn)('__lock__');
expect(coreActions.logIn).toHaveBeenCalled();
});
});
describe('for a non-SSO connection', function () {
it('passes connectionScopes to the connection', function () {
lock = l.setup('__lock__', 'client', 'domain', {
auth: {
connectionScopes: {
'enterprise-connection': ['offline_access']
}
}
});
lock = (0, _index2.setField)(lock, 'password', 'test');
lock = (0, _index2.setField)(lock, 'username', 'test');
require('store/index').read.mockReturnValue(lock);
require('connection/enterprise').enterpriseActiveFlowConnection.mockReturnValue(_immutable.default.fromJS({
name: 'enterprise-connection'
}));
var coreActions = require('core/actions');
(0, _actions.logIn)('__lock__');
expect(coreActions.logIn).toHaveBeenCalledWith('__lock__', ['password', 'username'], {
connection_scope: ['offline_access'],
connection: 'enterprise-connection',
username: 'test',
password: 'test',
login_hint: 'test'
}, expect.any(Function));
});
});
});