neo4j-client-sso
Version:
Single sign-on client (frontend) library for Neo4j products
127 lines (126 loc) • 5.75 kB
JavaScript
"use strict";
/*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const common_1 = require("./common");
const __mocks__1 = require("./__mocks__");
describe('getInitialisationParameters', () => {
describe('With URL pathname', () => {
test('no search or hash params present', () => {
const windowLocationHref = 'http://localhost/app/static/';
window.history.replaceState({}, '', windowLocationHref);
expect(window.location.href).toEqual(windowLocationHref);
const result = (0, common_1.getInitialisationParameters)();
expect(result).toEqual({});
});
test('several search params present', () => {
const windowLocationHref = 'http://localhost/app/static/?search_param=w&tea=2234sdfj&cup=5%73bsod?892()';
window.history.replaceState({}, '', windowLocationHref);
expect(window.location.href).toEqual(windowLocationHref);
const result = (0, common_1.getInitialisationParameters)();
expect(result).toEqual({
search_param: 'w',
tea: '2234sdfj',
cup: '5sbsod?892()'
});
});
test('several hash params present', () => {
const windowLocationHref = 'http://localhost/app/static/#box=/%#/=Q4535&state_test=ljhf873';
window.history.replaceState({}, '', windowLocationHref);
expect(window.location.href).toEqual(windowLocationHref);
const result = (0, common_1.getInitialisationParameters)();
expect(result).toEqual({
box: '/%#/=Q4535',
state_test: 'ljhf873'
});
});
test('only simple search and hash params present', () => {
const windowLocationHref = 'http://localhost/app/static/?search_param=w#hash_param=45';
window.history.replaceState({}, '', windowLocationHref);
expect(window.location.href).toEqual(windowLocationHref);
const result = (0, common_1.getInitialisationParameters)();
expect(result).toEqual({
search_param: 'w',
hash_param: '45'
});
});
test('several search and hash params present', () => {
const windowLocationHref = 'http://localhost/app/static/?search_param=w&tea=2234sdfj&cup=5%73bsod?892()#box=/%#/=Q4535&state_test=ljhf873';
window.history.replaceState({}, '', windowLocationHref);
expect(window.location.href).toEqual(windowLocationHref);
const result = (0, common_1.getInitialisationParameters)();
expect(result).toEqual({
search_param: 'w',
tea: '2234sdfj',
cup: '5sbsod?892()',
box: '/%#/=Q4535',
state_test: 'ljhf873'
});
});
});
describe('Without URL pathname', () => {
test('no search or hash params present', () => {
const windowLocationHref = 'http://localhost/';
window.history.replaceState({}, '', windowLocationHref);
expect(window.location.href).toEqual(windowLocationHref);
const result = (0, common_1.getInitialisationParameters)();
expect(result).toEqual({});
});
test('several search and hash params present', () => {
const windowLocationHref = 'http://localhost/?search_param=w&tea=2234sdfj&cup=5%73bsod?892()#box=/%#/=Q4535&state_test=ljhf873';
window.history.replaceState({}, '', windowLocationHref);
expect(window.location.href).toEqual(windowLocationHref);
const result = (0, common_1.getInitialisationParameters)();
expect(result).toEqual({
search_param: 'w',
tea: '2234sdfj',
cup: '5sbsod?892()',
box: '/%#/=Q4535',
state_test: 'ljhf873'
});
});
});
});
describe('getValidSSOProviders', () => {
test('empty input', () => {
const input = [];
const expected = [];
const result = (0, common_1.getValidSSOProviders)(input);
expect(expected).toEqual(result);
});
test('valid SSO provider as input', () => {
const input = [__mocks__1.exampleSSOProviderFull];
const expected = input;
const result = (0, common_1.getValidSSOProviders)(input);
expect(expected).toEqual(result);
});
test('several valid SSO providers as input', () => {
const input = [
__mocks__1.exampleSSOProviderFull,
__mocks__1.exampleSSOProviderMinimal,
__mocks__1.exampleSSOProvider
];
const expected = input;
const result = (0, common_1.getValidSSOProviders)(input);
expect(expected).toEqual(result);
expect((0, common_1.getValidSSOProviders)([__mocks__1.exampleSSOProviderMissingVisible])).toEqual([
Object.assign(Object.assign({}, __mocks__1.exampleSSOProviderMissingVisible), { visible: true })
]);
});
});