1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 describe("Virtual machine login manage tests", function () {
9 const vmHost = `vm-${Math.floor(999999 * Math.random())}.host`;
12 // Only set up common users once. These aren't set up as aliases because
13 // aliases are cleaned up after every test. Also it doesn't make sense
14 // to set the same users on beforeEach() over and over again, so we
15 // separate a little from Cypress' 'Best Practices' here.
16 cy.getUser("admin", "VMAdmin", "User", true, true)
19 adminUser = this.adminUser;
21 cy.getUser("user", "VMActive", "User", false, true)
24 activeUser = this.activeUser;
28 it("adds and removes vm logins", function () {
29 cy.loginAs(adminUser);
30 cy.createVirtualMachine(adminUser.token, { hostname: vmHost });
32 // Navigate to VM admin
33 cy.get('header button[aria-label="Admin Panel"]').click();
34 cy.get("#admin-menu").contains("Shell Access").click();
36 // Add login permission to admin
37 cy.get("[data-cy=vm-admin-table]")
41 cy.get('button[aria-label="Add Login Permission"]').click();
43 cy.get("[data-cy=form-dialog]")
44 .should("contain", "Add login permission")
47 .contains("Search for user")
50 cy.get("input").type("VMAdmin");
53 cy.waitForDom().get("[role=tooltip]").click();
54 cy.get("[data-cy=form-dialog]")
55 .as("add-login-dialog")
56 .should("contain", "Add login permission")
59 .contains("Add groups")
62 cy.get("input").type("docker ");
63 // Veryfy submit enabled (form has changed)
64 cy.get("@add-login-dialog").within(() => {
65 cy.get("[data-cy=form-submit-btn]").should("be.enabled");
67 cy.get("input").type("sudo");
68 // Veryfy submit disabled (partial input in chips)
69 cy.get("@add-login-dialog").within(() => {
70 cy.get("[data-cy=form-submit-btn]").should("be.disabled");
72 cy.get("input").type("{enter}");
75 cy.get("[data-cy=form-dialog]").within(() => {
76 cy.get("[data-cy=form-submit-btn]").click();
79 cy.get("[data-cy=vm-admin-table]")
83 cy.get("td").contains("admin");
86 // Add login permission to activeUser
87 cy.get("[data-cy=vm-admin-table]")
91 cy.get('button[aria-label="Add Login Permission"]').click();
93 cy.get("[data-cy=form-dialog]")
94 .should("contain", "Add login permission")
97 .contains("Search for user")
100 cy.get("input").type("VMActive user");
103 cy.get("[role=tooltip]").click();
104 cy.get("[data-cy=form-dialog]").within(() => {
105 cy.get("[data-cy=form-submit-btn]").click();
108 cy.get("[data-cy=vm-admin-table]")
112 cy.get("td").contains("user");
115 // Check admin's vm page for login
116 cy.get('header button[aria-label="Account Management"]').click();
117 cy.get("#account-menu").contains("Shell Access").click();
119 cy.get("[data-cy=vm-user-table]")
123 cy.get("td").contains("admin");
124 cy.get("td").contains("docker");
125 cy.get("td").contains("sudo");
126 cy.get("td").contains("ssh admin@" + vmHost);
129 // Check activeUser's vm page for login
130 cy.loginAs(activeUser);
131 cy.get('header button[aria-label="Account Management"]').click();
132 cy.get("#account-menu").contains("Shell Access").click();
134 cy.get("[data-cy=vm-user-table]")
138 cy.get("td").contains("user");
139 cy.get("td").should("not.contain", "docker");
140 cy.get("td").should("not.contain", "sudo");
141 cy.get("td").contains("ssh user@" + vmHost);
144 // Edit login permissions
145 cy.loginAs(adminUser);
146 cy.get('header button[aria-label="Admin Panel"]').click();
147 cy.get("#admin-menu").contains("Shell Access").click();
149 cy.get("[data-cy=vm-admin-table]").contains("admin"); // Wait for page to finish
151 cy.get("[data-cy=vm-admin-table]").contains(vmHost).parents("tr").contains("admin").click();
153 cy.get("[data-cy=form-dialog]")
154 .should("contain", "Update login permission")
156 cy.get("label").contains("Add groups").parent().as("groupInput");
159 cy.get("@groupInput").within(() => {
160 cy.get("div[role=button]").contains("sudo").parent().find("svg").click();
161 cy.get("div[role=button]").contains("docker").parent().find("svg").click();
164 cy.get("[data-cy=form-dialog]").within(() => {
165 cy.get("[data-cy=form-submit-btn]").click();
168 // Wait for page to finish loading
169 cy.get("[data-cy=vm-admin-table]")
173 cy.get("div[role=button]").parent().first().contains("admin");
176 cy.get("[data-cy=vm-admin-table]").contains(vmHost).parents("tr").contains("user").click();
178 cy.get("[data-cy=form-dialog]")
179 .should("contain", "Update login permission")
182 .contains("Add groups")
185 cy.get("input").type("docker{enter}");
189 cy.get("[data-cy=form-dialog]").within(() => {
190 cy.get("[data-cy=form-submit-btn]").click();
193 // Verify new login permissions
194 // Check admin's vm page for login
195 cy.get('header button[aria-label="Account Management"]').click();
196 cy.get("#account-menu").contains("Shell Access").click();
198 cy.get("[data-cy=vm-user-table]")
202 cy.get("td").contains("admin");
203 cy.get("td").should("not.contain", "docker");
204 cy.get("td").should("not.contain", "sudo");
205 cy.get("td").contains("ssh admin@" + vmHost);
208 // Verify new login permissions
209 // Check activeUser's vm page for login
210 cy.loginAs(activeUser);
211 cy.get('header button[aria-label="Account Management"]').click();
212 cy.get("#account-menu").contains("Shell Access").click();
214 cy.get("[data-cy=vm-user-table]")
218 cy.get("td").contains("user");
219 cy.get("td").contains("docker");
220 cy.get("td").should("not.contain", "sudo");
221 cy.get("td").contains("ssh user@" + vmHost);
224 // Remove login permissions
225 cy.loginAs(adminUser);
226 cy.get('header button[aria-label="Admin Panel"]').click();
227 cy.get("#admin-menu").contains("Shell Access").click();
229 cy.get("[data-cy=vm-admin-table]").contains("user"); // Wait for page to finish
231 cy.get("[data-cy=vm-admin-table]")
236 .parents("[role=button]")
239 cy.get("@removeButton").click();
240 cy.get("[data-cy=confirmation-dialog-ok-btn]").click();
242 cy.get("@vmRow").within(() => {
243 cy.get("div[role=button]").should("not.contain", "user");
244 cy.get("div[role=button]").should("have.length", 1);
247 cy.get("@vmRow").find("div[role=button]").contains("admin").parents("[role=button]").find("svg").as("removeButton");
248 cy.get("@removeButton").click();
249 cy.get("[data-cy=confirmation-dialog-ok-btn]").click();
252 .get("[data-cy=vm-admin-table]")
256 cy.get("div[role=button]").should("not.exist");
259 // Check admin's vm page for login
260 cy.get('header button[aria-label="Account Management"]').click();
261 cy.get("#account-menu").contains("Shell Access").click();
263 cy.get("[data-cy=vm-user-panel]").should("not.contain", vmHost);
265 // Check activeUser's vm page for login
266 cy.loginAs(activeUser);
267 cy.get('header button[aria-label="Account Management"]').click();
268 cy.get("#account-menu").contains("Shell Access").click();
270 cy.get("[data-cy=vm-user-panel]").should("not.contain", vmHost);