]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/cypress/support/commands.ts
import 15.2.4
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / cypress / support / commands.ts
1 declare global {
2 namespace Cypress {
3 interface Chainable<Subject> {
4 login(): void;
5 text(): Chainable<string>;
6 }
7 }
8 }
9
10 import { Permissions } from '../../src/app/shared/models/permissions';
11
12 let auth: any;
13
14 const fillAuth = () => {
15 window.localStorage.setItem('dashboard_username', auth.username);
16 window.localStorage.setItem('access_token', auth.token);
17 window.localStorage.setItem('dashboard_permissions', auth.permissions);
18 window.localStorage.setItem('user_pwd_expiration_date', auth.pwdExpirationDate);
19 window.localStorage.setItem('user_pwd_update_required', auth.pwdUpdateRequired);
20 window.localStorage.setItem('sso', auth.sso);
21 };
22
23 Cypress.Commands.add('login', () => {
24 const username = Cypress.env('LOGIN_USER') || 'admin';
25 const password = Cypress.env('LOGIN_PWD') || 'admin';
26
27 if (auth === undefined) {
28 cy.request({
29 method: 'POST',
30 url: 'api/auth',
31 body: { username: username, password: password }
32 }).then((resp) => {
33 auth = resp.body;
34 auth.permissions = JSON.stringify(new Permissions(auth.permissions));
35 auth.pwdExpirationDate = String(auth.pwdExpirationDate);
36 auth.pwdUpdateRequired = String(auth.pwdUpdateRequired);
37 auth.sso = String(auth.sso);
38 fillAuth();
39 });
40 } else {
41 fillAuth();
42 }
43 });
44
45 Cypress.Commands.add('text', { prevSubject: true }, (subject) => {
46 return subject.text();
47 });