-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution][Endpoint] Ensure fleet setup is done prior to att…
…empting to install/upgrade the Endpoint package (#107929) (#108045) * Ensure install/upgrade of endpoint package first checks to see that fleet is setup * Delete un-used `<Setup />` component * Test cases for `useUpgradeSecurityPackages()` hook Co-authored-by: Paul Tavares <[email protected]>
- Loading branch information
1 parent
3dfcdf8
commit ed4c3fe
Showing
6 changed files
with
77 additions
and
52 deletions.
There are no files selected for viewing
41 changes: 0 additions & 41 deletions
41
x-pack/plugins/security_solution/public/app/home/setup.tsx
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
x-pack/plugins/security_solution/public/common/hooks/use_upgrade_secuirty_packages.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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 React, { memo } from 'react'; | ||
import { useKibana } from '../lib/kibana'; | ||
import { renderHook as _renderHook, RenderHookResult } from '@testing-library/react-hooks'; | ||
import { useUpgradeSecurityPackages } from './use_upgrade_security_packages'; | ||
|
||
jest.mock('../components/user_privileges', () => { | ||
return { | ||
useUserPrivileges: jest.fn().mockReturnValue({ | ||
endpointPrivileges: { | ||
canAccessFleet: true, | ||
}, | ||
}), | ||
}; | ||
}); | ||
jest.mock('../lib/kibana'); | ||
|
||
describe('When using the `useUpgradeSecurityPackages()` hook', () => { | ||
let renderResult: RenderHookResult<object, void>; | ||
let renderHook: () => RenderHookResult<object, void>; | ||
let kibana: ReturnType<typeof useKibana>; | ||
|
||
// eslint-disable-next-line react/display-name | ||
const Wrapper = memo(({ children }) => { | ||
kibana = useKibana(); | ||
return <>{children}</>; | ||
}); | ||
|
||
beforeEach(() => { | ||
renderHook = () => { | ||
renderResult = _renderHook(() => useUpgradeSecurityPackages(), { wrapper: Wrapper }); | ||
return renderResult; | ||
}; | ||
}); | ||
|
||
afterEach(() => { | ||
if (renderResult) { | ||
renderResult.unmount(); | ||
} | ||
}); | ||
|
||
it('should call fleet setup first via `isInitialized()` and then send upgrade request', async () => { | ||
renderHook(); | ||
|
||
expect(kibana.services.fleet?.isInitialized).toHaveBeenCalled(); | ||
expect(kibana.services.http.post).not.toHaveBeenCalled(); | ||
|
||
await renderResult.waitFor( | ||
() => (kibana.services.http.post as jest.Mock).mock.calls.length > 0 | ||
); | ||
|
||
expect(kibana.services.http.post).toHaveBeenCalledWith( | ||
'/api/fleet/epm/packages/_bulk', | ||
expect.objectContaining({ | ||
body: '{"packages":["endpoint","security_detection_engine"]}', | ||
}) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters