diff --git a/x-pack/plugins/security/public/nav_control/nav_control_service.tsx b/x-pack/plugins/security/public/nav_control/nav_control_service.tsx index 153e7112dc95b..035549ccaa2cb 100644 --- a/x-pack/plugins/security/public/nav_control/nav_control_service.tsx +++ b/x-pack/plugins/security/public/nav_control/nav_control_service.tsx @@ -57,7 +57,7 @@ export class SecurityNavControlService { } private registerSecurityNavControl( - core: Pick + core: Pick ) { const currentUserPromise = this.authc.getCurrentUser(); core.chrome.navControls.registerRight({ @@ -65,10 +65,14 @@ export class SecurityNavControlService { mount: (el: HTMLElement) => { const I18nContext = core.i18n.Context; + const serverBasePath = core.injectedMetadata.getInjectedVar('serverBasePath') as string; + + const logoutUrl = `${serverBasePath}/logout`; + const props = { user: currentUserPromise, editProfileUrl: core.http.basePath.prepend('/app/kibana#/account'), - logoutUrl: core.http.basePath.prepend(`/logout`), + logoutUrl, }; ReactDOM.render( diff --git a/x-pack/test/functional/apps/security/security.js b/x-pack/test/functional/apps/security/security.ts similarity index 54% rename from x-pack/test/functional/apps/security/security.js rename to x-pack/test/functional/apps/security/security.ts index 37b01ff61f5af..2096a7755e01d 100644 --- a/x-pack/test/functional/apps/security/security.js +++ b/x-pack/test/functional/apps/security/security.ts @@ -5,11 +5,15 @@ */ import expect from '@kbn/expect'; +import { parse } from 'url'; +import { FtrProviderContext } from '../../ftr_provider_context'; -export default function({ getService, getPageObjects }) { +export default function({ getService, getPageObjects }: FtrProviderContext) { + const browser = getService('browser'); const esArchiver = getService('esArchiver'); - const PageObjects = getPageObjects(['security']); + const PageObjects = getPageObjects(['security', 'spaceSelector']); const testSubjects = getService('testSubjects'); + const spaces = getService('spaces'); describe('Security', function() { this.tags('smoke'); @@ -46,6 +50,37 @@ export default function({ getService, getPageObjects }) { const logoutMessage = await testSubjects.getVisibleText('loginInfoMessage'); expect(logoutMessage).to.eql('You have logged out of Kibana.'); }); + + describe('within a non-default space', async () => { + before(async () => { + await PageObjects.security.forceLogout(); + + await spaces.create({ + id: 'some-space', + name: 'Some non-default space', + disabledFeatures: [], + }); + }); + + after(async () => { + await spaces.delete('some-space'); + }); + + it('logging out of a non-default space redirects to the login page at the server root', async () => { + await PageObjects.security.login(null, null, { + expectSpaceSelector: true, + }); + + await PageObjects.spaceSelector.clickSpaceCard('some-space'); + await PageObjects.spaceSelector.expectHomePage('some-space'); + + await PageObjects.security.logout(); + + const currentUrl = await browser.getCurrentUrl(); + const url = parse(currentUrl); + expect(url.pathname).to.eql('/login'); + }); + }); }); }); } diff --git a/x-pack/test/functional/page_objects/index.ts b/x-pack/test/functional/page_objects/index.ts index 91d4a3663fa65..7d503c18a7ffd 100644 --- a/x-pack/test/functional/page_objects/index.ts +++ b/x-pack/test/functional/page_objects/index.ts @@ -22,8 +22,6 @@ import { WatcherPageProvider } from './watcher_page'; // @ts-ignore not ts yet import { ReportingPageProvider } from './reporting_page'; // @ts-ignore not ts yet -import { SpaceSelectorPageProvider } from './space_selector_page'; -// @ts-ignore not ts yet import { AccountSettingProvider } from './accountsetting_page'; import { InfraHomePageProvider } from './infra_home_page'; import { InfraLogsPageProvider } from './infra_logs_page'; @@ -46,6 +44,7 @@ import { CopySavedObjectsToSpacePageProvider } from './copy_saved_objects_to_spa import { LensPageProvider } from './lens_page'; import { InfraMetricExplorerProvider } from './infra_metric_explorer'; import { RoleMappingsPageProvider } from './role_mappings_page'; +import { SpaceSelectorPageProvider } from './space_selector_page'; // just like services, PageObjects are defined as a map of // names to Providers. Merge in Kibana's or pick specific ones diff --git a/x-pack/test/functional/page_objects/space_selector_page.js b/x-pack/test/functional/page_objects/space_selector_page.ts similarity index 86% rename from x-pack/test/functional/page_objects/space_selector_page.js rename to x-pack/test/functional/page_objects/space_selector_page.ts index ad0f48bdd50bf..74f53a1cf551f 100644 --- a/x-pack/test/functional/page_objects/space_selector_page.js +++ b/x-pack/test/functional/page_objects/space_selector_page.ts @@ -5,8 +5,9 @@ */ import expect from '@kbn/expect'; +import { FtrProviderContext } from '../ftr_provider_context'; -export function SpaceSelectorPageProvider({ getService, getPageObjects }) { +export function SpaceSelectorPageProvider({ getService, getPageObjects }: FtrProviderContext) { const retry = getService('retry'); const log = getService('log'); const testSubjects = getService('testSubjects'); @@ -19,7 +20,7 @@ export function SpaceSelectorPageProvider({ getService, getPageObjects }) { log.debug('SpaceSelectorPage:initTests'); } - async clickSpaceCard(spaceId) { + async clickSpaceCard(spaceId: string) { return await retry.try(async () => { log.info(`SpaceSelectorPage:clickSpaceCard(${spaceId})`); await testSubjects.click(`space-card-${spaceId}`); @@ -27,11 +28,11 @@ export function SpaceSelectorPageProvider({ getService, getPageObjects }) { }); } - async expectHomePage(spaceId) { + async expectHomePage(spaceId: string) { return await this.expectRoute(spaceId, `/app/kibana#/home`); } - async expectRoute(spaceId, route) { + async expectRoute(spaceId: string, route: string) { return await retry.try(async () => { log.debug(`expectRoute(${spaceId}, ${route})`); await find.byCssSelector('[data-test-subj="kibanaChrome"] nav:not(.ng-hide) ', 20000); @@ -49,7 +50,7 @@ export function SpaceSelectorPageProvider({ getService, getPageObjects }) { return await testSubjects.click('spacesNavSelector'); } - async clickSpaceAvatar(spaceId) { + async clickSpaceAvatar(spaceId: string) { return await retry.try(async () => { log.info(`SpaceSelectorPage:clickSpaceAvatar(${spaceId})`); await testSubjects.click(`space-avatar-${spaceId}`);