Skip to content

Commit

Permalink
Review#1: add more tests, host more views under /app/security and m…
Browse files Browse the repository at this point in the history
…ore.
  • Loading branch information
azasypkin committed Mar 3, 2020
1 parent 86aff5e commit db9c2cd
Show file tree
Hide file tree
Showing 44 changed files with 655 additions and 127 deletions.
4 changes: 0 additions & 4 deletions test/functional/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ export default async function({ readConfigFile }) {
pathname: '/app/kibana',
hash: '/dev_tools/console',
},
account: {
pathname: '/app/kibana',
hash: '/account',
},
home: {
pathname: '/app/kibana',
hash: '/home',
Expand Down
3 changes: 1 addition & 2 deletions x-pack/legacy/plugins/security/public/hacks/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const securityPluginSetup = (npSetup.plugins as any).security as SecurityPluginS
if (securityPluginSetup) {
routes.when('/account', {
template: '<div />',
controller: () => npStart.core.application.navigateToApp('security'),
controller: () => npStart.core.application.navigateToApp('security/account'),
});

const getNextParameter = () => {
Expand All @@ -37,7 +37,6 @@ if (securityPluginSetup) {

function interceptorFactory(responseHandler: (response: ng.IHttpResponse<unknown>) => any) {
return function interceptor(response: ng.IHttpResponse<unknown>) {
// TODO: SHOULD WE CHECK THAT IT'S NOT ERROR RESPONSE (&& response.status !== 401)?
if (!isAnonymous && !isSystemApiRequest(response.config)) {
securityPluginSetup.sessionTimeout.extend(response.config.url);
}
Expand Down
7 changes: 6 additions & 1 deletion x-pack/legacy/plugins/xpack_main/public/services/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import chrome from 'ui/chrome';
export const Path = {
isUnauthenticated() {
const path = chrome.removeBasePath(window.location.pathname);
return path === '/login' || path === '/logout' || path === '/logged_out' || path === '/status';
return (
path === '/login' ||
path === '/logout' ||
path === '/app/security/logged_out' ||
path === '/status'
);
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ describe('XPackInfo routes', () => {
showLinks: false,
allowRoleDocumentLevelSecurity: false,
allowRoleFieldLevelSecurity: false,
linksMessage: 'Message',
},
},
});
Expand Down
5 changes: 0 additions & 5 deletions x-pack/plugins/security/common/licensing/license_features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,4 @@ export interface SecurityLicenseFeatures {
* Describes the layout of the login form if it's displayed.
*/
readonly layout?: LoginLayout;

/**
* Message to show when security links are clicked throughout the kibana app.
*/
readonly linksMessage?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ describe('license features', function() {
"allowRbac": false,
"allowRoleDocumentLevelSecurity": false,
"allowRoleFieldLevelSecurity": false,
"linksMessage": "Access is denied because Security is disabled in Elasticsearch.",
"showLinks": false,
"showLogin": false,
"showRoleMappingsManagement": false,
Expand Down Expand Up @@ -130,7 +129,6 @@ describe('license features', function() {
allowRoleDocumentLevelSecurity: false,
allowRoleFieldLevelSecurity: false,
allowRbac: false,
linksMessage: 'Access is denied because Security is disabled in Elasticsearch.',
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export class SecurityLicenseService {
allowRoleDocumentLevelSecurity: false,
allowRoleFieldLevelSecurity: false,
allowRbac: false,
linksMessage: 'Access is denied because Security is disabled in Elasticsearch.',
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ describe('accountManagementApp', () => {

const [[appRegistration]] = coreSetupMock.application.register.mock.calls;
expect(appRegistration).toEqual({
id: 'security',
appRoute: '/security/account',
id: 'security/account',
appRoute: '/app/security/account',
navLinkStatus: AppNavLinkStatus.hidden,
title: 'Account Management',
mount: expect.any(Function),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,24 @@ interface CreateDeps {
}

export const accountManagementApp = Object.freeze({
id: 'security',
id: 'security/account',
create({ application, authc, getStartServices }: CreateDeps) {
const title = i18n.translate('xpack.security.account.breadcrumb', {
defaultMessage: 'Account Management',
});
application.register({
id: this.id,
title: i18n.translate('xpack.security.account.breadcrumb', {
defaultMessage: 'Account Management',
}),
title,
// TODO: switch to proper enum once https://github.com/elastic/kibana/issues/58327 is resolved.
navLinkStatus: 3,
appRoute: '/security/account',
appRoute: '/app/security/account',
async mount({ element }: AppMountParameters) {
const [[coreStart], { renderAccountManagementPage }] = await Promise.all([
getStartServices(),
import('./account_management_page'),
]);

coreStart.chrome.setBreadcrumbs([
{
text: i18n.translate('xpack.security.account.breadcrumb', {
defaultMessage: 'Account Management',
}),
},
]);
coreStart.chrome.setBreadcrumbs([{ text: title }]);

return renderAccountManagementPage(coreStart.i18n, element, {
authc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ describe('loggedOutApp', () => {
loggedOutApp.create(coreSetupMock);

expect(coreSetupMock.http.anonymousPaths.register).toHaveBeenCalledTimes(1);
expect(coreSetupMock.http.anonymousPaths.register).toHaveBeenCalledWith('/logged_out');
expect(coreSetupMock.http.anonymousPaths.register).toHaveBeenCalledWith(
'/app/security/logged_out'
);

expect(coreSetupMock.application.register).toHaveBeenCalledTimes(1);

const [[appRegistration]] = coreSetupMock.application.register.mock.calls;
expect(appRegistration).toEqual({
id: 'logged_out',
id: 'security/logged_out',
chromeless: true,
appRoute: '/logged_out',
appRoute: '/app/security/logged_out',
title: 'Logged out',
mount: expect.any(Function),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ interface CreateDeps {
}

export const loggedOutApp = Object.freeze({
id: 'logged_out',
id: 'security/logged_out',
create({ application, http, getStartServices }: CreateDeps) {
http.anonymousPaths.register('/logged_out');
http.anonymousPaths.register('/app/security/logged_out');
application.register({
id: this.id,
title: i18n.translate('xpack.security.loggedOutAppTitle', { defaultMessage: 'Logged out' }),
chromeless: true,
appRoute: '/logged_out',
appRoute: '/app/security/logged_out',
async mount({ element }: AppMountParameters) {
const [[coreStart], { renderLoggedOutPage }] = await Promise.all([
getStartServices(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('loginApp', () => {

const [[appRegistration]] = coreSetupMock.application.register.mock.calls;
expect(appRegistration).toEqual({
id: 'login',
id: 'security/login',
chromeless: true,
appRoute: '/login',
title: 'Login',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface CreateDeps {
}

export const loginApp = Object.freeze({
id: 'login',
id: 'security/login',
create({ application, http, getStartServices, config }: CreateDeps) {
http.anonymousPaths.register('/login');
application.register({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('logoutApp', () => {

const [[appRegistration]] = coreSetupMock.application.register.mock.calls;
expect(appRegistration).toEqual({
id: 'logout',
id: 'security/logout',
chromeless: true,
appRoute: '/logout',
title: 'Logout',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface CreateDeps {
}

export const logoutApp = Object.freeze({
id: 'logout',
id: 'security/logout',
create({ application, http }: CreateDeps) {
http.anonymousPaths.register('/logout');
application.register({
Expand Down

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 @@ -26,10 +26,10 @@ describe('overwrittenSessionApp', () => {

const [[appRegistration]] = coreSetupMock.application.register.mock.calls;
expect(appRegistration).toEqual({
id: 'overwritten_session',
id: 'security/overwritten_session',
title: 'Overwritten Session',
chromeless: true,
appRoute: '/overwritten_session',
appRoute: '/app/security/overwritten_session',
mount: expect.any(Function),
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ interface CreateDeps {
}

export const overwrittenSessionApp = Object.freeze({
id: 'overwritten_session',
id: 'security/overwritten_session',
create({ application, authc, getStartServices }: CreateDeps) {
application.register({
id: this.id,
title: i18n.translate('xpack.security.overwrittenSessionAppTitle', {
defaultMessage: 'Overwritten Session',
}),
chromeless: true,
appRoute: '/overwritten_session',
appRoute: '/app/security/overwritten_session',
async mount({ element }: AppMountParameters) {
const [[coreStart], { renderOverwrittenSessionPage }] = await Promise.all([
getStartServices(),
Expand Down
Loading

0 comments on commit db9c2cd

Please sign in to comment.