@7365admin1/core 3.52.10 → 3.52.11
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/CHANGELOG.md +6 -0
- package/dist/index.d.ts +11 -1
- package/dist/index.js +12 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/visitor-document-site-scope.test.mjs +82 -0
package/package.json
CHANGED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Two more instances of the `/api/vehicles` defect, found by sweeping every
|
|
8
|
+
* list endpoint the mobile apps call:
|
|
9
|
+
*
|
|
10
|
+
* - `GET /api/visitor-transactions` took an OPTIONAL `site` and the repository
|
|
11
|
+
* applied it only when it parsed as an ObjectId
|
|
12
|
+
* (`visitor-transaction.repo.ts` `...(ObjectId.isValid(site) && ...)`), so a
|
|
13
|
+
* request that named no site was answered from the WHOLE collection — every
|
|
14
|
+
* customer's visitor records. Nothing checked a NAMED site either.
|
|
15
|
+
* - `GET /api/documents` refused a missing site (the repository throws on
|
|
16
|
+
* `new ObjectId("")`) but never checked the caller could reach the site they
|
|
17
|
+
* DID name, so any signed-in user could read any estate's documents by id.
|
|
18
|
+
*
|
|
19
|
+
* The decision itself is `entitledSiteScope` and is covered by
|
|
20
|
+
* `vehicle-site-scope.test.mjs`. What is asserted here is the WIRING, which
|
|
21
|
+
* needs a live Atlas connection to exercise — the same approach
|
|
22
|
+
* `camera-entitlement-wiring.test.mjs` takes.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const read = (p) =>
|
|
26
|
+
readFileSync(fileURLToPath(new URL(p, import.meta.url)), "utf8");
|
|
27
|
+
|
|
28
|
+
const visitorController = read("../src/controllers/visitor-transaction.controller.ts");
|
|
29
|
+
const visitorRepo = read("../src/repositories/visitor-transaction.repo.ts");
|
|
30
|
+
const documentController = read("../src/controllers/document-management.controller.ts");
|
|
31
|
+
|
|
32
|
+
test("the visitor list resolves a scope when no site is named", () => {
|
|
33
|
+
assert.equal(
|
|
34
|
+
visitorController.match(/const siteScope = site \? null : await entitledSites\(req\);/g)?.length,
|
|
35
|
+
1,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
// A named site is still authorised, and never trusted.
|
|
39
|
+
assert.equal(
|
|
40
|
+
visitorController.match(/if \(site\) await requireSiteReach\(req, site\);/g)?.length,
|
|
41
|
+
1,
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
assert.ok(
|
|
45
|
+
/^ {8}siteScope,\s*$/m.test(visitorController),
|
|
46
|
+
"the scope must reach the repository, not be resolved and dropped",
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
assert.ok(
|
|
50
|
+
/import \{ entitledSites, requireSiteReach \} from "\.\.\/utils\/site-reach\.util";/.test(
|
|
51
|
+
visitorController,
|
|
52
|
+
),
|
|
53
|
+
"the rule is the shared one, not a second implementation",
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("the visitor repository applies an empty scope rather than dropping it", () => {
|
|
58
|
+
assert.equal(visitorRepo.match(/^ +\.\.\.\(siteScope\s*$/gm)?.length, 1);
|
|
59
|
+
|
|
60
|
+
// `siteScope && siteScope.length` here would turn "reaches no site" back into
|
|
61
|
+
// "sees everything", which is the whole defect.
|
|
62
|
+
assert.ok(
|
|
63
|
+
!/siteScope\?\.length|siteScope && siteScope\.length/.test(visitorRepo),
|
|
64
|
+
"an empty array must not collapse into the no-restriction branch",
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("the document list authorises the site it is given", () => {
|
|
69
|
+
const getAll = documentController.slice(
|
|
70
|
+
documentController.indexOf("async function getAll("),
|
|
71
|
+
documentController.indexOf("async function getDocumentById("),
|
|
72
|
+
);
|
|
73
|
+
assert.ok(getAll.length > 0, "the list handler must still be called getAll");
|
|
74
|
+
assert.ok(
|
|
75
|
+
/await requireSiteReach\(req, site\);/.test(getAll),
|
|
76
|
+
"the list must check the caller reaches the site it was handed",
|
|
77
|
+
);
|
|
78
|
+
assert.ok(
|
|
79
|
+
getAll.indexOf("requireSiteReach") < getAll.indexOf("_getDocuments"),
|
|
80
|
+
"the check must run BEFORE the read, not after it",
|
|
81
|
+
);
|
|
82
|
+
});
|