2022-09-19 17:49:46 +00:00
|
|
|
import { apiCallProperties } from './apiauth';
|
|
|
|
import { ensureSomethingDoesntExist, ensureSomethingExists } from './ensure';
|
2022-04-28 10:35:02 +00:00
|
|
|
|
|
|
|
export function ensureProjectExists(api: apiCallProperties, projectName: string): Cypress.Chainable<number> {
|
2022-09-19 17:49:46 +00:00
|
|
|
return ensureSomethingExists(api, `projects/_search`, (project: any) => project.name === projectName, 'projects', {
|
|
|
|
name: projectName,
|
|
|
|
});
|
2022-04-28 10:35:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function ensureProjectDoesntExist(api: apiCallProperties, projectName: string): Cypress.Chainable<null> {
|
2022-09-19 17:49:46 +00:00
|
|
|
return ensureSomethingDoesntExist(
|
|
|
|
api,
|
|
|
|
`projects/_search`,
|
|
|
|
(project: any) => project.name === projectName,
|
|
|
|
(project) => `projects/${project.id}`,
|
|
|
|
);
|
2022-04-28 10:35:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class ResourceType {
|
2022-09-19 17:49:46 +00:00
|
|
|
constructor(public resourcePath: string, public compareProperty: string, public identifierProperty: string) {}
|
2022-04-28 10:35:02 +00:00
|
|
|
}
|
|
|
|
|
2022-09-19 17:49:46 +00:00
|
|
|
export const Apps = new ResourceType('apps', 'name', 'id');
|
|
|
|
export const Roles = new ResourceType('roles', 'key', 'key');
|
2022-04-28 10:35:02 +00:00
|
|
|
//export const Grants = new ResourceType('apps', 'name')
|
|
|
|
|
2022-09-19 17:49:46 +00:00
|
|
|
export function ensureProjectResourceDoesntExist(
|
|
|
|
api: apiCallProperties,
|
|
|
|
projectId: number,
|
|
|
|
resourceType: ResourceType,
|
|
|
|
resourceName: string,
|
|
|
|
): Cypress.Chainable<null> {
|
|
|
|
return ensureSomethingDoesntExist(
|
|
|
|
api,
|
|
|
|
`projects/${projectId}/${resourceType.resourcePath}/_search`,
|
|
|
|
(resource: any) => {
|
|
|
|
return resource[resourceType.compareProperty] === resourceName;
|
|
|
|
},
|
|
|
|
(resource) => {
|
|
|
|
return `projects/${projectId}/${resourceType.resourcePath}/${resource[resourceType.identifierProperty]}`;
|
|
|
|
},
|
|
|
|
);
|
2022-04-28 10:35:02 +00:00
|
|
|
}
|
|
|
|
|
2022-09-19 17:49:46 +00:00
|
|
|
export function ensureApplicationExists(
|
|
|
|
api: apiCallProperties,
|
|
|
|
projectId: number,
|
|
|
|
appName: string,
|
|
|
|
): Cypress.Chainable<number> {
|
|
|
|
return ensureSomethingExists(
|
|
|
|
api,
|
|
|
|
`projects/${projectId}/${Apps.resourcePath}/_search`,
|
|
|
|
(resource: any) => resource.name === appName,
|
|
|
|
`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'],
|
|
|
|
/* "clientId": "129383004379407963@e2eprojectpermission",
|
2022-04-28 10:35:02 +00:00
|
|
|
"clockSkew": "0s",
|
|
|
|
"allowedOrigins": [
|
|
|
|
"https://testurl.org"
|
|
|
|
]*/
|
2022-09-19 17:49:46 +00:00
|
|
|
},
|
|
|
|
);
|
2022-04-28 10:35:02 +00:00
|
|
|
}
|