Skip to content

Commit

Permalink
Fixed it so that the warning banner does not show up whenever you hav…
Browse files Browse the repository at this point in the history
…e the priviledges to migrate the index in which case should be happening
  • Loading branch information
FrankHassanabad committed Feb 5, 2021
1 parent 1dda142 commit 0340413
Show file tree
Hide file tree
Showing 4 changed files with 282 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { waitForAlertsIndexToBeCreated } from '../../tasks/alerts';
import { goToRuleDetails } from '../../tasks/alerts_detection_rules';
import { createCustomRule, deleteCustomRule } from '../../tasks/api_calls/rules';
import { getCallOut, waitForCallOutToBeShown } from '../../tasks/common/callouts';
import { getCallOut } from '../../tasks/common/callouts';
import { cleanKibana } from '../../tasks/common';

const loadPageAsPlatformEngineerUser = (url: string) => {
Expand Down Expand Up @@ -55,9 +55,9 @@ describe('Detections > Need Admin Callouts indicating an admin is needed to migr
});

it('We show the need admin primary callout', () => {
waitForCallOutToBeShown(NEED_ADMIN_FOR_UPDATE_CALLOUT, 'primary');
getCallOut(ALERTS_CALLOUT).should('not.exist');
getCallOut(RULES_CALLOUT).should('not.exist');
getCallOut(NEED_ADMIN_FOR_UPDATE_CALLOUT).should('not.exist');
});
});

Expand All @@ -67,9 +67,9 @@ describe('Detections > Need Admin Callouts indicating an admin is needed to migr
});

it('We show 1 primary callout of need admin', () => {
waitForCallOutToBeShown(NEED_ADMIN_FOR_UPDATE_CALLOUT, 'primary');
getCallOut(ALERTS_CALLOUT).should('not.exist');
getCallOut(RULES_CALLOUT).should('not.exist');
getCallOut(NEED_ADMIN_FOR_UPDATE_CALLOUT).should('not.exist');
});
});

Expand All @@ -86,9 +86,9 @@ describe('Detections > Need Admin Callouts indicating an admin is needed to migr
});

