@webiny/api-core-testing 0.0.0-unstable.7c2def32a7 → 0.0.0-unstable.a85ef555b2
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.
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
import { Abstraction } from "@webiny/di";
|
|
2
2
|
import type { IAuthorizer } from "@webiny/api-core/features/security/authorization/Authorizer/abstractions.js";
|
|
3
3
|
import type { SecurityPermission } from "@webiny/api-core/types/security.js";
|
|
4
|
-
import type { IdentityData } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
4
|
+
import type { Identity, IdentityData } from "@webiny/api-core/features/security/IdentityContext/index.js";
|
|
5
5
|
/**
|
|
6
6
|
* The permissions granted to the test identity, wrapped in a holder so DI treats it as a single
|
|
7
7
|
* value (not a multiple-binding of SecurityPermission):
|
|
8
8
|
* `container.registerInstance(TestPermissions, { list: [{ name: "*" }] })`.
|
|
9
|
+
*
|
|
10
|
+
* `byIdentity` grants other identities their own permissions (by identity id), for code that
|
|
11
|
+
* evaluates another user through `IdentityContext.withIdentity`. Other identities not listed get
|
|
12
|
+
* no permissions.
|
|
9
13
|
*/
|
|
10
14
|
export interface TestPermissionsHolder {
|
|
11
15
|
list: SecurityPermission[];
|
|
16
|
+
byIdentity?: Record<string, SecurityPermission[]>;
|
|
12
17
|
}
|
|
13
18
|
export declare const TestPermissions: Abstraction<TestPermissionsHolder>;
|
|
14
19
|
declare class TestAuthorizerImpl implements IAuthorizer {
|
|
15
20
|
private permissions;
|
|
16
|
-
private
|
|
17
|
-
constructor(permissions: TestPermissionsHolder,
|
|
18
|
-
authorize(): Promise<SecurityPermission[] | null>;
|
|
21
|
+
private requestIdentity;
|
|
22
|
+
constructor(permissions: TestPermissionsHolder, requestIdentity: IdentityData | null);
|
|
23
|
+
authorize(identity: Identity): Promise<SecurityPermission[] | null>;
|
|
24
|
+
private isRequestIdentity;
|
|
19
25
|
}
|
|
20
26
|
export declare const TestAuthorizer: typeof TestAuthorizerImpl & {
|
|
21
27
|
__abstraction: Abstraction<IAuthorizer>;
|
package/mocks/TestAuthorizer.js
CHANGED
|
@@ -3,14 +3,22 @@ import { Authorizer } from "@webiny/api-core/features/security/authorization/Aut
|
|
|
3
3
|
import { TestIdentity } from "./TestAuthenticator.js";
|
|
4
4
|
const TestPermissions = new Abstraction("TestPermissions");
|
|
5
5
|
class TestAuthorizerImpl {
|
|
6
|
-
constructor(permissions,
|
|
6
|
+
constructor(permissions, requestIdentity){
|
|
7
7
|
this.permissions = permissions;
|
|
8
|
-
this.
|
|
8
|
+
this.requestIdentity = requestIdentity;
|
|
9
9
|
}
|
|
10
|
-
async authorize() {
|
|
11
|
-
if (this.
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
async authorize(identity) {
|
|
11
|
+
if (this.isRequestIdentity(identity)) {
|
|
12
|
+
if (this.permissions.list.length > 0) return this.permissions.list;
|
|
13
|
+
if ("api-key" === identity.type) return identity.permissions;
|
|
14
|
+
return this.permissions.list;
|
|
15
|
+
}
|
|
16
|
+
if ("api-key" === identity.type) return null;
|
|
17
|
+
return this.permissions.byIdentity?.[identity.id] ?? [];
|
|
18
|
+
}
|
|
19
|
+
isRequestIdentity(identity) {
|
|
20
|
+
if (!this.requestIdentity) return identity.isAnonymous();
|
|
21
|
+
return identity.id === this.requestIdentity.id;
|
|
14
22
|
}
|
|
15
23
|
}
|
|
16
24
|
const TestAuthorizer = Authorizer.createImplementation({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mocks/TestAuthorizer.js","sources":["../../src/mocks/TestAuthorizer.ts"],"sourcesContent":["import { Abstraction } from \"@webiny/di\";\nimport { Authorizer } from \"@webiny/api-core/features/security/authorization/Authorizer/abstractions.js\";\nimport type { IAuthorizer } from \"@webiny/api-core/features/security/authorization/Authorizer/abstractions.js\";\nimport type { SecurityPermission } from \"@webiny/api-core/types/security.js\";\nimport type {
|
|
1
|
+
{"version":3,"file":"mocks/TestAuthorizer.js","sources":["../../src/mocks/TestAuthorizer.ts"],"sourcesContent":["import { Abstraction } from \"@webiny/di\";\nimport { Authorizer } from \"@webiny/api-core/features/security/authorization/Authorizer/abstractions.js\";\nimport type { IAuthorizer } from \"@webiny/api-core/features/security/authorization/Authorizer/abstractions.js\";\nimport type { SecurityPermission } from \"@webiny/api-core/types/security.js\";\nimport type {\n Identity,\n IdentityData\n} from \"@webiny/api-core/features/security/IdentityContext/index.js\";\nimport { TestIdentity } from \"./TestAuthenticator.js\";\n\n/**\n * The permissions granted to the test identity, wrapped in a holder so DI treats it as a single\n * value (not a multiple-binding of SecurityPermission):\n * `container.registerInstance(TestPermissions, { list: [{ name: \"*\" }] })`.\n *\n * `byIdentity` grants other identities their own permissions (by identity id), for code that\n * evaluates another user through `IdentityContext.withIdentity`. Other identities not listed get\n * no permissions.\n */\nexport interface TestPermissionsHolder {\n list: SecurityPermission[];\n byIdentity?: Record<string, SecurityPermission[]>;\n}\n\nexport const TestPermissions = new Abstraction<TestPermissionsHolder>(\"TestPermissions\");\n\nclass TestAuthorizerImpl implements IAuthorizer {\n constructor(\n private permissions: TestPermissionsHolder,\n private requestIdentity: IdentityData | null\n ) {}\n\n async authorize(identity: Identity): Promise<SecurityPermission[] | null> {\n if (this.isRequestIdentity(identity)) {\n if (this.permissions.list.length > 0) {\n return this.permissions.list;\n }\n // An API-key request identity with embedded permissions (mirrors ApiKeyAuthorizer).\n if (identity.type === \"api-key\") {\n return identity.permissions;\n }\n return this.permissions.list;\n }\n // A real API key authenticated during the test: leave it to api-core's ApiKeyAuthorizer.\n if (identity.type === \"api-key\") {\n return null;\n }\n // Another identity (withIdentity): only what the test granted it (R70).\n return this.permissions.byIdentity?.[identity.id] ?? [];\n }\n\n private isRequestIdentity(identity: Identity): boolean {\n if (!this.requestIdentity) {\n return identity.isAnonymous();\n }\n return identity.id === this.requestIdentity.id;\n }\n}\n\nexport const TestAuthorizer = Authorizer.createImplementation({\n implementation: TestAuthorizerImpl,\n dependencies: [TestPermissions, TestIdentity]\n});\n"],"names":["TestPermissions","Abstraction","TestAuthorizerImpl","permissions","requestIdentity","identity","TestAuthorizer","Authorizer","TestIdentity"],"mappings":";;;AAwBO,MAAMA,kBAAkB,IAAIC,YAAmC;AAEtE,MAAMC;IACF,YACYC,WAAkC,EAClCC,eAAoC,CAC9C;aAFUD,WAAW,GAAXA;aACAC,eAAe,GAAfA;IACT;IAEH,MAAM,UAAUC,QAAkB,EAAwC;QACtE,IAAI,IAAI,CAAC,iBAAiB,CAACA,WAAW;YAClC,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,GAAG,GAC/B,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI;YAGhC,IAAIA,AAAkB,cAAlBA,SAAS,IAAI,EACb,OAAOA,SAAS,WAAW;YAE/B,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI;QAChC;QAEA,IAAIA,AAAkB,cAAlBA,SAAS,IAAI,EACb,OAAO;QAGX,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,CAACA,SAAS,EAAE,CAAC,IAAI,EAAE;IAC3D;IAEQ,kBAAkBA,QAAkB,EAAW;QACnD,IAAI,CAAC,IAAI,CAAC,eAAe,EACrB,OAAOA,SAAS,WAAW;QAE/B,OAAOA,SAAS,EAAE,KAAK,IAAI,CAAC,eAAe,CAAC,EAAE;IAClD;AACJ;AAEO,MAAMC,iBAAiBC,WAAW,oBAAoB,CAAC;IAC1D,gBAAgBL;IAChB,cAAc;QAACF;QAAiBQ;KAAa;AACjD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-core-testing",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.a85ef555b2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -15,13 +15,13 @@
|
|
|
15
15
|
"author": "Webiny Ltd.",
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@webiny/api-core": "0.0.0-unstable.
|
|
18
|
+
"@webiny/api-core": "0.0.0-unstable.a85ef555b2",
|
|
19
19
|
"@webiny/di": "2.0.0",
|
|
20
|
-
"@webiny/event-handler-core": "0.0.0-unstable.
|
|
21
|
-
"@webiny/feature": "0.0.0-unstable.
|
|
20
|
+
"@webiny/event-handler-core": "0.0.0-unstable.a85ef555b2",
|
|
21
|
+
"@webiny/feature": "0.0.0-unstable.a85ef555b2"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@webiny/build-tools": "0.0.0-unstable.
|
|
24
|
+
"@webiny/build-tools": "0.0.0-unstable.a85ef555b2",
|
|
25
25
|
"rimraf": "6.1.3",
|
|
26
26
|
"typescript": "7.0.2"
|
|
27
27
|
},
|