Skip to content

Commit

Permalink
[8.14] [Security Solution][Serverless] Fix browser title updater (#18…
Browse files Browse the repository at this point in the history
…1056) (#181108)

# Backport

This will backport the following commits from `main` to `8.14`:
- [[Security Solution][Serverless] Fix browser title updater
(#181056)](#181056)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Sergi
Massaneda","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-04-18T06:47:52Z","message":"[Security
Solution][Serverless] Fix browser title updater (#181056)\n\n##
Summary\r\n\r\nissue:
https://github.com/elastic/kibana/issues/181060\r\n\r\nFixes a bug on
the Browser title generation from navigation links\r\n\r\n###
Issue\r\n\r\nExternal links (Discover, Osquery) were not processed
properly and they\r\nwere being compared using the Security base path
(/app/security) in the\r\n`matchPath`, causing the first external link
in the list, Osquery, to be\r\ndisplayed instead of the correct
ones.\r\n\r\n### Screenshots\r\n\r\nBefore:\r\n\r\n<img width=\"961\"
alt=\"before\"\r\nsrc=\"https://github.com/elastic/kibana/assets/17747913/3836d956-3a04-443a-8659-6b038a8f0bf4\">\r\n\r\n\r\nAfter:\r\n\r\n<img
width=\"961\"
alt=\"after\"\r\nsrc=\"https://github.com/elastic/kibana/assets/17747913/dfb39139-7cc5-459a-a5de-bc77576ce542\">","sha":"fbfcb063992b9d5e2b7d41bef889a72d71700a62","branchLabelMapping":{"^v8.15.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:Threat
Hunting","Team:Threat
Hunting:Explore","v8.14.0","v8.15.0"],"title":"[Security
Solution][Serverless] Fix browser title
updater","number":181056,"url":"https://github.com/elastic/kibana/pull/181056","mergeCommit":{"message":"[Security
Solution][Serverless] Fix browser title updater (#181056)\n\n##
Summary\r\n\r\nissue:
https://github.com/elastic/kibana/issues/181060\r\n\r\nFixes a bug on
the Browser title generation from navigation links\r\n\r\n###
Issue\r\n\r\nExternal links (Discover, Osquery) were not processed
properly and they\r\nwere being compared using the Security base path
(/app/security) in the\r\n`matchPath`, causing the first external link
in the list, Osquery, to be\r\ndisplayed instead of the correct
ones.\r\n\r\n### Screenshots\r\n\r\nBefore:\r\n\r\n<img width=\"961\"
alt=\"before\"\r\nsrc=\"https://github.com/elastic/kibana/assets/17747913/3836d956-3a04-443a-8659-6b038a8f0bf4\">\r\n\r\n\r\nAfter:\r\n\r\n<img
width=\"961\"
alt=\"after\"\r\nsrc=\"https://github.com/elastic/kibana/assets/17747913/dfb39139-7cc5-459a-a5de-bc77576ce542\">","sha":"fbfcb063992b9d5e2b7d41bef889a72d71700a62"}},"sourceBranch":"main","suggestedTargetBranches":["8.14"],"targetPullRequestStates":[{"branch":"8.14","label":"v8.14.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.15.0","branchLabelMappingKey":"^v8.15.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/181056","number":181056,"mergeCommit":{"message":"[Security
Solution][Serverless] Fix browser title updater (#181056)\n\n##
Summary\r\n\r\nissue:
https://github.com/elastic/kibana/issues/181060\r\n\r\nFixes a bug on
the Browser title generation from navigation links\r\n\r\n###
Issue\r\n\r\nExternal links (Discover, Osquery) were not processed
properly and they\r\nwere being compared using the Security base path
(/app/security) in the\r\n`matchPath`, causing the first external link
in the list, Osquery, to be\r\ndisplayed instead of the correct
ones.\r\n\r\n### Screenshots\r\n\r\nBefore:\r\n\r\n<img width=\"961\"
alt=\"before\"\r\nsrc=\"https://github.com/elastic/kibana/assets/17747913/3836d956-3a04-443a-8659-6b038a8f0bf4\">\r\n\r\n\r\nAfter:\r\n\r\n<img
width=\"961\"
alt=\"after\"\r\nsrc=\"https://github.com/elastic/kibana/assets/17747913/dfb39139-7cc5-459a-a5de-bc77576ce542\">","sha":"fbfcb063992b9d5e2b7d41bef889a72d71700a62"}}]}]
BACKPORT-->

Co-authored-by: Sergi Massaneda <[email protected]>
  • Loading branch information
kibanamachine and semd authored Apr 18, 2024
1 parent 86de61e commit 9590ea6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { ExternalPageName } from '@kbn/security-solution-navigation';
import { renderHook } from '@testing-library/react-hooks';
import { APP_PATH, SecurityPageName } from '../../../common';
import { useFindAppLinksByPath } from './use_find_app_links_by_path';
Expand All @@ -30,6 +31,10 @@ jest.mock('react-router-dom', () => {
});

describe('useFindAppLinksByPath', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('returns null when navLinks is undefined', () => {
const { result } = renderHook(() => useFindAppLinksByPath(undefined));
expect(result.current).toBe(null);
Expand Down Expand Up @@ -80,4 +85,23 @@ describe('useFindAppLinksByPath', () => {
const { result } = renderHook(() => useFindAppLinksByPath([usersNavItem, usersRiskNavItem]));
expect(result.current).toBe(usersRiskNavItem);
});

it('should call getAppUrl using security internal security appId', () => {
const navItem = { id: SecurityPageName.users, title: 'Test User page' };
mockedUseLocation.mockReturnValue({ pathname: '/users' });
const { result } = renderHook(() => useFindAppLinksByPath([navItem]));
expect(result.current).toBe(navItem);
expect(mockedGetAppUrl).toHaveBeenCalledWith({
appId: 'securitySolutionUI',
deepLinkId: 'users',
});
});

it('should call getAppUrl using security external appId', () => {
const navItem = { id: ExternalPageName.osquery, title: 'Test Osquery external page' };
mockedUseLocation.mockReturnValue({ pathname: '/osquery' });
const { result } = renderHook(() => useFindAppLinksByPath([navItem]));
expect(result.current).toBe(navItem);
expect(mockedGetAppUrl).toHaveBeenCalledWith({ appId: 'osquery', deepLinkId: '' });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { getNavigationPropsFromId } from '@kbn/security-solution-navigation';
import { useCallback, useMemo } from 'react';
import { matchPath, useLocation } from 'react-router-dom';
import { APP_PATH } from '../../../common';
Expand All @@ -23,7 +24,8 @@ export const useFindAppLinksByPath = (navLinks: NavigationLink[] | undefined) =>

const isCurrentPathItem = useCallback(
(navItem: NavigationLink) => {
const appUrl = getAppUrl({ deepLinkId: navItem.id });
const { appId, deepLinkId } = getNavigationPropsFromId(navItem.id);
const appUrl = getAppUrl({ appId, deepLinkId });
return !!matchPath(`${basePath}${APP_PATH}${pathname}`, { path: appUrl, strict: false });
},
[basePath, getAppUrl, pathname]
Expand Down

0 comments on commit 9590ea6

Please sign in to comment.