@blossm/permissions-lookup 0.0.179 → 0.0.181
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/index.js +7 -1
- package/package.json +12 -12
- package/test/index.js +64 -0
- package/LICENSE +0 -21
package/index.js
CHANGED
|
@@ -23,7 +23,13 @@ export default ({ downloadFileFn }) => async ({
|
|
|
23
23
|
}) => {
|
|
24
24
|
if (!principal) throw forbidden.message("Missing required permissions.");
|
|
25
25
|
|
|
26
|
-
const cacheKey = `${cacheKeyPrefix}.${
|
|
26
|
+
const cacheKey = `${cacheKeyPrefix}.${JSON.stringify([
|
|
27
|
+
process.env.NETWORK,
|
|
28
|
+
principal.root,
|
|
29
|
+
principal.service,
|
|
30
|
+
principal.network,
|
|
31
|
+
context ? [context.root, context.service, context.network] : null,
|
|
32
|
+
])}`;
|
|
27
33
|
|
|
28
34
|
//Lookup permissions in cache. If found, use them.
|
|
29
35
|
let { permissions: cachedPermissions } =
|
package/package.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blossm/permissions-lookup",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.181",
|
|
4
4
|
"description": "Looks up permissions for a role.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": "blossm.network",
|
|
8
8
|
"engines": {
|
|
9
|
-
"node": ">=
|
|
9
|
+
"node": ">= 24.22.1"
|
|
10
10
|
},
|
|
11
11
|
"publishConfig": {
|
|
12
12
|
"access": "public"
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
|
-
"test": "
|
|
15
|
+
"test": "mocha --recursive"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@blossm/errors": "^0.0.
|
|
19
|
-
"@blossm/fact-rpc": "^0.0.
|
|
20
|
-
"@blossm/
|
|
21
|
-
"@blossm/
|
|
22
|
-
"@blossm/
|
|
23
|
-
"
|
|
18
|
+
"@blossm/errors": "^0.0.41",
|
|
19
|
+
"@blossm/fact-rpc": "^0.0.212",
|
|
20
|
+
"@blossm/node-external-token": "^0.0.206",
|
|
21
|
+
"@blossm/redis": "^0.0.17",
|
|
22
|
+
"@blossm/role-permissions": "^0.0.31",
|
|
23
|
+
"@blossm/uuid": "^0.0.11",
|
|
24
|
+
"yaml": "^2.9.1"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
|
-
"mocha": "^
|
|
27
|
-
}
|
|
28
|
-
"gitHead": "f58d526fd2a4be52946a0b8474d47b64f2b3b0fd"
|
|
27
|
+
"mocha": "^12.0.3"
|
|
28
|
+
}
|
|
29
29
|
}
|
package/test/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { replace, restore } from "sinon";
|
|
3
|
+
import redis from "@blossm/redis";
|
|
4
|
+
import permissionsLookup from "../index.js";
|
|
5
|
+
import factDeps from "../../../../rpc/fact/deps.js";
|
|
6
|
+
|
|
7
|
+
const principal = { root: "user", service: "core", network: "example.test" };
|
|
8
|
+
const contextA = { root: "A", service: "core", network: "example.test" };
|
|
9
|
+
const contextB = { ...contextA, root: "B" };
|
|
10
|
+
const permission = { service: "core", domain: "document", privilege: "read" };
|
|
11
|
+
|
|
12
|
+
describe("Contextual permission cache", () => {
|
|
13
|
+
let network;
|
|
14
|
+
let lookup;
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
network = process.env.NETWORK;
|
|
17
|
+
process.env.NETWORK = "example.test";
|
|
18
|
+
const cache = new Map();
|
|
19
|
+
replace(redis, "readObject", async (key) => cache.get(key));
|
|
20
|
+
replace(redis, "writeObject", async (key, value) => cache.set(key, value));
|
|
21
|
+
replace(redis, "setExpiry", async () => {});
|
|
22
|
+
replace(factDeps, "rpc", ({ operationNameComponents: [name] }) => ({
|
|
23
|
+
get: () => ({
|
|
24
|
+
in: () => ({
|
|
25
|
+
with: async () => ({
|
|
26
|
+
body:
|
|
27
|
+
name === "roles"
|
|
28
|
+
? [{ id: "reader", subject: contextA }]
|
|
29
|
+
: [permission],
|
|
30
|
+
}),
|
|
31
|
+
}),
|
|
32
|
+
}),
|
|
33
|
+
}));
|
|
34
|
+
lookup = permissionsLookup({ downloadFileFn: async () => {} });
|
|
35
|
+
});
|
|
36
|
+
afterEach(() => {
|
|
37
|
+
restore();
|
|
38
|
+
if (network === undefined) delete process.env.NETWORK;
|
|
39
|
+
else process.env.NETWORK = network;
|
|
40
|
+
});
|
|
41
|
+
it("does not grant A's permissions in B", async () => {
|
|
42
|
+
expect(await lookup({ principal, context: contextA })).to.deep.equal([
|
|
43
|
+
permission,
|
|
44
|
+
]);
|
|
45
|
+
expect(await lookup({ principal, context: contextB })).to.deep.equal([]);
|
|
46
|
+
});
|
|
47
|
+
it("does not reuse B's missing permissions in A", async () => {
|
|
48
|
+
expect(await lookup({ principal, context: contextB })).to.deep.equal([]);
|
|
49
|
+
expect(await lookup({ principal, context: contextA })).to.deep.equal([
|
|
50
|
+
permission,
|
|
51
|
+
]);
|
|
52
|
+
});
|
|
53
|
+
it("distinguishes unscoped and scoped permissions", async () => {
|
|
54
|
+
expect(await lookup({ principal })).to.deep.equal([permission]);
|
|
55
|
+
expect(await lookup({ principal, context: contextB })).to.deep.equal([]);
|
|
56
|
+
});
|
|
57
|
+
it("distinguishes the network whose roles are being resolved", async () => {
|
|
58
|
+
expect(await lookup({ principal, context: contextA })).to.deep.equal([
|
|
59
|
+
permission,
|
|
60
|
+
]);
|
|
61
|
+
process.env.NETWORK = "another.test";
|
|
62
|
+
expect(await lookup({ principal, context: contextA })).to.deep.equal([]);
|
|
63
|
+
});
|
|
64
|
+
});
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2020 Blossm
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|