From 204bdb6cc4bea79d03a25e6526910a84f0fbe4c5 Mon Sep 17 00:00:00 2001 From: Mark Hopkin Date: Wed, 10 Aug 2022 19:55:48 +0100 Subject: [PATCH] [Fleet][Test] Add cypress test for force installing unverified package assets (#138447) --- .../integration/install_assets.spec.ts | 65 +++++++++++++++++++ .../detail/settings/install_button.tsx | 7 +- 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 x-pack/plugins/fleet/cypress/integration/install_assets.spec.ts diff --git a/x-pack/plugins/fleet/cypress/integration/install_assets.spec.ts b/x-pack/plugins/fleet/cypress/integration/install_assets.spec.ts new file mode 100644 index 0000000000000..1c6268d2cf66a --- /dev/null +++ b/x-pack/plugins/fleet/cypress/integration/install_assets.spec.ts @@ -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 type { Interception } from 'cypress/types/net-stubbing'; + +describe('Install unverified package assets', () => { + beforeEach(() => { + cy.intercept('POST', '/api/fleet/epm/packages/fleet_server/*', (req) => { + if (!req.body.force) { + return req.reply({ + statusCode: 400, + body: { + message: 'Package is not verified.', + attributes: { + type: 'verification_failed', + }, + }, + }); + } + + req.reply({ + items: [ + { id: 'fleet_server-1234', type: 'dashboard' }, + { id: 'fleet_server-5678', type: 'dashboard' }, + ], + _meta: { install_source: 'registry' }, + }); + }).as('installAssets'); + + // save mocking out the whole package response, but make it so that fleet server is always uninstalled + cy.intercept('GET', '/api/fleet/epm/packages/fleet_server', (req) => { + req.continue((res) => { + if (res.body?.item?.savedObject) { + delete res.body.item.savedObject; + } + if (res.body?.item?.status) { + res.body.item.status = 'not_installed'; + } + }); + }); + }); + + it('should show force install modal if package is unverified', () => { + cy.visit('app/integrations/detail/fleet_server/settings'); + cy.getBySel('installAssetsButton').click(); + // this action will install x assets modal + const confirmInstall = cy.getBySel('confirmModalConfirmButton'); + confirmInstall.click(); + + // unverified integration force install modal + const installAnyway = cy.getBySel('confirmModalConfirmButton').contains('Install anyway'); + installAnyway.click(); + + // cypress 'hack' to get all requests made to an intercepted request + cy.get('@installAssets.all').then((interceptions) => { + const castInterceptions = interceptions as unknown as Interception[]; + // expect latest request to have used force + expect(castInterceptions.at(-1)?.request?.body?.force).to.equal(true); + }); + }); +}); diff --git a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/settings/install_button.tsx b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/settings/install_button.tsx index d4560812853fd..28ad351b865f7 100644 --- a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/settings/install_button.tsx +++ b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/settings/install_button.tsx @@ -52,7 +52,12 @@ export function InstallButton(props: InstallationButtonProps) { return canInstallPackages ? ( - + {isInstalling ? (