neo4j-client-sso
Version:
Single sign-on client (frontend) library for Neo4j products
125 lines (124 loc) • 5.59 kB
JavaScript
/*
* 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.
*/
import { getInitialisationParameters, getValidSSOProviders } from './common';
import { exampleSSOProvider, exampleSSOProviderFull, exampleSSOProviderMinimal, exampleSSOProviderMissingVisible } from './__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 = 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 = 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 = 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 = 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 = 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 = 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 = 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 = getValidSSOProviders(input);
expect(expected).toEqual(result);
});
test('valid SSO provider as input', () => {
const input = [exampleSSOProviderFull];
const expected = input;
const result = getValidSSOProviders(input);
expect(expected).toEqual(result);
});
test('several valid SSO providers as input', () => {
const input = [
exampleSSOProviderFull,
exampleSSOProviderMinimal,
exampleSSOProvider
];
const expected = input;
const result = getValidSSOProviders(input);
expect(expected).toEqual(result);
expect(getValidSSOProviders([exampleSSOProviderMissingVisible])).toEqual([
Object.assign(Object.assign({}, exampleSSOProviderMissingVisible), { visible: true })
]);
});
});