Add fixtures for software and vulnerabilities end-to-end tests (#6337)

This commit is contained in:
gillespi314 2022-06-23 10:01:37 -05:00 committed by GitHub
parent fc7650c4f8
commit 2715f8eb32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 95 additions and 0 deletions

View File

@ -251,12 +251,29 @@ e2e-setup:
./build/fleetctl user create --context e2e --email=observer@example.com --name observer --password=password123# --global-role=observer
./build/fleetctl user create --context e2e --email=sso_user@example.com --name "SSO user" --sso=true
# Setup e2e test environment and pre-populate database with software and vulnerabilities fixtures.
#
# Use in lieu of `e2e-setup` for tests that depend on these fixtures
e2e-setup-with-software:
curl 'https://localhost:8642/api/v1/setup' \
--data-raw '{"server_url":"https://localhost:8642","org_info":{"org_name":"Fleet Test"},"admin":{"admin":true,"email":"admin@example.com","name":"Admin","password":"password123#","password_confirmation":"password123#"}}' \
--compressed \
--insecure
./tools/backup_db/restore_e2e_software_test.sh
e2e-serve-free: e2e-reset-db
./build/fleet serve --mysql_address=localhost:3307 --mysql_username=root --mysql_password=toor --mysql_database=e2e --server_address=0.0.0.0:8642
e2e-serve-premium: e2e-reset-db
./build/fleet serve --dev_license --mysql_address=localhost:3307 --mysql_username=root --mysql_password=toor --mysql_database=e2e --server_address=0.0.0.0:8642
# Associate a host with a Fleet Desktop token.
#
# Usage:
# make e2e-set-desktop-token host_id=1 token=foo
e2e-set-desktop-token:
docker-compose exec -T mysql_test bash -c 'echo "INSERT INTO e2e.host_device_auth (host_id, token) VALUES ($(host_id), \"$(token)\") ON DUPLICATE KEY UPDATE token=VALUES(token)" | MYSQL_PWD=toor mysql -uroot'
changelog:
sh -c "find changes -type f | grep -v .keep | xargs -I {} sh -c 'grep \"\S\" {}; echo' > new-CHANGELOG.md"
sh -c "cat new-CHANGELOG.md CHANGELOG.md > tmp-CHANGELOG.md && rm new-CHANGELOG.md && mv tmp-CHANGELOG.md CHANGELOG.md"

View File

@ -0,0 +1 @@
- Add end-to-end test fixtures for software and vulnerabilities features and also for Fleet Desktop features

View File

@ -0,0 +1,24 @@
const fakeDeviceToken = "phAK3d3vIC37OK3n";
describe("Fleet Desktop", () => {
before(() => {
Cypress.session.clearAllSavedSessions();
cy.setup();
cy.loginWithCySession();
cy.addDockerHost();
cy.setDesktopToken(1, fakeDeviceToken);
cy.viewport(1200, 660);
});
after(() => {
cy.stopDockerHost();
});
describe("Fleet Desktop device user page", () => {
beforeEach(() => {
Cypress.session.clearAllSavedSessions();
});
it("serves device user page if url includes valid token", () => {
cy.visit(`/device/${fakeDeviceToken}`);
cy.findByText(/my device/i).should("exist");
});
});
});

View File

@ -0,0 +1,24 @@
describe("Software", () => {
before(() => {
Cypress.session.clearAllSavedSessions();
cy.setupWithSoftware();
cy.loginWithCySession();
cy.viewport(1600, 900);
});
after(() => {
cy.logout();
});
describe("Manage software page", () => {
beforeEach(() => {
cy.loginWithCySession();
cy.viewport(1600, 900);
cy.visit("/software/manage");
});
it("displays total software count", () => {
cy.getAttached(".table-container__header-left").within(() => {
cy.findByText(/902 software items/i).should("exist");
});
});
});
});

View File

@ -39,6 +39,13 @@ Cypress.Commands.add("setup", () => {
});
});
Cypress.Commands.add("setupWithSoftware", () => {
cy.exec("make e2e-reset-db e2e-setup-with-software", {
timeout: 20000,
env: { SHELL },
});
});
Cypress.Commands.add("login", (email, password) => {
email ||= "admin@example.com";
password ||= GOOD_PASSWORD;
@ -74,6 +81,13 @@ Cypress.Commands.add("logout", () => {
});
});
Cypress.Commands.add("setDesktopToken", (hostId, token) => {
cy.exec(`make e2e-set-desktop-token host_id=${hostId} token=${token}`, {
timeout: 20000,
env: { SHELL },
});
});
Cypress.Commands.add("seedQueries", () => {
const queries = [
{

View File

@ -8,6 +8,11 @@ declare namespace Cypress {
*/
setup(): Chainable<Element>;
/**
* Custom command to setup the testing environment with fixture data for software and vulnerabilities.
*/
setupWithSoftware(): Chainable<Element>;
/**
* Custom command to login the user programmatically using the fleet API.
*/
@ -24,6 +29,11 @@ declare namespace Cypress {
*/
logout(): Chainable<Element>;
/**
* Custom command to set a Fleet Desktop token to a host.
*/
setDesktopToken(hostId?: number, token?: string): Chainable<Element>;
/**
* Custom command to add new queries by default.
*/

View File

@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -euo pipefail
docker run --rm -i --network fleet_default mysql:5.7 bash -c 'gzip -kdc - | mysql -hmysql_test -uroot -ptoor e2e' < tools/testdata/e2e_software_test.sql.gz

BIN
tools/testdata/e2e_software_test.sql.gz vendored Normal file

Binary file not shown.