Merge branch '21901-file-log-throttling'
[arvados.git] / services / workbench2 / cypress / e2e / virtual-machine-admin.cy.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 describe("Virtual machine login manage tests", function () {
6     let activeUser;
7     let adminUser;
8
9     const vmHost = `vm-${Math.floor(999999 * Math.random())}.host`;
10
11     before(function () {
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)
17             .as("adminUser")
18             .then(function () {
19                 adminUser = this.adminUser;
20             });
21         cy.getUser("user", "VMActive", "User", false, true)
22             .as("activeUser")
23             .then(function () {
24                 activeUser = this.activeUser;
25             });
26     });
27
28     it("adds and removes vm logins", function () {
29         cy.loginAs(adminUser);
30         cy.createVirtualMachine(adminUser.token, { hostname: vmHost });
31
32         // Navigate to VM admin
33         cy.get('header button[title="Admin Panel"]').click();
34         cy.get("#admin-menu").contains("Shell Access").click();
35
36         // Add login permission to admin
37         cy.get("[data-cy=vm-admin-table]")
38             .contains(vmHost)
39             .parents("tr")
40             .within(() => {
41                 cy.get('button[title="Add Login Permission"]').click();
42             });
43         cy.get("[data-cy=form-dialog]")
44             .should("contain", "Add login permission")
45             .within(() => {
46                 cy.get("label")
47                     .contains("Search for user")
48                     .parent()
49                     .within(() => {
50                         cy.get("input").type("VMAdmin");
51                     });
52             });
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")
57             .within(() => {
58                 cy.get("label")
59                     .contains("Add groups")
60                     .parent()
61                     .within(() => {
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");
66                         });
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");
71                         });
72                         cy.get("input").type("{enter}");
73                     });
74             });
75         cy.get("[data-cy=form-dialog]").within(() => {
76             cy.get("[data-cy=form-submit-btn]").click();
77         });
78
79         cy.get("[data-cy=vm-admin-table]")
80             .contains(vmHost)
81             .parents("tr")
82             .within(() => {
83                 cy.get("td").contains("admin");
84             });
85
86         // Add login permission to activeUser
87         cy.get("[data-cy=vm-admin-table]")
88             .contains(vmHost)
89             .parents("tr")
90             .within(() => {
91                 cy.get('button[title="Add Login Permission"]').click();
92             });
93         cy.get("[data-cy=form-dialog]")
94             .should("contain", "Add login permission")
95             .within(() => {
96                 cy.get("label")
97                     .contains("Search for user")
98                     .parent()
99                     .within(() => {
100                         cy.get("input").type("VMActive user");
101                     });
102             });
103         cy.get("[role=tooltip]").click();
104         cy.get("[data-cy=form-dialog]").within(() => {
105             cy.get("[data-cy=form-submit-btn]").click();
106         });
107
108         cy.get("[data-cy=vm-admin-table]")
109             .contains(vmHost)
110             .parents("tr")
111             .within(() => {
112                 cy.get("td").contains("user");
113             });
114
115         // Check admin's vm page for login
116         cy.get('header button[title="Account Management"]').click();
117         cy.get("#account-menu").contains("Shell Access").click();
118
119         cy.get("[data-cy=vm-user-table]")
120             .contains(vmHost)
121             .parents("tr")
122             .within(() => {
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);
127             });
128
129         // Check activeUser's vm page for login
130         cy.loginAs(activeUser);
131         cy.get('header button[title="Account Management"]').click();
132         cy.get("#account-menu").contains("Shell Access").click();
133
134         cy.get("[data-cy=vm-user-table]")
135             .contains(vmHost)
136             .parents("tr")
137             .within(() => {
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);
142             });
143
144         // Edit login permissions
145         cy.loginAs(adminUser);
146         cy.get('header button[title="Admin Panel"]').click();
147         cy.get("#admin-menu").contains("Shell Access").click();
148
149         cy.get("[data-cy=vm-admin-table]").contains("admin"); // Wait for page to finish
150
151         cy.get("[data-cy=vm-admin-table]").contains(vmHost).parents("tr").contains("admin").click();
152
153         cy.get("[data-cy=form-dialog]")
154             .should("contain", "Update login permission")
155             .within(() => {
156                 cy.get("label").contains("Add groups").parent().as("groupInput");
157             });
158
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();
162         });
163
164         cy.get("[data-cy=form-dialog]").within(() => {
165             cy.get("[data-cy=form-submit-btn]").click();
166         });
167
168         // Wait for page to finish loading
169         cy.get("[data-cy=vm-admin-table]")
170             .contains(vmHost)
171             .parents("tr")
172             .within(() => {
173                 cy.get("div[role=button]").parent().first().contains("admin");
174             });
175
176         cy.get("[data-cy=vm-admin-table]").contains(vmHost).parents("tr").contains("user").click();
177
178         cy.get("[data-cy=form-dialog]")
179             .should("contain", "Update login permission")
180             .within(() => {
181                 cy.get("label")
182                     .contains("Add groups")
183                     .parent()
184                     .within(() => {
185                         cy.get("input").type("docker{enter}");
186                     });
187             });
188
189         cy.get("[data-cy=form-dialog]").within(() => {
190             cy.get("[data-cy=form-submit-btn]").click();
191         });
192
193         // Verify new login permissions
194         // Check admin's vm page for login
195         cy.get('header button[title="Account Management"]').click();
196         cy.get("#account-menu").contains("Shell Access").click();
197
198         cy.get("[data-cy=vm-user-table]")
199             .contains(vmHost)
200             .parents("tr")
201             .within(() => {
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);
206             });
207
208         // Verify new login permissions
209         // Check activeUser's vm page for login
210         cy.loginAs(activeUser);
211         cy.get('header button[title="Account Management"]').click();
212         cy.get("#account-menu").contains("Shell Access").click();
213
214         cy.get("[data-cy=vm-user-table]")
215             .contains(vmHost)
216             .parents("tr")
217             .within(() => {
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);
222             });
223
224         // Remove login permissions
225         cy.loginAs(adminUser);
226         cy.get('header button[title="Admin Panel"]').click();
227         cy.get("#admin-menu").contains("Shell Access").click();
228
229         cy.get("[data-cy=vm-admin-table]").contains("user"); // Wait for page to finish
230
231         cy.get("[data-cy=vm-admin-table]")
232             .contains(vmHost)
233             .parents("tr")
234             .as("vmRow")
235             .contains("user")
236             .parents("[role=button]")
237             .find("svg")
238             .as("removeButton");
239         cy.get("@removeButton").click();
240         cy.get("[data-cy=confirmation-dialog-ok-btn]").click();
241
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);
245         });
246
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();
250
251         cy.waitForDom()
252             .get("[data-cy=vm-admin-table]")
253             .contains(vmHost)
254             .parents("tr")
255             .within(() => {
256                 cy.get("div[role=button]").should("not.exist");
257             });
258
259         // Check admin's vm page for login
260         cy.get('header button[title="Account Management"]').click();
261         cy.get("#account-menu").contains("Shell Access").click();
262
263         cy.get("[data-cy=vm-user-panel]").should("not.contain", vmHost);
264
265         // Check activeUser's vm page for login
266         cy.loginAs(activeUser);
267         cy.get('header button[title="Account Management"]').click();
268         cy.get("#account-menu").contains("Shell Access").click();
269
270         cy.get("[data-cy=vm-user-panel]").should("not.contain", vmHost);
271     });
272 });