Skip to content

Commit

Permalink
Review#1: introduce showInSelector config value, properly handle de…
Browse files Browse the repository at this point in the history
…fault value of `selector.enabled`, improve redirect URL handling.
  • Loading branch information
azasypkin committed Mar 18, 2020
1 parent 5253fc7 commit d6d4c2d
Show file tree
Hide file tree
Showing 42 changed files with 1,083 additions and 488 deletions.
6 changes: 5 additions & 1 deletion x-pack/plugins/security/common/login_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import { LoginLayout } from './licensing';

interface LoginSelector {
enabled: boolean;
providers: Array<{ type: string; name: string; options: { description: string; order: number } }>;
providers: Array<{
type: string;
name: string;
options: { description?: string; order: number };
}>;
}

export interface LoginState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function mockAuthenticatedUser(user: Partial<AuthenticatedUser> = {}) {
enabled: true,
authentication_realm: { name: 'native1', type: 'native' },
lookup_realm: { name: 'native1', type: 'native' },
authentication_provider: 'basic',
authentication_provider: 'basic1',
...user,
};
}
17 changes: 17 additions & 0 deletions x-pack/plugins/security/common/parse_next.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ describe('parseNext', () => {
expect(parseNext(href, basePath)).toEqual(`${next}#${hash}`);
});

it('should properly handle multiple next with hash', () => {
const basePath = '/iqf';
const next1 = `${basePath}/app/kibana`;
const next2 = `${basePath}/app/ml`;
const hash = '/discover/New-Saved-Search';
const href = `${basePath}/login?next=${next1}&next=${next2}#${hash}`;
expect(parseNext(href, basePath)).toEqual(`${next1}#${hash}`);
});

it('should properly decode special characters', () => {
const basePath = '/iqf';
const next = `${encodeURIComponent(basePath)}%2Fapp%2Fkibana`;
Expand Down Expand Up @@ -118,6 +127,14 @@ describe('parseNext', () => {
expect(parseNext(href)).toEqual(`${next}#${hash}`);
});

it('should properly handle multiple next with hash', () => {
const next1 = '/app/kibana';
const next2 = '/app/ml';
const hash = '/discover/New-Saved-Search';
const href = `/login?next=${next1}&next=${next2}#${hash}`;
expect(parseNext(href)).toEqual(`${next1}#${hash}`);
});

it('should properly decode special characters', () => {
const next = '%2Fapp%2Fkibana';
const hash = '/discover/New-Saved-Search';
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/security/common/parse_next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ export function parseNext(href: string, basePath = '') {
return `${basePath}/`;
}

return query.next + (hash || '');
return next + (hash || '');
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ describe('loginApp', () => {
it('properly renders application', async () => {
const coreSetupMock = coreMock.createSetup();
const coreStartMock = coreMock.createStart();
coreStartMock.injectedMetadata.getInjectedVar.mockReturnValue(true);
coreSetupMock.getStartServices.mockResolvedValue([coreStartMock, {}]);
const containerMock = document.createElement('div');

Expand All @@ -55,16 +54,13 @@ describe('loginApp', () => {
history: (scopedHistoryMock.create() as unknown) as ScopedHistory,
});

expect(coreStartMock.injectedMetadata.getInjectedVar).toHaveBeenCalledTimes(1);
expect(coreStartMock.injectedMetadata.getInjectedVar).toHaveBeenCalledWith('secureCookies');

const mockRenderApp = jest.requireMock('./login_page').renderLoginPage;
expect(mockRenderApp).toHaveBeenCalledTimes(1);
expect(mockRenderApp).toHaveBeenCalledWith(coreStartMock.i18n, containerMock, {
http: coreStartMock.http,
notifications: coreStartMock.notifications,
fatalErrors: coreStartMock.fatalErrors,
loginAssistanceMessage: 'some-message',
requiresSecureConnection: true,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const loginApp = Object.freeze({
]);
return renderLoginPage(coreStart.i18n, element, {
http: coreStart.http,
notifications: coreStart.notifications,
fatalErrors: coreStart.fatalErrors,
loginAssistanceMessage: config.loginAssistanceMessage,
});
Expand Down
Loading

0 comments on commit d6d4c2d

Please sign in to comment.