2022-09-19 17:49:46 +00:00
|
|
|
import { login, User } from 'support/login/users';
|
2023-02-15 01:52:11 +00:00
|
|
|
import { API, SystemAPI, Token } from './types';
|
2022-08-05 18:00:46 +00:00
|
|
|
|
2022-10-11 13:29:23 +00:00
|
|
|
const authHeaderKey = 'Authorization',
|
2023-02-15 01:52:11 +00:00
|
|
|
orgIdHeaderKey = 'x-zitadel-orgid',
|
|
|
|
backendUrl = Cypress.env('BACKEND_URL');
|
2022-08-05 18:00:46 +00:00
|
|
|
|
2022-10-11 13:29:23 +00:00
|
|
|
export function apiAuth(): Cypress.Chainable<API> {
|
2022-09-19 17:49:46 +00:00
|
|
|
return login(User.IAMAdminUser, 'Password1!', false, true).then((token) => {
|
2022-10-11 13:29:23 +00:00
|
|
|
return <API>{
|
|
|
|
token: token,
|
2023-02-15 01:52:11 +00:00
|
|
|
mgmtBaseURL: `${backendUrl}/management/v1`,
|
|
|
|
adminBaseURL: `${backendUrl}/admin/v1`,
|
|
|
|
authBaseURL: `${backendUrl}/auth/v1`,
|
|
|
|
assetsBaseURL: `${backendUrl}/assets/v1`,
|
|
|
|
oauthBaseURL: `${backendUrl}/oauth/v2`,
|
|
|
|
oidcBaseURL: `${backendUrl}/oidc/v1`,
|
|
|
|
samlBaseURL: `${backendUrl}/saml/v2`,
|
2022-09-19 17:49:46 +00:00
|
|
|
};
|
|
|
|
});
|
2022-08-05 18:00:46 +00:00
|
|
|
}
|
2022-10-11 13:29:23 +00:00
|
|
|
|
2023-02-15 01:52:11 +00:00
|
|
|
export function systemAuth(): Cypress.Chainable<SystemAPI> {
|
|
|
|
return cy.task('systemToken').then((token) => {
|
|
|
|
return <SystemAPI>{
|
|
|
|
token: token,
|
|
|
|
baseURL: `${backendUrl}/system/v1`,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function requestHeaders(token: Token, orgId?: string): object {
|
|
|
|
const headers = { [authHeaderKey]: `Bearer ${token.token}` };
|
2022-10-11 13:29:23 +00:00
|
|
|
if (orgId) {
|
|
|
|
headers[orgIdHeaderKey] = orgId;
|
|
|
|
}
|
|
|
|
return headers;
|
|
|
|
}
|