diff --git a/Makefile b/Makefile index 4d56a65b12..214ef3e88d 100644 --- a/Makefile +++ b/Makefile @@ -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" diff --git a/changes/issue-6245-e2e-software-fixtures b/changes/issue-6245-e2e-software-fixtures new file mode 100644 index 0000000000..1042f54247 --- /dev/null +++ b/changes/issue-6245-e2e-software-fixtures @@ -0,0 +1 @@ +- Add end-to-end test fixtures for software and vulnerabilities features and also for Fleet Desktop features diff --git a/cypress/integration/all/app/fleetdesktop.spec.ts b/cypress/integration/all/app/fleetdesktop.spec.ts new file mode 100644 index 0000000000..8fbbe1b915 --- /dev/null +++ b/cypress/integration/all/app/fleetdesktop.spec.ts @@ -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"); + }); + }); +}); diff --git a/cypress/integration/all/app/software.spec.ts b/cypress/integration/all/app/software.spec.ts new file mode 100644 index 0000000000..c854c18cfa --- /dev/null +++ b/cypress/integration/all/app/software.spec.ts @@ -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"); + }); + }); + }); +}); diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 65a3c55113..5775f3ace5 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -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 = [ { diff --git a/cypress/support/index.d.ts b/cypress/support/index.d.ts index c577854154..411c79edbe 100644 --- a/cypress/support/index.d.ts +++ b/cypress/support/index.d.ts @@ -8,6 +8,11 @@ declare namespace Cypress { */ setup(): Chainable; + /** + * Custom command to setup the testing environment with fixture data for software and vulnerabilities. + */ + setupWithSoftware(): Chainable; + /** * Custom command to login the user programmatically using the fleet API. */ @@ -24,6 +29,11 @@ declare namespace Cypress { */ logout(): Chainable; + /** + * Custom command to set a Fleet Desktop token to a host. + */ + setDesktopToken(hostId?: number, token?: string): Chainable; + /** * Custom command to add new queries by default. */ diff --git a/tools/backup_db/restore_e2e_software_test.sh b/tools/backup_db/restore_e2e_software_test.sh new file mode 100755 index 0000000000..5ab60f4fe0 --- /dev/null +++ b/tools/backup_db/restore_e2e_software_test.sh @@ -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 + diff --git a/tools/testdata/e2e_software_test.sql.gz b/tools/testdata/e2e_software_test.sql.gz new file mode 100644 index 0000000000..5de505f4ab Binary files /dev/null and b/tools/testdata/e2e_software_test.sql.gz differ