-
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.
Merge branch 'main' into 157721-hosts-view-flaky-test-fix
- Loading branch information
Showing
56 changed files
with
1,182 additions
and
214 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# @kbn/maps-vector-tile-utils | ||
|
||
Utility functions for vector tile API |
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,8 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { getTileUrlParams } from './src/get_tile_url_params'; |
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,12 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test', | ||
rootDir: '../../../..', | ||
roots: ['<rootDir>/x-pack/packages/maps/vector_tile_utils'], | ||
}; |
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,5 @@ | ||
{ | ||
"type": "shared-common", | ||
"id": "@kbn/maps-vector-tile-utils", | ||
"owner": "@elastic/kibana-gis" | ||
} |
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,6 @@ | ||
{ | ||
"name": "@kbn/maps-vector-tile-utils", | ||
"private": true, | ||
"version": "1.0.0", | ||
"license": "Elastic License 2.0" | ||
} |
33 changes: 33 additions & 0 deletions
33
x-pack/packages/maps/vector_tile_utils/src/get_tile_url_params.ts
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,33 @@ | ||
/* | ||
* 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 rison from '@kbn/rison'; | ||
|
||
export function getTileUrlParams( | ||
params: Record<string, boolean | number | object | string | null | undefined> | ||
) { | ||
const urlSearchParams = new URLSearchParams(); | ||
Object.keys(params).forEach((key) => { | ||
const value = params[key]; | ||
if (value === null || value === undefined) { | ||
return; | ||
} | ||
|
||
if (typeof value === 'object') { | ||
urlSearchParams.set(key, rison.encode(value)); | ||
return; | ||
} | ||
|
||
if (typeof value === 'number' || typeof value === 'boolean') { | ||
urlSearchParams.set(key, value.toString()); | ||
} | ||
|
||
urlSearchParams.set(key, value as string); | ||
}); | ||
|
||
return urlSearchParams.toString(); | ||
} |
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,21 @@ | ||
{ | ||
"extends": "../../../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "target/types", | ||
"types": [ | ||
"jest", | ||
"node", | ||
"react" | ||
] | ||
}, | ||
"include": [ | ||
"**/*.ts", | ||
"**/*.tsx", | ||
], | ||
"exclude": [ | ||
"target/**/*" | ||
], | ||
"kbn_references": [ | ||
"@kbn/rison", | ||
] | ||
} |
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
117 changes: 117 additions & 0 deletions
117
...ations/fleet/sections/agent_policy/components/agent_policy_advanced_fields/index.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,117 @@ | ||
/* | ||
* 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 from 'react'; | ||
|
||
import { waitFor, fireEvent, act } from '@testing-library/react'; | ||
import type { RenderResult } from '@testing-library/react'; | ||
|
||
import { createFleetTestRendererMock } from '../../../../../../mock'; | ||
import type { TestRenderer } from '../../../../../../mock'; | ||
|
||
import { allowedExperimentalValues } from '../../../../../../../common/experimental_features'; | ||
|
||
import { ExperimentalFeaturesService } from '../../../../../../services/experimental_features'; | ||
|
||
import type { NewAgentPolicy, AgentPolicy } from '../../../../../../../common/types'; | ||
|
||
import { useLicense } from '../../../../../../hooks/use_license'; | ||
|
||
import type { LicenseService } from '../../../../../../../common/services'; | ||
|
||
import type { ValidationResults } from '../agent_policy_validation'; | ||
|
||
import { AgentPolicyAdvancedOptionsContent } from '.'; | ||
|
||
jest.mock('../../../../../../hooks/use_license'); | ||
|
||
const mockedUseLicence = useLicense as jest.MockedFunction<typeof useLicense>; | ||
|
||
describe('Agent policy advanced options content', () => { | ||
let testRender: TestRenderer; | ||
let renderResult: RenderResult; | ||
|
||
const mockAgentPolicy: Partial<NewAgentPolicy | AgentPolicy> = { | ||
id: 'agent-policy-1', | ||
name: 'some-agent-policy', | ||
is_managed: false, | ||
is_protected: false, | ||
}; | ||
|
||
const mockUpdateAgentPolicy = jest.fn(); | ||
const mockValidation = jest.fn() as unknown as ValidationResults; | ||
const usePlatinumLicense = () => | ||
mockedUseLicence.mockReturnValue({ | ||
hasAtLeast: () => true, | ||
isPlatinum: () => true, | ||
} as unknown as LicenseService); | ||
|
||
const render = () => { | ||
// remove when feature flag is removed | ||
ExperimentalFeaturesService.init({ | ||
...allowedExperimentalValues, | ||
agentTamperProtectionEnabled: true, | ||
}); | ||
|
||
renderResult = testRender.render( | ||
<AgentPolicyAdvancedOptionsContent | ||
agentPolicy={mockAgentPolicy} | ||
updateAgentPolicy={mockUpdateAgentPolicy} | ||
validation={mockValidation} | ||
/> | ||
); | ||
}; | ||
|
||
beforeEach(() => { | ||
testRender = createFleetTestRendererMock(); | ||
}); | ||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('Agent tamper protection toggle', () => { | ||
it('should be visible if license is at least platinum', () => { | ||
usePlatinumLicense(); | ||
render(); | ||
expect(renderResult.queryByTestId('tamperProtectionSwitch')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should not be visible if license is below platinum', () => { | ||
mockedUseLicence.mockReturnValueOnce({ | ||
isPlatinum: () => false, | ||
hasAtLeast: () => false, | ||
} as unknown as LicenseService); | ||
render(); | ||
expect(renderResult.queryByTestId('tamperProtectionSwitch')).not.toBeInTheDocument(); | ||
}); | ||
it('switched to true enables the uninstall command link', async () => { | ||
usePlatinumLicense(); | ||
render(); | ||
await act(async () => { | ||
fireEvent.click(renderResult.getByTestId('tamperProtectionSwitch')); | ||
}); | ||
waitFor(() => { | ||
expect(renderResult.getByTestId('tamperProtectionSwitch')).toBeChecked(); | ||
expect(renderResult.getByTestId('uninstallCommandLink')).toBeEnabled(); | ||
}); | ||
}); | ||
it('switched to false disables the uninstall command link', () => { | ||
usePlatinumLicense(); | ||
render(); | ||
expect(renderResult.getByTestId('tamperProtectionSwitch')).not.toBeChecked(); | ||
expect(renderResult.getByTestId('uninstallCommandLink')).toBeDisabled(); | ||
}); | ||
it('should update agent policy when switched on', async () => { | ||
usePlatinumLicense(); | ||
render(); | ||
await act(async () => { | ||
(await renderResult.findByTestId('tamperProtectionSwitch')).click(); | ||
}); | ||
expect(mockUpdateAgentPolicy).toHaveBeenCalledWith({ is_protected: true }); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.