]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/cypress/support/commands.ts
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / cypress / support / commands.ts
CommitLineData
e306af50
TL
1declare global {
2 namespace Cypress {
3 interface Chainable<Subject> {
4 login(): void;
5 text(): Chainable<string>;
6 }
7 }
8}
9
f67539c2 10import { Permissions } from '~/app/shared/models/permissions';
e306af50
TL
11
12let auth: any;
13
14const fillAuth = () => {
15 window.localStorage.setItem('dashboard_username', auth.username);
e306af50
TL
16 window.localStorage.setItem('dashboard_permissions', auth.permissions);
17 window.localStorage.setItem('user_pwd_expiration_date', auth.pwdExpirationDate);
18 window.localStorage.setItem('user_pwd_update_required', auth.pwdUpdateRequired);
19 window.localStorage.setItem('sso', auth.sso);
20};
21
22Cypress.Commands.add('login', () => {
23 const username = Cypress.env('LOGIN_USER') || 'admin';
24 const password = Cypress.env('LOGIN_PWD') || 'admin';
25
26 if (auth === undefined) {
27 cy.request({
28 method: 'POST',
29 url: 'api/auth',
f67539c2 30 headers: { Accept: 'application/vnd.ceph.api.v1.0+json' },
e306af50
TL
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
45Cypress.Commands.add('text', { prevSubject: true }, (subject) => {
46 return subject.text();
47});