auth0-lock
Version:
Auth0 Lock
67 lines (63 loc) • 2.26 kB
JavaScript
;
var _immutable = _interopRequireDefault(require("immutable"));
var _enterprise = require("../../../connection/enterprise");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
jest.mock('core/index', function () {
return {
connections: jest.fn()
};
});
describe('matchConnection', function () {
afterEach(function () {
return jest.resetAllMocks();
});
it('does not throw when enterprise connection has no domains field (key absent)', function () {
var _require = require('core/index'),
connections = _require.connections;
// Tenant omits the domains field entirely
connections.mockReturnValue(_immutable.default.fromJS([{
name: 'samlp-connection',
strategy: 'samlp',
type: 'enterprise'
}]));
var m = _immutable.default.fromJS({
id: '__lock__'
});
expect(function () {
return (0, _enterprise.matchConnection)(m, 'test@example.com');
}).not.toThrow();
expect((0, _enterprise.matchConnection)(m, 'test@example.com')).toBeFalsy();
});
it('does not throw when enterprise connection has domains explicitly set to null', function () {
var _require2 = require('core/index'),
connections = _require2.connections;
// Tenant returns domains: null
connections.mockReturnValue(_immutable.default.fromJS([{
name: 'samlp-connection',
strategy: 'samlp',
type: 'enterprise',
domains: null
}]));
var m = _immutable.default.fromJS({
id: '__lock__'
});
expect(function () {
return (0, _enterprise.matchConnection)(m, 'test@example.com');
}).not.toThrow();
expect((0, _enterprise.matchConnection)(m, 'test@example.com')).toBeFalsy();
});
it('matches a connection when the email domain is in the domains list', function () {
var _require3 = require('core/index'),
connections = _require3.connections;
connections.mockReturnValue(_immutable.default.fromJS([{
name: 'samlp-connection',
strategy: 'samlp',
type: 'enterprise',
domains: ['example.com']
}]));
var m = _immutable.default.fromJS({
id: '__lock__'
});
expect((0, _enterprise.matchConnection)(m, 'user@example.com')).toBeTruthy();
});
});