mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[Fleet] Fix pipelines and mapping editor not showing for integration packages (#154546)
## Summary After focusing so much on wriitng an automated test for input packages I realise I broke integration packages. I have added the missing automated tests, so we now have tests for: - an input package (should show pipelines and mappings editor) - an integration package that allows dataset to be customized (should not show) - an integration package that does not allow dataset to be customized (should show) I also fixed a bug where the request was firing even when not on the edit package policy page.
This commit is contained in:
parent
48300b0a59
commit
6a99c46108
6 changed files with 241 additions and 101 deletions
|
@ -0,0 +1,238 @@
|
|||
/*
|
||||
* 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 {
|
||||
ADD_INTEGRATION_POLICY_BTN,
|
||||
CREATE_PACKAGE_POLICY_SAVE_BTN,
|
||||
INTEGRATION_NAME_LINK,
|
||||
POLICY_EDITOR,
|
||||
} from '../screens/integrations';
|
||||
import { EXISTING_HOSTS_TAB } from '../screens/fleet';
|
||||
import { CONFIRM_MODAL } from '../screens/navigation';
|
||||
const INPUT_TEST_PACKAGE = 'input_package-1.0.0';
|
||||
const INTEGRATION_TEST_PACKAGE = 'logs_integration-1.0.0';
|
||||
const INTEGRATION_TEST_PACKAGE_NO_DATASET = 'logs_int_no_dataset-1.0.0';
|
||||
|
||||
describe('Input package create and edit package policy', () => {
|
||||
const agentPolicyId = 'test-input-package-policy';
|
||||
const agentPolicyName = 'Test input package policy';
|
||||
const packagePolicyName = 'input-package-policy';
|
||||
const datasetName = 'inputpkgdataset';
|
||||
|
||||
function editPackagePolicyandShowAdvanced(pkg: string, pkgPolicyName: string) {
|
||||
cy.visit(`/app/integrations/detail/${pkg}/policies`);
|
||||
|
||||
cy.getBySel(INTEGRATION_NAME_LINK).contains(pkgPolicyName).click();
|
||||
|
||||
cy.get('button').contains('Change defaults').click();
|
||||
cy.get('[data-test-subj^="advancedStreamOptionsToggle"]').click();
|
||||
}
|
||||
|
||||
before(() => {
|
||||
cy.task('installTestPackage', INPUT_TEST_PACKAGE);
|
||||
|
||||
cy.request({
|
||||
method: 'POST',
|
||||
url: `/api/fleet/agent_policies`,
|
||||
body: {
|
||||
id: agentPolicyId,
|
||||
name: agentPolicyName,
|
||||
description: 'desc',
|
||||
namespace: 'default',
|
||||
monitoring_enabled: [],
|
||||
},
|
||||
headers: { 'kbn-xsrf': 'cypress' },
|
||||
});
|
||||
});
|
||||
after(() => {
|
||||
// delete agent policy
|
||||
cy.request({
|
||||
method: 'POST',
|
||||
url: `/api/fleet/agent_policies/delete`,
|
||||
headers: { 'kbn-xsrf': 'cypress' },
|
||||
body: JSON.stringify({
|
||||
agentPolicyId,
|
||||
}),
|
||||
});
|
||||
cy.task('uninstallTestPackage', INPUT_TEST_PACKAGE);
|
||||
});
|
||||
it('should successfully create a package policy', () => {
|
||||
cy.visit(`/app/integrations/detail/${INPUT_TEST_PACKAGE}/overview`);
|
||||
cy.getBySel(ADD_INTEGRATION_POLICY_BTN).click();
|
||||
|
||||
cy.getBySel(POLICY_EDITOR.POLICY_NAME_INPUT).click().clear().type(packagePolicyName);
|
||||
cy.getBySel('multiTextInput-paths')
|
||||
.find('[data-test-subj="multiTextInputRow-0"]')
|
||||
.click()
|
||||
.type('/var/log/test.log');
|
||||
|
||||
cy.getBySel('multiTextInput-tags')
|
||||
.find('[data-test-subj="multiTextInputRow-0"]')
|
||||
.click()
|
||||
.type('tag1');
|
||||
|
||||
cy.getBySel(POLICY_EDITOR.DATASET_SELECT).click().type(datasetName);
|
||||
|
||||
cy.getBySel(EXISTING_HOSTS_TAB).click();
|
||||
|
||||
cy.getBySel(POLICY_EDITOR.AGENT_POLICY_SELECT).click().get(`#${agentPolicyId}`).click();
|
||||
cy.wait(500); // wait for policy id to be set
|
||||
cy.getBySel(CREATE_PACKAGE_POLICY_SAVE_BTN).click();
|
||||
|
||||
cy.getBySel(CONFIRM_MODAL.CANCEL_BUTTON).click();
|
||||
});
|
||||
|
||||
it('should show pipelines editor with link to pipeline', () => {
|
||||
editPackagePolicyandShowAdvanced(INPUT_TEST_PACKAGE, packagePolicyName);
|
||||
cy.getBySel(POLICY_EDITOR.INSPECT_PIPELINES_BTN).click();
|
||||
cy.getBySel(CONFIRM_MODAL.CONFIRM_BUTTON).click();
|
||||
cy.get('body').should('not.contain', 'Pipeline not found');
|
||||
cy.get('body').should('contain', '"managed_by": "fleet"');
|
||||
});
|
||||
it('should show mappings editor with link to create custom template', () => {
|
||||
editPackagePolicyandShowAdvanced(INPUT_TEST_PACKAGE, packagePolicyName);
|
||||
cy.getBySel(POLICY_EDITOR.EDIT_MAPPINGS_BTN).click();
|
||||
cy.getBySel(CONFIRM_MODAL.CONFIRM_BUTTON).click();
|
||||
cy.get('body').should('contain', `logs-${datasetName}@custom`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Integration package with custom dataset create and edit package policy', () => {
|
||||
const agentPolicyId = 'test-logs-integration-package-policy';
|
||||
const agentPolicyName = 'Test integration with custom dataset package policy';
|
||||
const packagePolicyName = 'logs-integration-package-policy';
|
||||
const datasetName = 'integrationpkgdataset';
|
||||
|
||||
before(() => {
|
||||
cy.task('installTestPackage', INTEGRATION_TEST_PACKAGE);
|
||||
|
||||
cy.request({
|
||||
method: 'POST',
|
||||
url: `/api/fleet/agent_policies`,
|
||||
body: {
|
||||
id: agentPolicyId,
|
||||
name: agentPolicyName,
|
||||
description: 'desc',
|
||||
namespace: 'default',
|
||||
monitoring_enabled: [],
|
||||
},
|
||||
headers: { 'kbn-xsrf': 'cypress' },
|
||||
});
|
||||
});
|
||||
after(() => {
|
||||
// delete agent policy
|
||||
cy.request({
|
||||
method: 'POST',
|
||||
url: `/api/fleet/agent_policies/delete`,
|
||||
headers: { 'kbn-xsrf': 'cypress' },
|
||||
body: JSON.stringify({
|
||||
agentPolicyId,
|
||||
}),
|
||||
});
|
||||
cy.task('uninstallTestPackage', INTEGRATION_TEST_PACKAGE);
|
||||
});
|
||||
it('should successfully create a package policy', () => {
|
||||
cy.visit(`/app/integrations/detail/${INTEGRATION_TEST_PACKAGE}/overview`);
|
||||
cy.getBySel(ADD_INTEGRATION_POLICY_BTN).click();
|
||||
|
||||
cy.getBySel(POLICY_EDITOR.POLICY_NAME_INPUT).click().clear().type(packagePolicyName);
|
||||
cy.getBySel('multiTextInput-log-file-path')
|
||||
.find('[data-test-subj="multiTextInputRow-0"]')
|
||||
.click()
|
||||
.type('/var/log/test.log');
|
||||
|
||||
cy.getBySel('textInput-dataset-name').click().type(datasetName);
|
||||
|
||||
cy.getBySel(EXISTING_HOSTS_TAB).click();
|
||||
|
||||
cy.getBySel(POLICY_EDITOR.AGENT_POLICY_SELECT).click().get(`#${agentPolicyId}`).click();
|
||||
cy.wait(500); // wait for policy id to be set
|
||||
cy.getBySel(CREATE_PACKAGE_POLICY_SAVE_BTN).click();
|
||||
|
||||
cy.getBySel(CONFIRM_MODAL.CANCEL_BUTTON).click();
|
||||
});
|
||||
|
||||
it('should not show pipelines or mappings editor', () => {
|
||||
cy.visit(`/app/integrations/detail/${INTEGRATION_TEST_PACKAGE}/policies`);
|
||||
cy.getBySel(INTEGRATION_NAME_LINK).contains(packagePolicyName).click();
|
||||
cy.get('[data-test-subj^="advancedStreamOptionsToggle"]').click();
|
||||
|
||||
cy.getBySel(POLICY_EDITOR.INSPECT_PIPELINES_BTN).should('not.exist');
|
||||
cy.getBySel(POLICY_EDITOR.EDIT_MAPPINGS_BTN).should('not.exist');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Integration package with fixed dataset create and edit package policy', () => {
|
||||
const agentPolicyId = 'test-integration-package-policy';
|
||||
const agentPolicyName = 'Test integration package policy';
|
||||
const packagePolicyName = 'integration-package-policy';
|
||||
|
||||
before(() => {
|
||||
cy.task('installTestPackage', INTEGRATION_TEST_PACKAGE_NO_DATASET);
|
||||
|
||||
cy.request({
|
||||
method: 'POST',
|
||||
url: `/api/fleet/agent_policies`,
|
||||
body: {
|
||||
id: agentPolicyId,
|
||||
name: agentPolicyName,
|
||||
description: 'desc',
|
||||
namespace: 'default',
|
||||
monitoring_enabled: [],
|
||||
},
|
||||
headers: { 'kbn-xsrf': 'cypress' },
|
||||
});
|
||||
});
|
||||
after(() => {
|
||||
// delete agent policy
|
||||
cy.request({
|
||||
method: 'POST',
|
||||
url: `/api/fleet/agent_policies/delete`,
|
||||
headers: { 'kbn-xsrf': 'cypress' },
|
||||
body: JSON.stringify({
|
||||
agentPolicyId,
|
||||
}),
|
||||
});
|
||||
cy.task('uninstallTestPackage', INTEGRATION_TEST_PACKAGE_NO_DATASET);
|
||||
});
|
||||
it('should successfully create a package policy', () => {
|
||||
cy.visit(`/app/integrations/detail/${INTEGRATION_TEST_PACKAGE_NO_DATASET}/overview`);
|
||||
cy.getBySel(ADD_INTEGRATION_POLICY_BTN).click();
|
||||
|
||||
cy.getBySel(POLICY_EDITOR.POLICY_NAME_INPUT).click().clear().type(packagePolicyName);
|
||||
cy.getBySel('multiTextInput-log-file-path')
|
||||
.find('[data-test-subj="multiTextInputRow-0"]')
|
||||
.click()
|
||||
.type('/var/log/test.log');
|
||||
|
||||
cy.getBySel(EXISTING_HOSTS_TAB).click();
|
||||
|
||||
cy.getBySel(POLICY_EDITOR.AGENT_POLICY_SELECT).click().get(`#${agentPolicyId}`).click();
|
||||
cy.wait(500); // wait for policy id to be set
|
||||
cy.getBySel(CREATE_PACKAGE_POLICY_SAVE_BTN).click();
|
||||
|
||||
cy.getBySel(CONFIRM_MODAL.CANCEL_BUTTON).click();
|
||||
});
|
||||
|
||||
it('should show pipelines editor with link to pipeline', () => {
|
||||
cy.visit(`/app/integrations/detail/${INTEGRATION_TEST_PACKAGE_NO_DATASET}/policies`);
|
||||
cy.getBySel(INTEGRATION_NAME_LINK).contains(packagePolicyName).click();
|
||||
cy.get('[data-test-subj^="advancedStreamOptionsToggle"]').click();
|
||||
|
||||
cy.getBySel(POLICY_EDITOR.INSPECT_PIPELINES_BTN).click();
|
||||
cy.get('body').should('not.contain', 'Pipeline not found');
|
||||
cy.get('body').should('contain', '"managed_by": "fleet"');
|
||||
});
|
||||
it('should show mappings editor with link to create custom template', () => {
|
||||
cy.visit(`/app/integrations/detail/${INTEGRATION_TEST_PACKAGE_NO_DATASET}/policies`);
|
||||
cy.getBySel(INTEGRATION_NAME_LINK).contains(packagePolicyName).click();
|
||||
cy.get('[data-test-subj^="advancedStreamOptionsToggle"]').click();
|
||||
|
||||
cy.getBySel(POLICY_EDITOR.EDIT_MAPPINGS_BTN).click();
|
||||
cy.get('body').should('contain', `logs-logs_int_no_dataset.log@custom`);
|
||||
});
|
||||
});
|
|
@ -1,98 +0,0 @@
|
|||
/*
|
||||
* 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 {
|
||||
ADD_INTEGRATION_POLICY_BTN,
|
||||
CREATE_PACKAGE_POLICY_SAVE_BTN,
|
||||
INTEGRATION_NAME_LINK,
|
||||
POLICY_EDITOR,
|
||||
} from '../screens/integrations';
|
||||
import { EXISTING_HOSTS_TAB } from '../screens/fleet';
|
||||
import { CONFIRM_MODAL } from '../screens/navigation';
|
||||
|
||||
const TEST_PACKAGE = 'input_package-1.0.0';
|
||||
const agentPolicyId = 'test-input-package-policy';
|
||||
const agentPolicyName = 'Test input package policy';
|
||||
const inputPackagePolicyName = 'input-package-policy';
|
||||
|
||||
function editPackagePolicyandShowAdvanced() {
|
||||
cy.visit(`/app/integrations/detail/${TEST_PACKAGE}/policies`);
|
||||
|
||||
cy.getBySel(INTEGRATION_NAME_LINK).contains(inputPackagePolicyName).click();
|
||||
|
||||
cy.get('button').contains('Change defaults').click();
|
||||
cy.get('[data-test-subj^="advancedStreamOptionsToggle"]').click();
|
||||
}
|
||||
describe('Input package create and edit package policy', () => {
|
||||
before(() => {
|
||||
cy.task('installTestPackage', TEST_PACKAGE);
|
||||
|
||||
cy.request({
|
||||
method: 'POST',
|
||||
url: `/api/fleet/agent_policies`,
|
||||
body: {
|
||||
id: agentPolicyId,
|
||||
name: agentPolicyName,
|
||||
description: 'desc',
|
||||
namespace: 'default',
|
||||
monitoring_enabled: [],
|
||||
},
|
||||
headers: { 'kbn-xsrf': 'cypress' },
|
||||
});
|
||||
});
|
||||
after(() => {
|
||||
// delete agent policy
|
||||
cy.request({
|
||||
method: 'POST',
|
||||
url: `/api/fleet/agent_policies/delete`,
|
||||
headers: { 'kbn-xsrf': 'cypress' },
|
||||
body: JSON.stringify({
|
||||
agentPolicyId,
|
||||
}),
|
||||
});
|
||||
cy.task('uninstallTestPackage', TEST_PACKAGE);
|
||||
});
|
||||
it('should successfully create a package policy', () => {
|
||||
cy.visit(`/app/integrations/detail/${TEST_PACKAGE}/overview`);
|
||||
cy.getBySel(ADD_INTEGRATION_POLICY_BTN).click();
|
||||
|
||||
cy.getBySel(POLICY_EDITOR.POLICY_NAME_INPUT).click().clear().type(inputPackagePolicyName);
|
||||
cy.getBySel('multiTextInput-paths')
|
||||
.find('[data-test-subj="multiTextInputRow-0"]')
|
||||
.click()
|
||||
.type('/var/log/test.log');
|
||||
|
||||
cy.getBySel('multiTextInput-tags')
|
||||
.find('[data-test-subj="multiTextInputRow-0"]')
|
||||
.click()
|
||||
.type('tag1');
|
||||
|
||||
cy.getBySel(POLICY_EDITOR.DATASET_SELECT).click().type('testdataset');
|
||||
|
||||
cy.getBySel(EXISTING_HOSTS_TAB).click();
|
||||
|
||||
cy.getBySel(POLICY_EDITOR.AGENT_POLICY_SELECT).click().get(`#${agentPolicyId}`).click();
|
||||
cy.wait(500); // wait for policy id to be set
|
||||
cy.getBySel(CREATE_PACKAGE_POLICY_SAVE_BTN).click();
|
||||
|
||||
cy.getBySel(CONFIRM_MODAL.CANCEL_BUTTON).click();
|
||||
});
|
||||
|
||||
it('should show pipelines editor with link to pipeline', () => {
|
||||
editPackagePolicyandShowAdvanced();
|
||||
cy.getBySel(POLICY_EDITOR.INSPECT_PIPELINES_BTN).click();
|
||||
cy.getBySel(CONFIRM_MODAL.CONFIRM_BUTTON).click();
|
||||
cy.get('body').should('not.contain', 'Pipeline not found');
|
||||
cy.get('body').should('contain', '"managed_by": "fleet"');
|
||||
});
|
||||
it('should show mappings editor with link to create custom template', () => {
|
||||
editPackagePolicyandShowAdvanced();
|
||||
cy.getBySel(POLICY_EDITOR.EDIT_MAPPINGS_BTN).click();
|
||||
cy.getBySel(CONFIRM_MODAL.CONFIRM_BUTTON).click();
|
||||
cy.get('body').should('contain', 'logs-testdataset@custom');
|
||||
});
|
||||
});
|
Binary file not shown.
BIN
x-pack/plugins/fleet/cypress/packages/logs_integration-1.0.0.zip
Normal file
BIN
x-pack/plugins/fleet/cypress/packages/logs_integration-1.0.0.zip
Normal file
Binary file not shown.
|
@ -31,7 +31,7 @@ export function usePackagePolicyEditorPageUrl(dataStreamId?: string) {
|
|||
|
||||
export function useIndexTemplateExists(
|
||||
templateName: string,
|
||||
enabled: boolean
|
||||
enabled: boolean = true
|
||||
): {
|
||||
exists?: boolean;
|
||||
isLoading: boolean;
|
||||
|
@ -43,7 +43,7 @@ export function useIndexTemplateExists(
|
|||
path: `/api/index_management/index_templates/${templateName}`,
|
||||
method: 'get',
|
||||
}),
|
||||
{ enabled: enabled || !!templateName }
|
||||
{ enabled }
|
||||
);
|
||||
|
||||
if (isLoading) {
|
||||
|
|
|
@ -102,7 +102,7 @@ export const PackagePolicyInputStreamConfig = memo<Props>(
|
|||
const { exists: indexTemplateExists, isLoading: isLoadingIndexTemplate } =
|
||||
useIndexTemplateExists(
|
||||
getRegistryDataStreamAssetBaseName({
|
||||
dataset: customDatasetVarValue,
|
||||
dataset: customDatasetVarValue || packageInputStream.data_stream.dataset,
|
||||
type: packageInputStream.data_stream.type,
|
||||
}),
|
||||
isPackagePolicyEdit
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue