Skip to content

Commit

Permalink
[Fleet][Test] Add cypress test for force installing unverified packag…
Browse files Browse the repository at this point in the history
…e assets (#138447)
  • Loading branch information
hop-dev authored Aug 10, 2022
1 parent 07d1ec8 commit 204bdb6
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
65 changes: 65 additions & 0 deletions x-pack/plugins/fleet/cypress/integration/install_assets.spec.ts
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 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);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ export function InstallButton(props: InstallationButtonProps) {

return canInstallPackages ? (
<Fragment>
<EuiButton iconType={'importAction'} isLoading={isInstalling} onClick={toggleInstallModal}>
<EuiButton
iconType={'importAction'}
isLoading={isInstalling}
onClick={toggleInstallModal}
data-test-subj="installAssetsButton"
>
{isInstalling ? (
<FormattedMessage
id="xpack.fleet.integrations.installPackage.installingPackageButtonLabel"
Expand Down

0 comments on commit 204bdb6

Please sign in to comment.