-
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.
[Fleet][Test] Add cypress test for force installing unverified packag…
…e assets (#138447)
- Loading branch information
Showing
2 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
x-pack/plugins/fleet/cypress/integration/install_assets.spec.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,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); | ||
}); | ||
}); | ||
}); |
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