|
16 | 16 | import { shallow } from 'enzyme';
|
17 | 17 | import React from 'react';
|
18 | 18 | import { ClientConfigType } from '../../../types';
|
19 |
| -import { LoginPage, extractNextUrlFromWindowLocation } from '../login-page'; |
| 19 | +import { LoginPage, extractNextUrlFromWindowLocation, getNextPath } from '../login-page'; |
20 | 20 | import { validateCurrentPassword } from '../../../utils/login-utils';
|
21 | 21 | import { API_AUTH_LOGOUT } from '../../../../common';
|
22 | 22 | import { chromeServiceMock } from '../../../../../../src/core/public/mocks';
|
23 | 23 | import { AuthType } from '../../../../common';
|
| 24 | +import { setSavedTenant } from '../../../utils/storage-utils'; |
24 | 25 |
|
25 | 26 | jest.mock('../../../utils/login-utils', () => ({
|
26 | 27 | validateCurrentPassword: jest.fn(),
|
@@ -85,6 +86,45 @@ describe('test extractNextUrlFromWindowLocation', () => {
|
85 | 86 | });
|
86 | 87 | });
|
87 | 88 |
|
| 89 | +describe('test redirect', () => { |
| 90 | + test('extract redirect excludes security_tenant when no tenant in local storage', () => { |
| 91 | + // Trick to mock window.location |
| 92 | + const originalLocation = window.location; |
| 93 | + delete window.location; |
| 94 | + window.location = new URL('http://localhost:5601/app/login?nextUrl=%2Fapp%2Fdashboards') as any; |
| 95 | + setSavedTenant(null); |
| 96 | + const nextPath = getNextPath(''); |
| 97 | + expect(nextPath).toEqual('/app/dashboards'); |
| 98 | + window.location = originalLocation; |
| 99 | + }); |
| 100 | + |
| 101 | + test('extract redirect includes security_tenant when tenant in local storage', () => { |
| 102 | + const originalLocation = window.location; |
| 103 | + delete window.location; |
| 104 | + window.location = new URL('http://localhost:5601/app/login?nextUrl=%2Fapp%2Fdashboards'); |
| 105 | + setSavedTenant('custom'); |
| 106 | + const nextPath = getNextPath(''); |
| 107 | + expect(nextPath).toEqual('/app/dashboards?security_tenant=custom'); |
| 108 | + setSavedTenant(null); |
| 109 | + window.location = originalLocation; |
| 110 | + }); |
| 111 | + |
| 112 | + test('extract redirect includes security_tenant when tenant in local storage, existing url params and hash', () => { |
| 113 | + const originalLocation = window.location; |
| 114 | + delete window.location; |
| 115 | + window.location = new URL( |
| 116 | + "http://localhost:5601/app/login?nextUrl=%2Fapp%2Fdashboards?param1=value1#/view/7adfa750-4c81-11e8-b3d7-01146121b73d?_g=(filters:!(),refreshInterval:(pause:!f,value:900000),time:(from:now-24h,to:now))&_a=(description:'Analyze%20mock%20flight%20data%20for%20OpenSearch-Air,%20Logstash%20Airways,%20OpenSearch%20Dashboards%20Airlines%20and%20BeatsWest',filters:!(),fullScreenMode:!f,options:(hidePanelTitles:!f,useMargins:!t),query:(language:kuery,query:''),timeRestore:!t,title:'%5BFlights%5D%20Global%20Flight%20Dashboard',viewMode:view)" |
| 117 | + ); |
| 118 | + setSavedTenant('custom'); |
| 119 | + const nextPath = getNextPath(''); |
| 120 | + expect(nextPath).toEqual( |
| 121 | + "/app/dashboards?param1=value1&security_tenant=custom#/view/7adfa750-4c81-11e8-b3d7-01146121b73d?_g=(filters:!(),refreshInterval:(pause:!f,value:900000),time:(from:now-24h,to:now))&_a=(description:'Analyze%20mock%20flight%20data%20for%20OpenSearch-Air,%20Logstash%20Airways,%20OpenSearch%20Dashboards%20Airlines%20and%20BeatsWest',filters:!(),fullScreenMode:!f,options:(hidePanelTitles:!f,useMargins:!t),query:(language:kuery,query:''),timeRestore:!t,title:'%5BFlights%5D%20Global%20Flight%20Dashboard',viewMode:view)" |
| 122 | + ); |
| 123 | + setSavedTenant(null); |
| 124 | + window.location = originalLocation; |
| 125 | + }); |
| 126 | +}); |
| 127 | + |
88 | 128 | describe('Login page', () => {
|
89 | 129 | let chrome: ReturnType<typeof chromeServiceMock.createStartContract>;
|
90 | 130 | const mockHttpStart = {
|
|
0 commit comments