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)
17 .as('adminUser').then(function() {
18 adminUser = this.adminUser;
21 cy.getUser('user', 'VMActive', 'User', false, true)
22 .as('activeUser').then(function() {
23 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[title="Admin Panel"]').click();
34 cy.get('#admin-menu').contains('Virtual Machines').click();
36 // Add login permission to admin
37 cy.get('[data-cy=vm-admin-table]')
41 cy.get('button[title="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]').as('add-login-dialog')
55 .should('contain', 'Add login permission')
58 .contains('Add groups')
61 cy.get('input').type('docker ');
62 // Veryfy submit enabled (form has changed)
63 cy.get('@add-login-dialog').within(() => {
64 cy.get('[data-cy=form-submit-btn]').should('be.enabled');
66 cy.get('input').type('sudo');
67 // Veryfy submit disabled (partial input in chips)
68 cy.get('@add-login-dialog').within(() => {
69 cy.get('[data-cy=form-submit-btn]').should('be.disabled');
71 cy.get('input').type('{enter}');
74 cy.get('[data-cy=form-dialog]').within(() => {
75 cy.get('[data-cy=form-submit-btn]').click();
78 cy.get('[data-cy=vm-admin-table]')
82 cy.get('td').contains('admin');
85 // Add login permission to activeUser
86 cy.get('[data-cy=vm-admin-table]')
90 cy.get('button[title="Add Login Permission"]').click();
92 cy.get('[data-cy=form-dialog]')
93 .should('contain', 'Add login permission')
96 .contains('Search for user')
99 cy.get('input').type('VMActive user');
102 cy.get('[role=tooltip]').click();
103 cy.get('[data-cy=form-dialog]').within(() => {
104 cy.get('[data-cy=form-submit-btn]').click();
107 cy.get('[data-cy=vm-admin-table]')
111 cy.get('td').contains('user');
114 // Check admin's vm page for login
115 cy.get('header button[title="Account Management"]').click();
116 cy.get('#account-menu').contains('Virtual Machines').click();
118 cy.get('[data-cy=vm-user-table]')
122 cy.get('td').contains('admin');
123 cy.get('td').contains('docker');
124 cy.get('td').contains('sudo');
125 cy.get('td').contains('ssh admin@' + vmHost);
128 // Check activeUser's vm page for login
129 cy.loginAs(activeUser);
130 cy.get('header button[title="Account Management"]').click();
131 cy.get('#account-menu').contains('Virtual Machines').click();
133 cy.get('[data-cy=vm-user-table]')
137 cy.get('td').contains('user');
138 cy.get('td').should('not.contain', 'docker');
139 cy.get('td').should('not.contain', 'sudo');
140 cy.get('td').contains('ssh user@' + vmHost);
143 // Edit login permissions
144 cy.loginAs(adminUser);
145 cy.get('header button[title="Admin Panel"]').click();
146 cy.get('#admin-menu').contains('Virtual Machines').click();
148 cy.get('[data-cy=vm-admin-table]')
149 .contains('admin'); // Wait for page to finish
151 cy.get('[data-cy=vm-admin-table]')
157 cy.get('[data-cy=form-dialog]')
158 .should('contain', 'Update login permission')
161 .contains('Add groups')
166 cy.get('@groupInput').within(() => {
167 cy.get('div[role=button]').contains('sudo').parent().find('svg').click();
168 cy.get('div[role=button]').contains('docker').parent().find('svg').click();
171 cy.get('[data-cy=form-dialog]').within(() => {
172 cy.get('[data-cy=form-submit-btn]').click();
175 // Wait for page to finish loading
176 cy.get('[data-cy=vm-admin-table]')
180 cy.get('div[role=button]')
186 cy.get('[data-cy=vm-admin-table]')
192 cy.get('[data-cy=form-dialog]')
193 .should('contain', 'Update login permission')
196 .contains('Add groups')
199 cy.get('input').type('docker{enter}');
203 cy.get('[data-cy=form-dialog]').within(() => {
204 cy.get('[data-cy=form-submit-btn]').click();
207 // Verify new login permissions
208 // Check admin's vm page for login
209 cy.get('header button[title="Account Management"]').click();
210 cy.get('#account-menu').contains('Virtual Machines').click();
212 cy.get('[data-cy=vm-user-table]')
216 cy.get('td').contains('admin');
217 cy.get('td').should('not.contain', 'docker');
218 cy.get('td').should('not.contain', 'sudo');
219 cy.get('td').contains('ssh admin@' + vmHost);
222 // Verify new login permissions
223 // Check activeUser's vm page for login
224 cy.loginAs(activeUser);
225 cy.get('header button[title="Account Management"]').click();
226 cy.get('#account-menu').contains('Virtual Machines').click();
228 cy.get('[data-cy=vm-user-table]')
232 cy.get('td').contains('user');
233 cy.get('td').contains('docker');
234 cy.get('td').should('not.contain', 'sudo');
235 cy.get('td').contains('ssh user@' + vmHost);
238 // Remove login permissions
239 cy.loginAs(adminUser);
240 cy.get('header button[title="Admin Panel"]').click();
241 cy.get('#admin-menu').contains('Virtual Machines').click();
243 cy.get('[data-cy=vm-admin-table]')
244 .contains('user'); // Wait for page to finish
246 cy.get('[data-cy=vm-admin-table]')
251 .parents('[role=button]')
254 cy.get('@removeButton').click();
255 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
259 cy.get('div[role=button]').should('not.contain', 'user');
260 cy.get('div[role=button]').should('have.length', 1)
264 .find('div[role=button]')
266 .parents('[role=button]')
269 cy.get('@removeButton').click();
270 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
272 cy.waitForDom().get('[data-cy=vm-admin-table]')
276 cy.get('div[role=button]').should('not.exist');
279 // Check admin's vm page for login
280 cy.get('header button[title="Account Management"]').click();
281 cy.get('#account-menu').contains('Virtual Machines').click();
283 cy.get('[data-cy=vm-user-panel]')
284 .should('not.contain', vmHost);
286 // Check activeUser's vm page for login
287 cy.loginAs(activeUser);
288 cy.get('header button[title="Account Management"]').click();
289 cy.get('#account-menu').contains('Virtual Machines').click();
291 cy.get('[data-cy=vm-user-panel]')
292 .should('not.contain', vmHost);