@red-hat-developer-hub/e2e-test-utils 1.1.14 → 1.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/playwright/helpers/auth-api-helper.d.ts +7 -0
- package/dist/playwright/helpers/auth-api-helper.d.ts.map +1 -0
- package/dist/playwright/helpers/auth-api-helper.js +31 -0
- package/dist/playwright/helpers/index.d.ts +2 -0
- package/dist/playwright/helpers/index.d.ts.map +1 -1
- package/dist/playwright/helpers/index.js +2 -0
- package/dist/playwright/helpers/rbac-api-helper.d.ts +35 -0
- package/dist/playwright/helpers/rbac-api-helper.d.ts.map +1 -0
- package/dist/playwright/helpers/rbac-api-helper.js +63 -0
- package/package.json +2 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-api-helper.d.ts","sourceRoot":"","sources":["../../../src/playwright/helpers/auth-api-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAGxC,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAO;gBAEhB,IAAI,EAAE,IAAI;IAIhB,QAAQ,CACZ,QAAQ,GAAE,MAAe,EACzB,WAAW,GAAE,MAAqB;CA8BrC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// here, we spy on the request to get the Backstage token to use APIs
|
|
2
|
+
export class AuthApiHelper {
|
|
3
|
+
page;
|
|
4
|
+
constructor(page) {
|
|
5
|
+
this.page = page;
|
|
6
|
+
}
|
|
7
|
+
async getToken(provider = "oidc", environment = "production") {
|
|
8
|
+
try {
|
|
9
|
+
const response = await this.page.request.get(`/api/auth/${provider}/refresh?optional=&scope=&env=${environment}`, {
|
|
10
|
+
headers: {
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
12
|
+
"x-requested-with": "XMLHttpRequest",
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
if (!response.ok()) {
|
|
16
|
+
throw new Error(`HTTP error! Status: ${response.status()}`);
|
|
17
|
+
}
|
|
18
|
+
const body = await response.json();
|
|
19
|
+
if (typeof body?.backstageIdentity?.token === "string") {
|
|
20
|
+
return body.backstageIdentity.token;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
throw new TypeError("Token not found in response body");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
console.error("Failed to retrieve the token:", error);
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -2,4 +2,6 @@ export { GITHUB_API_ENDPOINTS } from "./api-endpoints.js";
|
|
|
2
2
|
export { APIHelper } from "./api-helper.js";
|
|
3
3
|
export { LoginHelper, setupBrowser } from "./common.js";
|
|
4
4
|
export { UIhelper } from "./ui-helper.js";
|
|
5
|
+
export { RbacApiHelper, Policy, Response } from "./rbac-api-helper.js";
|
|
6
|
+
export { AuthApiHelper } from "./auth-api-helper.js";
|
|
5
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/playwright/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/playwright/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -2,3 +2,5 @@ export { GITHUB_API_ENDPOINTS } from "./api-endpoints.js";
|
|
|
2
2
|
export { APIHelper } from "./api-helper.js";
|
|
3
3
|
export { LoginHelper, setupBrowser } from "./common.js";
|
|
4
4
|
export { UIhelper } from "./ui-helper.js";
|
|
5
|
+
export { RbacApiHelper, Response } from "./rbac-api-helper.js";
|
|
6
|
+
export { AuthApiHelper } from "./auth-api-helper.js";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { PermissionAction, RoleConditionalPolicyDecision } from "@backstage-community/plugin-rbac-common";
|
|
2
|
+
import { APIResponse } from "@playwright/test";
|
|
3
|
+
export interface Policy {
|
|
4
|
+
entityReference: string;
|
|
5
|
+
permission: string;
|
|
6
|
+
policy: string;
|
|
7
|
+
effect: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Thin HTTP client for the RHDH RBAC permission API.
|
|
11
|
+
* Uses a static factory (`build`) because the Playwright `APIRequestContext`
|
|
12
|
+
* must be created asynchronously — a constructor cannot await it.
|
|
13
|
+
*/
|
|
14
|
+
export declare class RbacApiHelper {
|
|
15
|
+
private readonly token;
|
|
16
|
+
private readonly apiUrl;
|
|
17
|
+
private readonly authHeader;
|
|
18
|
+
private myContext;
|
|
19
|
+
private constructor();
|
|
20
|
+
/** Creates a fully-initialised instance with a live Playwright request context. */
|
|
21
|
+
static build(token: string): Promise<RbacApiHelper>;
|
|
22
|
+
getPoliciesByRole(policy: string): Promise<APIResponse>;
|
|
23
|
+
/** Fetches all conditional policies across all roles. */
|
|
24
|
+
getConditions(): Promise<APIResponse>;
|
|
25
|
+
/** Filters a full conditions list down to those belonging to a specific role entity ref. */
|
|
26
|
+
getConditionsByRole(role: string, remainingConditions: RoleConditionalPolicyDecision<PermissionAction>[]): Promise<RoleConditionalPolicyDecision<PermissionAction>[]>;
|
|
27
|
+
deleteRole(role: string): Promise<APIResponse>;
|
|
28
|
+
deletePolicy(policy: string, policies: Policy[]): Promise<APIResponse>;
|
|
29
|
+
/** `id` comes from the `RoleConditionalPolicyDecision.id` field returned by the API. */
|
|
30
|
+
deleteCondition(id: string): Promise<APIResponse>;
|
|
31
|
+
}
|
|
32
|
+
export declare class Response {
|
|
33
|
+
static removeMetadataFromResponse(response: APIResponse): Promise<unknown[]>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=rbac-api-helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rbac-api-helper.d.ts","sourceRoot":"","sources":["../../../src/playwright/helpers/rbac-api-helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,6BAA6B,EAC9B,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAqB,WAAW,EAAW,MAAM,kBAAkB,CAAC;AAE3E,MAAM,WAAW,MAAM;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,qBAAa,aAAa;IAUJ,OAAO,CAAC,QAAQ,CAAC,KAAK;IAT1C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkD;IACzE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAKzB;IACF,OAAO,CAAC,SAAS,CAAqB;IAEtC,OAAO;IAOP,mFAAmF;WAC/D,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IASnD,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAIpE,yDAAyD;IAC5C,aAAa,IAAI,OAAO,CAAC,WAAW,CAAC;IAIlD,4FAA4F;IAC/E,mBAAmB,CAC9B,IAAI,EAAE,MAAM,EACZ,mBAAmB,EAAE,6BAA6B,CAAC,gBAAgB,CAAC,EAAE,GACrE,OAAO,CAAC,6BAA6B,CAAC,gBAAgB,CAAC,EAAE,CAAC;IAMhD,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAI9C,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE;IAM5D,wFAAwF;IAC3E,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;CAG/D;AAED,qBAAa,QAAQ;WACN,0BAA0B,CACrC,QAAQ,EAAE,WAAW,GACpB,OAAO,CAAC,OAAO,EAAE,CAAC;CActB"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { request } from "@playwright/test";
|
|
2
|
+
/**
|
|
3
|
+
* Thin HTTP client for the RHDH RBAC permission API.
|
|
4
|
+
* Uses a static factory (`build`) because the Playwright `APIRequestContext`
|
|
5
|
+
* must be created asynchronously — a constructor cannot await it.
|
|
6
|
+
*/
|
|
7
|
+
export class RbacApiHelper {
|
|
8
|
+
token;
|
|
9
|
+
apiUrl = process.env.RHDH_BASE_URL + "/api/permission/";
|
|
10
|
+
authHeader;
|
|
11
|
+
myContext;
|
|
12
|
+
constructor(token) {
|
|
13
|
+
this.token = token;
|
|
14
|
+
this.authHeader = {
|
|
15
|
+
Accept: "application/json",
|
|
16
|
+
Authorization: `Bearer ${this.token}`,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** Creates a fully-initialised instance with a live Playwright request context. */
|
|
20
|
+
static async build(token) {
|
|
21
|
+
const instance = new RbacApiHelper(token);
|
|
22
|
+
instance.myContext = await request.newContext({
|
|
23
|
+
baseURL: instance.apiUrl,
|
|
24
|
+
extraHTTPHeaders: instance.authHeader,
|
|
25
|
+
});
|
|
26
|
+
return instance;
|
|
27
|
+
}
|
|
28
|
+
async getPoliciesByRole(policy) {
|
|
29
|
+
return await this.myContext.get(`policies/role/default/${policy}`);
|
|
30
|
+
}
|
|
31
|
+
/** Fetches all conditional policies across all roles. */
|
|
32
|
+
async getConditions() {
|
|
33
|
+
return await this.myContext.get(`roles/conditions`);
|
|
34
|
+
}
|
|
35
|
+
/** Filters a full conditions list down to those belonging to a specific role entity ref. */
|
|
36
|
+
async getConditionsByRole(role, remainingConditions) {
|
|
37
|
+
return remainingConditions.filter((condition) => condition.roleEntityRef === role);
|
|
38
|
+
}
|
|
39
|
+
async deleteRole(role) {
|
|
40
|
+
return await this.myContext.delete(`roles/role/default/${role}`);
|
|
41
|
+
}
|
|
42
|
+
async deletePolicy(policy, policies) {
|
|
43
|
+
return await this.myContext.delete(`policies/role/default/${policy}`, {
|
|
44
|
+
data: policies,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/** `id` comes from the `RoleConditionalPolicyDecision.id` field returned by the API. */
|
|
48
|
+
async deleteCondition(id) {
|
|
49
|
+
return await this.myContext.delete(`roles/conditions/${id}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export class Response {
|
|
53
|
+
static async removeMetadataFromResponse(response) {
|
|
54
|
+
const responseJson = await response.json();
|
|
55
|
+
if (!Array.isArray(responseJson)) {
|
|
56
|
+
throw new TypeError(`Expected an array from policy response but received: ${JSON.stringify(responseJson)}`);
|
|
57
|
+
}
|
|
58
|
+
return responseJson.map((item) => {
|
|
59
|
+
delete item.metadata;
|
|
60
|
+
return item;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@red-hat-developer-hub/e2e-test-utils",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.15",
|
|
4
4
|
"description": "Test utilities for RHDH E2E tests",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -93,6 +93,7 @@
|
|
|
93
93
|
},
|
|
94
94
|
"dependencies": {
|
|
95
95
|
"@axe-core/playwright": "^4.11.0",
|
|
96
|
+
"@backstage-community/plugin-rbac-common": "1.23.0",
|
|
96
97
|
"@eslint/js": "^9.39.1",
|
|
97
98
|
"@keycloak/keycloak-admin-client": "^26.0.0",
|
|
98
99
|
"@kubernetes/client-node": "^1.4.0",
|