mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 04:07:31 +00:00
fix: correct oidcsettings management (#4413)
* fix(oidcsettings): corrected projection, unittests and added the add endpoint * fix(oidcsettings): corrected default handling and instance setup * fix: set oidc settings correctly in console * cleanup * e2e test * improve e2e test * lint e2e Co-authored-by: Livio Spring <livio.a@gmail.com> Co-authored-by: Fabi <38692350+hifabienne@users.noreply.github.com>
This commit is contained in:
@@ -3,6 +3,7 @@ import { login, User } from 'support/login/users';
|
||||
export interface apiCallProperties {
|
||||
authHeader: string;
|
||||
mgntBaseURL: string;
|
||||
adminBaseURL: string;
|
||||
}
|
||||
|
||||
export function apiAuth(): Cypress.Chainable<apiCallProperties> {
|
||||
@@ -10,6 +11,7 @@ export function apiAuth(): Cypress.Chainable<apiCallProperties> {
|
||||
return <apiCallProperties>{
|
||||
authHeader: `Bearer ${token}`,
|
||||
mgntBaseURL: `${Cypress.env('BACKEND_URL')}/management/v1/`,
|
||||
adminBaseURL: `${Cypress.env('BACKEND_URL')}/admin/v1/`,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
@@ -40,6 +40,46 @@ export function ensureSomethingExists(
|
||||
});
|
||||
}
|
||||
|
||||
export function ensureSomethingIsSet(
|
||||
api: apiCallProperties,
|
||||
path: string,
|
||||
find: (entity: any) => SearchResult,
|
||||
createPath: string,
|
||||
body: any,
|
||||
): Cypress.Chainable<number> {
|
||||
return getSomething(api, path, find)
|
||||
.then((sRes) => {
|
||||
if (sRes.entity) {
|
||||
return cy.wrap({
|
||||
id: sRes.entity.id,
|
||||
initialSequence: 0,
|
||||
});
|
||||
}
|
||||
return cy
|
||||
.request({
|
||||
method: 'PUT',
|
||||
url: createPath,
|
||||
headers: {
|
||||
Authorization: api.authHeader,
|
||||
},
|
||||
body: body,
|
||||
failOnStatusCode: false,
|
||||
followRedirect: false,
|
||||
})
|
||||
.then((cRes) => {
|
||||
expect(cRes.status).to.equal(200);
|
||||
return {
|
||||
id: cRes.body.id,
|
||||
initialSequence: sRes.sequence,
|
||||
};
|
||||
});
|
||||
})
|
||||
.then((data) => {
|
||||
awaitDesiredById(90, (entity) => !!entity, data.initialSequence, api, path, find);
|
||||
return cy.wrap<number>(data.id);
|
||||
});
|
||||
}
|
||||
|
||||
export function ensureSomethingDoesntExist(
|
||||
api: apiCallProperties,
|
||||
searchPath: string,
|
||||
@@ -97,6 +137,24 @@ function searchSomething(
|
||||
});
|
||||
}
|
||||
|
||||
function getSomething(
|
||||
api: apiCallProperties,
|
||||
searchPath: string,
|
||||
find: (entity: any) => SearchResult,
|
||||
): Cypress.Chainable<SearchResult> {
|
||||
return cy
|
||||
.request({
|
||||
method: 'GET',
|
||||
url: searchPath,
|
||||
headers: {
|
||||
Authorization: api.authHeader,
|
||||
},
|
||||
})
|
||||
.then((res) => {
|
||||
return find(res.body);
|
||||
});
|
||||
}
|
||||
|
||||
function awaitDesired(
|
||||
trials: number,
|
||||
expectEntity: (entity: any) => boolean,
|
||||
@@ -116,3 +174,23 @@ function awaitDesired(
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function awaitDesiredById(
|
||||
trials: number,
|
||||
expectEntity: (entity: any) => boolean,
|
||||
initialSequence: number,
|
||||
api: apiCallProperties,
|
||||
path: string,
|
||||
find: (entity: any) => SearchResult,
|
||||
) {
|
||||
getSomething(api, path, find).then((resp) => {
|
||||
const foundExpectedEntity = expectEntity(resp.entity);
|
||||
const foundExpectedSequence = resp.sequence > initialSequence;
|
||||
|
||||
if (!foundExpectedEntity || !foundExpectedSequence) {
|
||||
expect(trials, `trying ${trials} more times`).to.be.greaterThan(0);
|
||||
cy.wait(1000);
|
||||
awaitDesiredById(trials - 1, expectEntity, initialSequence, api, path, find);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
44
e2e/cypress/support/api/oidc-settings.ts
Normal file
44
e2e/cypress/support/api/oidc-settings.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { apiCallProperties } from './apiauth';
|
||||
import { ensureSomethingIsSet } from './ensure';
|
||||
|
||||
export function ensureOIDCSettingsSet(
|
||||
api: apiCallProperties,
|
||||
accessTokenLifetime,
|
||||
idTokenLifetime,
|
||||
refreshTokenExpiration,
|
||||
refreshTokenIdleExpiration: number,
|
||||
): Cypress.Chainable<number> {
|
||||
return ensureSomethingIsSet(
|
||||
api,
|
||||
`${api.adminBaseURL}settings/oidc`,
|
||||
(settings: any) => {
|
||||
let entity = null;
|
||||
if (
|
||||
settings.settings?.accessTokenLifetime === hoursToDuration(accessTokenLifetime) &&
|
||||
settings.settings?.idTokenLifetime === hoursToDuration(idTokenLifetime) &&
|
||||
settings.settings?.refreshTokenExpiration === daysToDuration(refreshTokenExpiration) &&
|
||||
settings.settings?.refreshTokenIdleExpiration === daysToDuration(refreshTokenIdleExpiration)
|
||||
) {
|
||||
entity = settings.settings;
|
||||
}
|
||||
return {
|
||||
entity: entity,
|
||||
sequence: settings.settings?.details?.sequence,
|
||||
};
|
||||
},
|
||||
`${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);
|
||||
}
|
Reference in New Issue
Block a user