it('We show 1 primary callout', () => {
waitForCallOutToBeShown(NEED_ADMIN_FOR_UPDATE_CALLOUT, 'primary');
getCallOut(ALERTS_CALLOUT).should('not.exist');
getCallOut(RULES_CALLOUT).should('not.exist');
getCallOut(NEED_ADMIN_FOR_UPDATE_CALLOUT).should('not.exist');
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { ROLES } from '../../../common/test';
import { DETECTIONS_RULE_MANAGEMENT_URL, DETECTIONS_URL } from '../../urls/navigation';
import { newRule } from '../../objects/rule';
import { PAGE_TITLE } from '../../screens/common/page';

import {
loginAndWaitForPageWithoutDateRange,
waitForPageWithoutDateRange,
} from '../../tasks/login';
import { waitForAlertsIndexToBeCreated } from '../../tasks/alerts';
import { goToRuleDetails } from '../../tasks/alerts_detection_rules';
import { createCustomRule, deleteCustomRule } from '../../tasks/api_calls/rules';
import { getCallOut, waitForCallOutToBeShown } from '../../tasks/common/callouts';
import { cleanKibana } from '../../tasks/common';

const loadPageAsPlatformEngineerUser = (url: string) => {
waitForPageWithoutDateRange(url, ROLES.soc_manager);
waitForPageTitleToBeShown();
};

const waitForPageTitleToBeShown = () => {
cy.get(PAGE_TITLE).should('be.visible');
};

describe('Detections > Need Admin Callouts indicating an admin is needed to migrate the alert data set', () => {
const NEED_ADMIN_FOR_UPDATE_CALLOUT = 'need-admin-for-update-rules';
const ALERTS_CALLOUT = 'read-only-access-to-alerts';
const RULES_CALLOUT = 'read-only-access-to-rules';

before(() => {
cleanKibana();
loginAndWaitForPageWithoutDateRange(DETECTIONS_URL, ROLES.soc_manager);
waitForAlertsIndexToBeCreated();
});

beforeEach(() => {
// Index mapping outdated is forced to return true as being outdated so that we get the
// need admin callouts being shown.
cy.intercept('GET', '/api/detection_engine/index', {
index_mapping_outdated: true,
name: '.siem-signals-default',
});
});

context('On Detections home page', () => {
beforeEach(() => {
loadPageAsPlatformEngineerUser(DETECTIONS_URL);
});

it('We show the need admin primary callout', () => {
waitForCallOutToBeShown(NEED_ADMIN_FOR_UPDATE_CALLOUT, 'primary');
getCallOut(ALERTS_CALLOUT).should('not.exist');
getCallOut(RULES_CALLOUT).should('not.exist');
});
});

context('On Rules Management page', () => {
beforeEach(() => {
loadPageAsPlatformEngineerUser(DETECTIONS_RULE_MANAGEMENT_URL);
});

it('We show 1 primary callout of need admin', () => {
waitForCallOutToBeShown(NEED_ADMIN_FOR_UPDATE_CALLOUT, 'primary');
getCallOut(ALERTS_CALLOUT).should('not.exist');
getCallOut(RULES_CALLOUT).should('not.exist');
});
});

context('On Rule Details page', () => {
beforeEach(() => {
createCustomRule(newRule);
loadPageAsPlatformEngineerUser(DETECTIONS_RULE_MANAGEMENT_URL);
waitForPageTitleToBeShown();
goToRuleDetails();
});

afterEach(() => {
deleteCustomRule();
});

it('We show 1 primary callout', () => {
waitForCallOutToBeShown(NEED_ADMIN_FOR_UPDATE_CALLOUT, 'primary');
getCallOut(ALERTS_CALLOUT).should('not.exist');
getCallOut(RULES_CALLOUT).should('not.exist');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,180 @@ describe('need_admin_for_update_callout', () => {
jest.resetAllMocks();
});

test('renders when signalIndexMappingOutdated is true', () => {
jest
.spyOn(userInfo, 'useUserData')
.mockImplementation(jest.fn().mockReturnValue([{ signalIndexMappingOutdated: true }]));
const wrapper = mount(
<TestProviders>
<NeedAdminForUpdateRulesCallOut />
</TestProviders>
);
expect(wrapper.exists('[data-test-subj="callout-need-admin-for-update-rules"]')).toEqual(true);
});
describe('hasIndexManage is "null"', () => {
const hasIndexManage = null;
test('renders when "signalIndexMappingOutdated" is true', () => {
jest
.spyOn(userInfo, 'useUserData')
.mockImplementation(
jest.fn().mockReturnValue([{ signalIndexMappingOutdated: true, hasIndexManage }])
);
const wrapper = mount(
<TestProviders>
<NeedAdminForUpdateRulesCallOut />
</TestProviders>
);
expect(wrapper.exists('[data-test-subj="callout-need-admin-for-update-rules"]')).toEqual(
true
);
});

test('Does not render a button as this is always persistent', () => {
jest
.spyOn(userInfo, 'useUserData')
.mockImplementation(jest.fn().mockReturnValue([{ signalIndexMappingOutdated: true }]));
const wrapper = mount(
<TestProviders>
<NeedAdminForUpdateRulesCallOut />
</TestProviders>
);
expect(wrapper.exists('[data-test-subj="callout-dismiss-btn"]')).toEqual(false);
});

test('Does NOT render when signalIndexMappingOutdated is false', () => {
jest
.spyOn(userInfo, 'useUserData')
.mockImplementation(jest.fn().mockReturnValue([{ signalIndexMappingOutdated: false }]));
const wrapper = mount(
<TestProviders>
<NeedAdminForUpdateRulesCallOut />
</TestProviders>
);
expect(wrapper.exists('[data-test-subj="callout-need-admin-for-update-rules"]')).toEqual(
false
);
});

test('Does not render a button as this is always persistent', () => {
jest
.spyOn(userInfo, 'useUserData')
.mockImplementation(jest.fn().mockReturnValue([{ signalIndexMappingOutdated: true }]));
const wrapper = mount(
<TestProviders>
<NeedAdminForUpdateRulesCallOut />
</TestProviders>
);
expect(wrapper.exists('[data-test-subj="callout-dismiss-btn"]')).toEqual(false);
test('Does NOT render when signalIndexMappingOutdated is null', () => {
jest
.spyOn(userInfo, 'useUserData')
.mockImplementation(jest.fn().mockReturnValue([{ signalIndexMappingOutdated: null }]));
const wrapper = mount(
<TestProviders>
<NeedAdminForUpdateRulesCallOut />
</TestProviders>
);
expect(wrapper.exists('[data-test-subj="callout-need-admin-for-update-rules"]')).toEqual(
false
);
});
});

test('Does NOT render when signalIndexMappingOutdated is false', () => {
jest
.spyOn(userInfo, 'useUserData')
.mockImplementation(jest.fn().mockReturnValue([{ signalIndexMappingOutdated: false }]));
const wrapper = mount(
<TestProviders>
<NeedAdminForUpdateRulesCallOut />
</TestProviders>
);
expect(wrapper.exists('[data-test-subj="callout-need-admin-for-update-rules"]')).toEqual(false);
describe('hasIndexManage is "false"', () => {
const hasIndexManage = false;
test('renders when "signalIndexMappingOutdated" is true', () => {
jest
.spyOn(userInfo, 'useUserData')
.mockImplementation(
jest.fn().mockReturnValue([{ signalIndexMappingOutdated: true, hasIndexManage }])
);
const wrapper = mount(
<TestProviders>
<NeedAdminForUpdateRulesCallOut />
</TestProviders>
);
expect(wrapper.exists('[data-test-subj="callout-need-admin-for-update-rules"]')).toEqual(
true
);
});

test('Does not render a button as this is always persistent', () => {
jest
.spyOn(userInfo, 'useUserData')
.mockImplementation(jest.fn().mockReturnValue([{ signalIndexMappingOutdated: true }]));
const wrapper = mount(
<TestProviders>
<NeedAdminForUpdateRulesCallOut />
</TestProviders>
);
expect(wrapper.exists('[data-test-subj="callout-dismiss-btn"]')).toEqual(false);
});

test('Does NOT render when signalIndexMappingOutdated is false', () => {
jest
.spyOn(userInfo, 'useUserData')
.mockImplementation(jest.fn().mockReturnValue([{ signalIndexMappingOutdated: false }]));
const wrapper = mount(
<TestProviders>
<NeedAdminForUpdateRulesCallOut />
</TestProviders>
);
expect(wrapper.exists('[data-test-subj="callout-need-admin-for-update-rules"]')).toEqual(
false
);
});

test('Does NOT render when signalIndexMappingOutdated is null', () => {
jest
.spyOn(userInfo, 'useUserData')
.mockImplementation(jest.fn().mockReturnValue([{ signalIndexMappingOutdated: null }]));
const wrapper = mount(
<TestProviders>
<NeedAdminForUpdateRulesCallOut />
</TestProviders>
);
expect(wrapper.exists('[data-test-subj="callout-need-admin-for-update-rules"]')).toEqual(
false
);
});
});

test('Does NOT render when signalIndexMappingOutdated is null', () => {
jest
.spyOn(userInfo, 'useUserData')
.mockImplementation(jest.fn().mockReturnValue([{ signalIndexMappingOutdated: null }]));
const wrapper = mount(
<TestProviders>
<NeedAdminForUpdateRulesCallOut />
</TestProviders>
);
expect(wrapper.exists('[data-test-subj="callout-need-admin-for-update-rules"]')).toEqual(false);
describe('hasIndexManage is "true"', () => {
const hasIndexManage = true;
test('Does not render when "signalIndexMappingOutdated" is true', () => {
jest
.spyOn(userInfo, 'useUserData')
.mockImplementation(
jest.fn().mockReturnValue([{ signalIndexMappingOutdated: true, hasIndexManage }])
);
const wrapper = mount(
<TestProviders>
<NeedAdminForUpdateRulesCallOut />
</TestProviders>
);
expect(wrapper.exists('[data-test-subj="callout-need-admin-for-update-rules"]')).toEqual(
false
);
});

test('Does not render a button as this is always persistent', () => {
jest
.spyOn(userInfo, 'useUserData')
.mockImplementation(jest.fn().mockReturnValue([{ signalIndexMappingOutdated: true }]));
const wrapper = mount(
<TestProviders>
<NeedAdminForUpdateRulesCallOut />
</TestProviders>
);
expect(wrapper.exists('[data-test-subj="callout-dismiss-btn"]')).toEqual(false);
});

test('Does NOT render when signalIndexMappingOutdated is false', () => {
jest
.spyOn(userInfo, 'useUserData')
.mockImplementation(jest.fn().mockReturnValue([{ signalIndexMappingOutdated: false }]));
const wrapper = mount(
<TestProviders>
<NeedAdminForUpdateRulesCallOut />
</TestProviders>
);
expect(wrapper.exists('[data-test-subj="callout-need-admin-for-update-rules"]')).toEqual(
false
);
});

test('Does NOT render when signalIndexMappingOutdated is null', () => {
jest
.spyOn(userInfo, 'useUserData')
.mockImplementation(jest.fn().mockReturnValue([{ signalIndexMappingOutdated: null }]));
const wrapper = mount(
<TestProviders>
<NeedAdminForUpdateRulesCallOut />
</TestProviders>
);
expect(wrapper.exists('[data-test-subj="callout-need-admin-for-update-rules"]')).toEqual(
false
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,25 @@ const needAdminForUpdateRulesMessage: CallOutMessage = {

/**
* Callout component that lets the user know that an administrator is needed for performing
* and auto-update of signals or not.
* and auto-update of signals or not. For this component to render the user must:
* - Have the permissions to be able to read "signalIndexMappingOutdated" and that condition is "true"
* - Have the permissions to be able to read "hasIndexManage" and that condition is "false"
*
* If the user has the permissions to see that signalIndexMappingOutdated is true and that
* hasIndexManage is also true, then the user should be performing the update on the page which is
* why we do not show it for that condition.
*/
const NeedAdminForUpdateCallOutComponent = (): JSX.Element => {
const [{ signalIndexMappingOutdated }] = useUserData();
const [{ signalIndexMappingOutdated, hasIndexManage }] = useUserData();

const signalIndexMappingIsOutdated =
signalIndexMappingOutdated != null && signalIndexMappingOutdated;

const userHasIndexManage = hasIndexManage != null && hasIndexManage;

return (
<CallOutPersistentSwitcher
condition={signalIndexMappingOutdated != null && signalIndexMappingOutdated}
condition={signalIndexMappingIsOutdated && !userHasIndexManage}
message={needAdminForUpdateRulesMessage}
/>
);
Expand Down

0 comments on commit 0340413

Please sign in to comment.