Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.10] Update insecure cluster warning message (#80344) #80434

Merged
merged 1 commit into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import React, { useState } from 'react';
import { render, unmountComponentAtNode } from 'react-dom';

export const defaultAlertTitle = i18n.translate('security.checkup.insecureClusterTitle', {
defaultMessage: 'Please secure your installation',
defaultMessage: 'Your data is not secure',
});

export const defaultAlertText: (onDismiss: (persist: boolean) => void) => MountPoint = (
Expand All @@ -47,7 +47,7 @@ export const defaultAlertText: (onDismiss: (persist: boolean) => void) => MountP
<EuiText size="s">
<FormattedMessage
id="security.checkup.insecureClusterMessage"
defaultMessage="Our free security features can protect against unauthorized access."
defaultMessage="Don't lose one bit. Secure your data for free with Elastic."
/>
</EuiText>
<EuiSpacer />
Expand All @@ -66,7 +66,7 @@ export const defaultAlertText: (onDismiss: (persist: boolean) => void) => MountP
size="s"
color="primary"
fill
href="https://www.elastic.co/what-is/elastic-stack-security"
href="https://www.elastic.co/what-is/elastic-stack-security?blade=kibanasecuritymessage"
target="_blank"
>
{i18n.translate('security.checkup.learnMoreButtonText', {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/security/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export class SecurityPlugin
public start(core: CoreStart, { management, securityOss }: PluginStartDependencies) {
this.sessionTimeout.start();
this.navControlService.start({ core });
this.securityCheckupService.start({ securityOssStart: securityOss });
this.securityCheckupService.start({ securityOssStart: securityOss, docLinks: core.docLinks });
if (management) {
this.managementService.start({ capabilities: core.application.capabilities });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ import {
EuiFlexItem,
EuiButton,
} from '@elastic/eui';
import { DocumentationLinksService } from '../documentation_links';

export const insecureClusterAlertTitle = i18n.translate(
'xpack.security.checkup.insecureClusterTitle',
{ defaultMessage: 'Please secure your installation' }
{ defaultMessage: 'Your data is not secure' }
);

export const insecureClusterAlertText = (onDismiss: (persist: boolean) => void) =>
export const insecureClusterAlertText = (
getDocLinksService: () => DocumentationLinksService,
onDismiss: (persist: boolean) => void
) =>
((e) => {
const AlertText = () => {
const [persist, setPersist] = useState(false);
Expand All @@ -33,7 +37,7 @@ export const insecureClusterAlertText = (onDismiss: (persist: boolean) => void)
<EuiText size="s">
<FormattedMessage
id="xpack.security.checkup.insecureClusterMessage"
defaultMessage="Our free security features can protect against unauthorized access."
defaultMessage="Don’t lose one bit. Enable our free security features."
/>
</EuiText>
<EuiSpacer />
Expand All @@ -52,8 +56,9 @@ export const insecureClusterAlertText = (onDismiss: (persist: boolean) => void)
size="s"
color="primary"
fill
href="https://www.elastic.co/what-is/elastic-stack-security"
href={getDocLinksService().getEnableSecurityDocUrl()}
target="_blank"
data-test-subj="learnMoreButton"
>
{i18n.translate('xpack.security.checkup.enableButtonText', {
defaultMessage: `Enable security`,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { DocLinksStart } from 'src/core/public';

export class DocumentationLinksService {
private readonly esDocBasePath: string;

constructor(docLinks: DocLinksStart) {
this.esDocBasePath = `${docLinks.ELASTIC_WEBSITE_URL}guide/en/elasticsearch/reference/${docLinks.DOC_LINK_VERSION}`;
}

public getEnableSecurityDocUrl() {
return `${this.esDocBasePath}/get-started-enable-security.html?blade=kibanasecuritymessage`;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { MountPoint } from 'kibana/public';

import { docLinksServiceMock } from '../../../../../src/core/public/mocks';
import { mockSecurityOssPlugin } from '../../../../../src/plugins/security_oss/public/mocks';
import { insecureClusterAlertTitle } from './components';
import { SecurityCheckupService } from './security_checkup_service';
Expand All @@ -13,9 +16,12 @@ let mockOnDismiss = jest.fn();
jest.mock('./components', () => {
return {
insecureClusterAlertTitle: 'mock insecure cluster title',
insecureClusterAlertText: (onDismiss: any) => {
insecureClusterAlertText: (getDocLinksService: any, onDismiss: any) => {
mockOnDismiss = onDismiss;
return 'mock insecure cluster text';
const { insecureClusterAlertText } = jest.requireActual(
'./components/insecure_cluster_alert'
);
return insecureClusterAlertText(getDocLinksService, onDismiss);
},
};
});
Expand All @@ -31,9 +37,7 @@ describe('SecurityCheckupService', () => {
insecureClusterAlertTitle
);

expect(securityOssSetup.insecureCluster.setAlertText).toHaveBeenCalledWith(
'mock insecure cluster text'
);
expect(securityOssSetup.insecureCluster.setAlertText).toHaveBeenCalledTimes(1);
});
});
describe('#start', () => {
Expand All @@ -42,13 +46,34 @@ describe('SecurityCheckupService', () => {
const securityOssStart = mockSecurityOssPlugin.createStart();
const service = new SecurityCheckupService();
service.setup({ securityOssSetup });
service.start({ securityOssStart });
service.start({ securityOssStart, docLinks: docLinksServiceMock.createStartContract() });

expect(securityOssStart.insecureCluster.hideAlert).toHaveBeenCalledTimes(0);

mockOnDismiss();

expect(securityOssStart.insecureCluster.hideAlert).toHaveBeenCalledTimes(1);
});

it('configures the doc link correctly', async () => {
const securityOssSetup = mockSecurityOssPlugin.createSetup();
const securityOssStart = mockSecurityOssPlugin.createStart();
const service = new SecurityCheckupService();
service.setup({ securityOssSetup });
service.start({ securityOssStart, docLinks: docLinksServiceMock.createStartContract() });

const [alertText] = securityOssSetup.insecureCluster.setAlertText.mock.calls[0];

const container = document.createElement('div');
(alertText as MountPoint)(container);

const docLink = container
.querySelector('[data-test-subj="learnMoreButton"]')
?.getAttribute('href');

expect(docLink).toMatchInlineSnapshot(
`"https://www.elastic.co/guide/en/elasticsearch/reference/mocked-test-branch/get-started-enable-security.html?blade=kibanasecuritymessage"`
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,42 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { DocLinksStart } from 'kibana/public';

import {
SecurityOssPluginSetup,
SecurityOssPluginStart,
} from '../../../../../src/plugins/security_oss/public';
import { insecureClusterAlertTitle, insecureClusterAlertText } from './components';
import { DocumentationLinksService } from './documentation_links';

interface SetupDeps {
securityOssSetup: SecurityOssPluginSetup;
}

interface StartDeps {
securityOssStart: SecurityOssPluginStart;
docLinks: DocLinksStart;
}

export class SecurityCheckupService {
private securityOssStart?: SecurityOssPluginStart;

private docLinksService?: DocumentationLinksService;

public setup({ securityOssSetup }: SetupDeps) {
securityOssSetup.insecureCluster.setAlertTitle(insecureClusterAlertTitle);
securityOssSetup.insecureCluster.setAlertText(
insecureClusterAlertText((persist: boolean) => this.onDismiss(persist))
insecureClusterAlertText(
() => this.docLinksService!,
(persist: boolean) => this.onDismiss(persist)
)
);
}

public start({ securityOssStart }: StartDeps) {
public start({ securityOssStart, docLinks }: StartDeps) {
this.securityOssStart = securityOssStart;
this.docLinksService = new DocumentationLinksService(docLinks);
}

private onDismiss(persist: boolean) {
Expand Down