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.get('[role=tooltip]').click();
54 cy.get('[data-cy=form-dialog]')
55 .should('contain', 'Add login permission')
58 .contains('Add groups')
61 cy.get('input').type('docker sudo{enter}');
64 cy.get('[data-cy=form-dialog]').within(() => {
65 cy.get('[data-cy=form-submit-btn]').click();
67 cy.get('[data-cy=snackbar]').contains('Permission updated');
68 cy.get('[data-cy=vm-admin-table]')
72 cy.get('td').contains('admin');
75 // Add login permission to activeUser
76 cy.get('[data-cy=vm-admin-table]')
80 cy.get('button[title="Add Login Permission"]').click();
82 cy.get('[data-cy=form-dialog]')
83 .should('contain', 'Add login permission')
86 .contains('Search for user')
89 cy.get('input').type('VMActive user');
92 cy.get('[role=tooltip]').click();
93 cy.get('[data-cy=form-dialog]').within(() => {
94 cy.get('[data-cy=form-submit-btn]').click();
96 cy.get('[data-cy=snackbar]').contains('Permission updated');
97 cy.get('[data-cy=vm-admin-table]')
101 cy.get('td').contains('user');
104 // Check admin's vm page for login
105 cy.get('header button[title="Account Management"]').click();
106 cy.get('#account-menu').contains('Virtual Machines').click();
108 cy.get('[data-cy=vm-user-table]')
112 cy.get('td').contains('admin');
113 cy.get('td').contains('docker');
114 cy.get('td').contains('sudo');
115 cy.get('td').contains('ssh admin@' + vmHost);
118 // Check activeUser's vm page for login
119 cy.loginAs(activeUser);
120 cy.get('header button[title="Account Management"]').click();
121 cy.get('#account-menu').contains('Virtual Machines').click();
123 cy.get('[data-cy=vm-user-table]')
127 cy.get('td').contains('user');
128 cy.get('td').should('not.contain', 'docker');
129 cy.get('td').should('not.contain', 'sudo');
130 cy.get('td').contains('ssh user@' + vmHost);
133 // Edit login permissions
134 cy.loginAs(adminUser);
135 cy.get('header button[title="Admin Panel"]').click();
136 cy.get('#admin-menu').contains('Virtual Machines').click();
138 cy.get('[data-cy=vm-admin-table]')
139 .contains('admin'); // Wait for page to finish
141 cy.get('[data-cy=vm-admin-table]')
147 cy.get('[data-cy=form-dialog]')
148 .should('contain', 'Update login permission')
151 .contains('Add groups')
156 cy.get('@groupInput').within(() => {
157 cy.get('div[role=button]').contains('sudo').parent().find('svg').click();
158 cy.get('div[role=button]').contains('docker').parent().find('svg').click();
161 cy.get('[data-cy=form-dialog]').within(() => {
162 cy.get('[data-cy=form-submit-btn]').click();
165 // Wait for page to finish loading
166 cy.get('[data-cy=snackbar]').contains('Permission updated');
167 cy.get('[data-cy=vm-admin-table]')
171 cy.get('div[role=button]')
177 cy.get('[data-cy=vm-admin-table]')
183 cy.get('[data-cy=form-dialog]')
184 .should('contain', 'Update login permission')
187 .contains('Add groups')
190 cy.get('input').type('docker{enter}');
194 cy.get('[data-cy=form-dialog]').within(() => {
195 cy.get('[data-cy=form-submit-btn]').click();
197 cy.get('[data-cy=snackbar]').contains('Permission updated');
199 // Verify new login permissions
200 // Check admin's vm page for login
201 cy.get('header button[title="Account Management"]').click();
202 cy.get('#account-menu').contains('Virtual Machines').click();
204 cy.get('[data-cy=vm-user-table]')
208 cy.get('td').contains('admin');
209 cy.get('td').should('not.contain', 'docker');
210 cy.get('td').should('not.contain', 'sudo');
211 cy.get('td').contains('ssh admin@' + vmHost);
214 // Verify new login permissions
215 // Check activeUser's vm page for login
216 cy.loginAs(activeUser);
217 cy.get('header button[title="Account Management"]').click();
218 cy.get('#account-menu').contains('Virtual Machines').click();
220 cy.get('[data-cy=vm-user-table]')
224 cy.get('td').contains('user');
225 cy.get('td').contains('docker');
226 cy.get('td').should('not.contain', 'sudo');
227 cy.get('td').contains('ssh user@' + vmHost);
230 // Remove login permissions
231 cy.loginAs(adminUser);
232 cy.get('header button[title="Admin Panel"]').click();
233 cy.get('#admin-menu').contains('Virtual Machines').click();
235 cy.get('[data-cy=vm-admin-table]')
236 .contains('user'); // Wait for page to finish
238 cy.get('[data-cy=vm-admin-table]')
243 .parents('[role=button]')
246 cy.get('@removeButton').click();
247 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
251 cy.get('div[role=button]').should('not.contain', 'user');
252 cy.get('div[role=button]').should('have.length', 1)
256 .find('div[role=button]')
258 .parents('[role=button]')
261 cy.get('@removeButton').click();
262 cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
264 cy.get('[data-cy=vm-admin-table]')
268 cy.get('div[role=button]').should('not.contain', 'admin');
271 // Check admin's vm page for login
272 cy.get('header button[title="Account Management"]').click();
273 cy.get('#account-menu').contains('Virtual Machines').click();
275 cy.get('[data-cy=vm-user-panel]')
276 .should('not.contain', vmHost);
278 // Check activeUser's vm page for login
279 cy.loginAs(activeUser);
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);