|
| 1 | +/* |
| 2 | + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this file except in compliance with the License. |
| 6 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +import { composeLogoutUrl } from './helper'; |
| 17 | + |
| 18 | +describe('test OIDC helper utility', () => { |
| 19 | + test('test compose logout url', () => { |
| 20 | + const idpEndSessionUrl = 'https://idp.com/path'; |
| 21 | + const customLogoutUrl = 'https://customurl.com/path'; |
| 22 | + const additionalQuery = { key: 'value' }; |
| 23 | + |
| 24 | + expect('https://customurl.com/path?key=value').toEqual( |
| 25 | + composeLogoutUrl(customLogoutUrl, idpEndSessionUrl, additionalQuery) |
| 26 | + ); |
| 27 | + }); |
| 28 | + |
| 29 | + test('test compose logout url when no custom logout url', () => { |
| 30 | + const idpEndSessionUrl = 'https://idp.com/path'; |
| 31 | + const customLogoutUrl = ''; |
| 32 | + const additionalQuery = { key: 'value' }; |
| 33 | + |
| 34 | + expect('https://idp.com/path?key=value').toEqual( |
| 35 | + composeLogoutUrl(customLogoutUrl, idpEndSessionUrl, additionalQuery) |
| 36 | + ); |
| 37 | + }); |
| 38 | + |
| 39 | + test('test compse logout url when custom url has query parameter', () => { |
| 40 | + const idpEndSessionUrl = 'https://idp.com/path'; |
| 41 | + const customLogoutUrl = 'https://customurl.com/path?a=b'; |
| 42 | + const additionalQuery = { key: 'value' }; |
| 43 | + |
| 44 | + expect('https://customurl.com/path?a=b&key=value').toEqual( |
| 45 | + composeLogoutUrl(customLogoutUrl, idpEndSessionUrl, additionalQuery) |
| 46 | + ); |
| 47 | + }); |
| 48 | + |
| 49 | + test('test compse logout url when idp end session url has query parameter', () => { |
| 50 | + const idpEndSessionUrl = 'https://idp.com/path?a=b'; |
| 51 | + const customLogoutUrl = ''; |
| 52 | + const additionalQuery = { key: 'value' }; |
| 53 | + |
| 54 | + expect('https://idp.com/path?a=b&key=value').toEqual( |
| 55 | + composeLogoutUrl(customLogoutUrl, idpEndSessionUrl, additionalQuery) |
| 56 | + ); |
| 57 | + }); |
| 58 | +}); |
0 commit comments