zitadel/e2e/cypress/support/api/oidc-settings.ts
Elio Bischof 681541f41b
feat: add quotas (#4779)
adds possibilities to cap authenticated requests and execution seconds of actions on a defined intervall
2023-02-15 02:52:11 +01: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,
) {
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);
}