zitadel/e2e/cypress/support/api/oidc-settings.ts
Elio Bischof 51febd7e4e
test(e2e): test authorizations (#4342)
* add specs that cover the b2b demo

* update cypress

* test handling manager roles

* use shared mocha contexts

* use beforeEach instead of before

* improve readability

* improve application test

* remove static waits

* remove old awaitDesired

* test owned project authorizations

* simplify ensure.ts

* test granted projects authz

* disable prevSubject for shouldNotExist

* await non-existence, then expect no error

* update dependencies

* fix tests from scratch

* fix settings tests from scratch

* Apply suggestions from code review

Co-authored-by: Max Peintner <max@caos.ch>

* Implement code review suggestions

* use spread operator

* settings properties must match

* add check settings object

* revert spread operator

Co-authored-by: Max Peintner <max@caos.ch>
2022-10-11 15:29:23 +02:00

48 lines
1.5 KiB
TypeScript

import { ensureSetting } from './ensure';
import { API } from './types';
export function ensureOIDCSettingsSet(
api: API,
accessTokenLifetime: number,
idTokenLifetime: number,
refreshTokenExpiration: number,
refreshTokenIdleExpiration: number,
): Cypress.Chainable<number> {
return ensureSetting(
api,
`${api.adminBaseURL}/settings/oidc`,
(body: any) => {
const result = {
sequence: body.settings?.details?.sequence,
id: body.settings.id,
entity: null,
};
if (
body.settings &&
body.settings.accessTokenLifetime === hoursToDuration(accessTokenLifetime) &&
body.settings.idTokenLifetime === hoursToDuration(idTokenLifetime) &&
body.settings.refreshTokenExpiration === daysToDuration(refreshTokenExpiration) &&
body.settings.refreshTokenIdleExpiration === daysToDuration(refreshTokenIdleExpiration)
) {
return { ...result, entity: body.settings };
}
return result;
},
`${api.adminBaseURL}/settings/oidc`,
{
accessTokenLifetime: hoursToDuration(accessTokenLifetime),
idTokenLifetime: hoursToDuration(idTokenLifetime),
refreshTokenExpiration: daysToDuration(refreshTokenExpiration),
refreshTokenIdleExpiration: daysToDuration(refreshTokenIdleExpiration),
},
);
}
function hoursToDuration(hours: number): string {
return (hours * 3600).toString() + 's';
}
function daysToDuration(days: number): string {
return hoursToDuration(24 * days);
}