Skip to content

Commit

Permalink
[7.6] Logout should redirect to the login screen at the server… (elas…
Browse files Browse the repository at this point in the history
…tic#57191)

* logout should redirect to the login screen at the server base path

* Revert "logout should redirect to the login screen at the server base path"

This reverts commit c80716b.

* fix logout url in nav control service

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
legrego and elasticmachine authored Feb 10, 2020
1 parent d4dfb17 commit 809d55e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,22 @@ export class SecurityNavControlService {
}

private registerSecurityNavControl(
core: Pick<CoreStart, 'chrome' | 'http' | 'i18n' | 'application'>
core: Pick<CoreStart, 'chrome' | 'http' | 'i18n' | 'injectedMetadata' | 'application'>
) {
const currentUserPromise = this.authc.getCurrentUser();
core.chrome.navControls.registerRight({
order: 2000,
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(
<I18nContext>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
});
});
});
});
}
3 changes: 1 addition & 2 deletions x-pack/test/functional/page_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -19,19 +20,19 @@ 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}`);
await PageObjects.common.sleep(1000);
});
}

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);
Expand All @@ -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}`);
Expand Down

0 comments on commit 809d55e

Please sign in to comment.