Skip to content

Commit

Permalink
[TIP] Add integrations on the threat_intelligence url now routes to t…
Browse files Browse the repository at this point in the history
…he threat_intel category (elastic#142538)
  • Loading branch information
PhilippeOberti authored and WafaaNasr committed Oct 14, 2022
1 parent d5159c9 commit 8aed554
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 24 deletions.
2 changes: 2 additions & 0 deletions x-pack/plugins/security_solution/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const APP_ICON = 'securityAnalyticsApp' as const;
export const APP_ICON_SOLUTION = 'logoSecurity' as const;
export const APP_PATH = `/app/security` as const;
export const ADD_DATA_PATH = `/app/integrations/browse/security`;
export const ADD_THREAT_INTELLIGENCE_DATA_PATH = `/app/integrations/browse/threat_intel`;
export const DEFAULT_BYTES_FORMAT = 'format:bytes:defaultPattern' as const;
export const DEFAULT_DATE_FORMAT = 'dateFormat' as const;
export const DEFAULT_DATE_FORMAT_TZ = 'dateFormat:tz' as const;
Expand Down Expand Up @@ -152,6 +153,7 @@ export const USERS_PATH = '/users' as const;
export const KUBERNETES_PATH = '/kubernetes' as const;
export const NETWORK_PATH = '/network' as const;
export const MANAGEMENT_PATH = '/administration' as const;
export const THREAT_INTELLIGENCE_PATH = '/threat_intelligence' as const;
export const ENDPOINTS_PATH = `${MANAGEMENT_PATH}/endpoints` as const;
export const POLICIES_PATH = `${MANAGEMENT_PATH}/policy` as const;
export const TRUSTED_APPS_PATH = `${MANAGEMENT_PATH}/trusted_apps` as const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import { render } from '@testing-library/react';
import { useLocation } from 'react-router-dom';
import { useVariationMock } from '../../../common/components/utils.mocks';
import { GlobalHeader } from '.';
import { ADD_DATA_PATH, SecurityPageName } from '../../../../common/constants';
import {
ADD_DATA_PATH,
ADD_THREAT_INTELLIGENCE_DATA_PATH,
SecurityPageName,
THREAT_INTELLIGENCE_PATH,
} from '../../../../common/constants';
import {
createSecuritySolutionStorageMock,
mockGlobalState,
Expand Down Expand Up @@ -98,6 +103,17 @@ describe('global header', () => {
expect(link?.getAttribute('href')).toBe(ADD_DATA_PATH);
});

it('points to the threat_intel Add data URL for threat_intelligence url', () => {
(useLocation as jest.Mock).mockReturnValue({ pathname: THREAT_INTELLIGENCE_PATH });
const { queryByTestId } = render(
<TestProviders store={store}>
<GlobalHeader setHeaderActionMenu={mockSetHeaderActionMenu} />
</TestProviders>
);
const link = queryByTestId('add-data');
expect(link?.getAttribute('href')).toBe(ADD_THREAT_INTELLIGENCE_DATA_PATH);
});

it('points to the resolved Add data URL by useVariation', () => {
(useLocation as jest.Mock).mockReturnValue([
{ pageName: SecurityPageName.overview, detailName: undefined },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { toMountPoint } from '@kbn/kibana-react-plugin/public';
import { useVariation } from '../../../common/components/utils';
import { MlPopover } from '../../../common/components/ml_popover/ml_popover';
import { useKibana } from '../../../common/lib/kibana';
import { ADD_DATA_PATH } from '../../../../common/constants';
import { isDetectionsPath } from '../../../helpers';
import { ADD_DATA_PATH, ADD_THREAT_INTELLIGENCE_DATA_PATH } from '../../../../common/constants';
import { isDetectionsPath, isThreatIntelligencePath } from '../../../helpers';
import { Sourcerer } from '../../../common/components/sourcerer';
import { TimelineId } from '../../../../common/types/timeline';
import { timelineDefaults } from '../../../timelines/store/timeline/defaults';
Expand Down Expand Up @@ -58,7 +58,10 @@ export const GlobalHeader = React.memo(
const sourcererScope = getScopeFromPath(pathname);
const showSourcerer = showSourcererByPath(pathname);

const [addIntegrationsUrl, setAddIntegrationsUrl] = useState(ADD_DATA_PATH);
const integrationsUrl = isThreatIntelligencePath(pathname)
? ADD_THREAT_INTELLIGENCE_DATA_PATH
: ADD_DATA_PATH;
const [addIntegrationsUrl, setAddIntegrationsUrl] = useState(integrationsUrl);
useVariation(
cloudExperiments,
'security-solutions.add-integrations-url',
Expand Down
18 changes: 13 additions & 5 deletions x-pack/plugins/security_solution/public/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* 2.0.
*/

import { ALERT_RULE_UUID, ALERT_RULE_NAME, ALERT_RULE_PARAMETERS } from '@kbn/rule-data-utils';
import { has, get, isEmpty } from 'lodash/fp';
import { ALERT_RULE_NAME, ALERT_RULE_PARAMETERS, ALERT_RULE_UUID } from '@kbn/rule-data-utils';
import { get, has, isEmpty } from 'lodash/fp';
import React from 'react';
import type { RouteProps } from 'react-router-dom';
import { matchPath, Redirect } from 'react-router-dom';
Expand All @@ -15,12 +15,13 @@ import type { Capabilities, CoreStart } from '@kbn/core/public';
import {
ALERTS_PATH,
APP_UI_ID,
CASES_FEATURE_ID,
CASES_PATH,
EXCEPTIONS_PATH,
LANDING_PATH,
RULES_PATH,
SERVER_APP_ID,
CASES_FEATURE_ID,
LANDING_PATH,
CASES_PATH,
THREAT_INTELLIGENCE_PATH,
} from '../common/constants';
import type { Ecs } from '../common/ecs';
import type {
Expand Down Expand Up @@ -164,6 +165,13 @@ export const isDetectionsPath = (pathname: string): boolean => {
});
};

export const isThreatIntelligencePath = (pathname: string): boolean => {
return !!matchPath(pathname, {
path: `(${THREAT_INTELLIGENCE_PATH})`,
strict: false,
});
};

export const getSubPluginRoutesByCapabilities = (
subPlugins: StartedSubPlugins,
capabilities: Capabilities
Expand Down
47 changes: 32 additions & 15 deletions x-pack/plugins/threat_intelligence/cypress/e2e/indicators.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,31 @@
*/

import {
ADD_INTEGRATIONS_BUTTON,
BREADCRUMBS,
DEFAULT_LAYOUT_TITLE,
FLYOUT_JSON,
FLYOUT_TABLE,
FLYOUT_TABS,
FLYOUT_TITLE,
INDICATORS_TABLE,
TOGGLE_FLYOUT_BUTTON,
FILTERS_GLOBAL_CONTAINER,
TIME_RANGE_PICKER,
QUERY_INPUT,
TABLE_CONTROLS,
INDICATOR_TYPE_CELL,
EMPTY_STATE,
FIELD_SELECTOR,
BREADCRUMBS,
LEADING_BREADCRUMB,
ENDING_BREADCRUMB,
FIELD_BROWSER,
FIELD_BROWSER_MODAL,
FIELD_SELECTOR_TOGGLE_BUTTON,
FIELD_SELECTOR,
FIELD_SELECTOR_INPUT,
FIELD_SELECTOR_LIST,
FIELD_SELECTOR_TOGGLE_BUTTON,
FILTERS_GLOBAL_CONTAINER,
FLYOUT_JSON,
FLYOUT_TABLE,
FLYOUT_TABS,
FLYOUT_TITLE,
INDICATOR_TYPE_CELL,
INDICATORS_TABLE,
INSPECTOR_BUTTON,
INSPECTOR_PANEL,
LEADING_BREADCRUMB,
QUERY_INPUT,
TABLE_CONTROLS,
TIME_RANGE_PICKER,
TOGGLE_FLYOUT_BUTTON,
} from '../screens/indicators';
import { login } from '../tasks/login';
import { esArchiverLoad, esArchiverUnload } from '../tasks/es_archiver';
Expand Down Expand Up @@ -189,4 +190,20 @@ describe('Indicators', () => {
});
});
});

describe('Add integrations', () => {
before(() => {
cy.visit(THREAT_INTELLIGENCE);

selectRange();
});

describe('when the global header add integrations button is clicked', () => {
it('should navigate to the Integrations page with Threat Intelligence category selected', () => {
cy.get(ADD_INTEGRATIONS_BUTTON).click();

cy.url().should('include', 'threat_intel');
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,5 @@ export const INDICATOR_FLYOUT_INVESTIGATE_IN_TIMELINE_BUTTON =
export const INSPECTOR_BUTTON = '[data-test-subj="tiIndicatorsGridInspect"]';

export const INSPECTOR_PANEL = '[data-test-subj="inspectorPanel"]';

export const ADD_INTEGRATIONS_BUTTON = '[data-test-subj="add-data"]';

0 comments on commit 8aed554

Please sign in to comment.