zitadel/e2e/cypress/support/api/projects.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

66 lines
2.2 KiB
TypeScript

import { ensureItemDoesntExist, ensureItemExists } from './ensure';
import { API } from './types';
export function ensureProjectExists(api: API, projectName: string, orgId?: number): Cypress.Chainable<number> {
return ensureItemExists(
api,
`${api.mgmtBaseURL}/projects/_search`,
(project: any) => project.name === projectName,
`${api.mgmtBaseURL}/projects`,
{ name: projectName },
orgId,
);
}
export function ensureProjectDoesntExist(api: API, projectName: string, orgId?: number): Cypress.Chainable<null> {
return ensureItemDoesntExist(
api,
`${api.mgmtBaseURL}/projects/_search`,
(project: any) => project.name === projectName,
(project) => `${api.mgmtBaseURL}/projects/${project.id}`,
orgId,
);
}
class ResourceType {
constructor(public resourcePath: string, public compareProperty: string, public identifierProperty: string) {}
}
export const Apps = new ResourceType('apps', 'name', 'id');
export const Roles = new ResourceType('roles', 'key', 'key');
//export const Grants = new ResourceType('apps', 'name')
export function ensureProjectResourceDoesntExist(
api: API,
projectId: number,
resourceType: ResourceType,
resourceName: string,
orgId?: number,
): Cypress.Chainable<null> {
return ensureItemDoesntExist(
api,
`${api.mgmtBaseURL}/projects/${projectId}/${resourceType.resourcePath}/_search`,
(resource: any) => resource[resourceType.compareProperty] === resourceName,
(resource) =>
`${api.mgmtBaseURL}/projects/${projectId}/${resourceType.resourcePath}/${resource[resourceType.identifierProperty]}`,
orgId,
);
}
export function ensureApplicationExists(api: API, projectId: number, appName: string): Cypress.Chainable<number> {
return ensureItemExists(
api,
`${api.mgmtBaseURL}/projects/${projectId}/${Apps.resourcePath}/_search`,
(resource: any) => resource.name === appName,
`${api.mgmtBaseURL}/projects/${projectId}/${Apps.resourcePath}/oidc`,
{
name: appName,
redirectUris: ['https://e2eredirecturl.org'],
responseTypes: ['OIDC_RESPONSE_TYPE_CODE'],
grantTypes: ['OIDC_GRANT_TYPE_AUTHORIZATION_CODE'],
authMethodType: 'OIDC_AUTH_METHOD_TYPE_NONE',
postLogoutRedirectUris: ['https://e2elogoutredirecturl.org'],
},
);
}