diff --git a/cypress/integration/basic/observer.spec.ts b/cypress/integration/basic/observer.spec.ts index 8a9b449298..8ec713423c 100644 --- a/cypress/integration/basic/observer.spec.ts +++ b/cypress/integration/basic/observer.spec.ts @@ -4,6 +4,7 @@ if (Cypress.env("FLEET_TIER") === "basic") { cy.setup(); cy.login(); cy.seedBasic(); + cy.seedQueries(); cy.logout(); }); @@ -16,5 +17,26 @@ if (Cypress.env("FLEET_TIER") === "basic") { // TODO write the test! }); + + it("Should verify Teams on Hosts page", () => { + cy.login("marco@organization.com", "user123#"); + cy.visit("/hosts/manage"); + + cy.findByText("All hosts which have enrolled in Fleet").should("exist"); + + // TODO: can see the "Team" column in the Hosts table + // cy.contains(".table-container .data-table__table th", "Team").should("be.visible"); + }); + + it("Should verify hidden items on Hosts page", () => { + cy.login("marco@organization.com", "user123#"); + cy.visit("/hosts/manage"); + + cy.findByText("Packs").should("not.exist"); + cy.findByText("Queries").should("not.exist"); + + // TODO: can see the "Team" column in the Hosts table + // cy.contains(".table-container .data-table__table th", "Team").should("be.visible"); + }); }); } diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 3f9c290fb3..679a441b51 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -53,6 +53,38 @@ Cypress.Commands.add("logout", () => { }); }); +Cypress.Commands.add("seedQueries", () => { + const queries = [ + { + name: "Detect presence of authorized SSH keys", + query: + "SELECT username, authorized_keys. * FROM users CROSS JOIN authorized_keys USING (uid)", + description: + "Presence of authorized SSH keys may be unusual on laptops. Could be completely normal on servers, but may be worth auditing for unusual keys and/or changes.", + observer_can_run: true, + }, + { + name: "Get authorized keys for Domain Joined Accounts", + query: + "SELECT * FROM users CROSS JOIN authorized_keys USING(uid) WHERE username IN (SELECT distinct(username) FROM last);", + description: "List authorized_keys for each user on the system.", + observer_can_run: false, + }, + ]; + + queries.forEach((queryForm) => { + const { name, query, description, observer_can_run } = queryForm; + cy.request({ + url: "/v1/fleet/queries", + method: "POST", + body: { name, query, description, observer_can_run }, + auth: { + bearer: window.localStorage.getItem("FLEET::auth_token"), + }, + }); + }); +}); + Cypress.Commands.add("setupSMTP", () => { const body = { smtp_settings: { diff --git a/cypress/support/index.d.ts b/cypress/support/index.d.ts index d3ffadb5f0..abd0ee351c 100644 --- a/cypress/support/index.d.ts +++ b/cypress/support/index.d.ts @@ -18,6 +18,11 @@ declare namespace Cypress { */ logout(): Chainable; + /** + * Custom command to add new queries by default. + */ + seedQueries(): Chainable; + /** * Custom command to add a new user in Fleet (via fleetctl). */