@7365admin1/core 3.53.1 → 3.53.2
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 +9 -1
- package/dist/index.js +50 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +112 -61
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/test/file-delete-scope.test.mjs +64 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@7365admin1/core",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "3.53.
|
|
4
|
+
"version": "3.53.2",
|
|
5
5
|
"author": "7365admin1",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"build": "tsup src/index.ts --format cjs,esm --dts && shx cp -r src/public dist && shx cp -r src/utils/handlebars dist",
|
|
14
14
|
"release": "yarn run build && changeset publish",
|
|
15
15
|
"lint": "tsc",
|
|
16
|
-
"test": "tsup src/config.ts src/utils/anpr-revoke.util.ts src/utils/vehicle-request.util.ts src/utils/camera-view.util.ts src/utils/camera-bulk-import.util.ts src/utils/dashboard-metrics.util.ts src/utils/camera-capability.util.ts src/services/camera-device-http.service.ts src/utils/camera-alert.util.ts src/utils/dahua-protocol.util.ts src/utils/site-name.util.ts src/utils/service-provider-invite.util.ts src/utils/notification-category.util.ts src/utils/hid-card.util.ts src/utils/hid-json.util.ts src/utils/hid-access.util.ts src/models/customer-site.model.ts src/models/site-camera.model.ts src/models/member.model.ts src/models/subscription.model.ts src/utils/session-id.util.ts src/utils/occurrence-query.util.ts src/utils/update-result.util.ts src/utils/hid-amico-authz.util.ts src/utils/promo-code-currency.util.ts src/utils/console-audit.util.ts src/utils/org-suspension.util.ts src/utils/session-revoke.util.ts src/models/hid-amico.model.ts src/models/patrol-email.model.ts src/utils/patrol-email-pdf.util.ts src/utils/visitor-status.util.ts src/utils/self-service-email.util.ts src/utils/hid-secret.util.ts src/models/visitor-invite.model.ts src/models/guard-invite.model.ts src/utils/site-timezone.util.ts src/utils/bulletin-service-apps.util.ts src/models/bulletin-board.model.ts src/utils/vehicle-import.util.ts src/utils/expired-vehicle-sweep.util.ts src/models/vehicle.model.ts src/controllers/chat.controller.ts --format esm --out-dir test/.build --no-dts --silent && node --test test/*.test.mjs",
|
|
16
|
+
"test": "tsup src/config.ts src/utils/anpr-revoke.util.ts src/utils/vehicle-request.util.ts src/utils/camera-view.util.ts src/utils/camera-bulk-import.util.ts src/utils/dashboard-metrics.util.ts src/utils/camera-capability.util.ts src/services/camera-device-http.service.ts src/utils/camera-alert.util.ts src/utils/dahua-protocol.util.ts src/utils/site-name.util.ts src/utils/service-provider-invite.util.ts src/utils/notification-category.util.ts src/utils/hid-card.util.ts src/utils/hid-json.util.ts src/utils/hid-access.util.ts src/models/customer-site.model.ts src/models/site-camera.model.ts src/models/member.model.ts src/models/subscription.model.ts src/utils/session-id.util.ts src/utils/occurrence-query.util.ts src/utils/update-result.util.ts src/utils/hid-amico-authz.util.ts src/utils/promo-code-currency.util.ts src/utils/console-audit.util.ts src/utils/org-suspension.util.ts src/utils/session-revoke.util.ts src/models/hid-amico.model.ts src/models/patrol-email.model.ts src/utils/patrol-email-pdf.util.ts src/utils/visitor-status.util.ts src/utils/self-service-email.util.ts src/utils/hid-secret.util.ts src/models/visitor-invite.model.ts src/models/guard-invite.model.ts src/utils/site-timezone.util.ts src/utils/bulletin-service-apps.util.ts src/models/bulletin-board.model.ts src/utils/vehicle-import.util.ts src/utils/expired-vehicle-sweep.util.ts src/models/vehicle.model.ts src/controllers/chat.controller.ts src/utils/file-owner.util.ts --format esm --out-dir test/.build --no-dts --silent && node --test test/*.test.mjs",
|
|
17
17
|
"test:camera": "yarn test",
|
|
18
18
|
"test:e2e": "yarn build && node --test --test-concurrency=1 --test-timeout=600000 \"test/e2e/*.test.mjs\""
|
|
19
19
|
},
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
|
|
5
|
+
const { fileOwnerId, mayDeleteFile } = await import("./.build/utils/file-owner.util.mjs");
|
|
6
|
+
|
|
7
|
+
const A = "aaaaaaaaaaaaaaaaaaaaaaaa";
|
|
8
|
+
const B = "bbbbbbbbbbbbbbbbbbbbbbbb";
|
|
9
|
+
const ORG_1 = "111111111111111111111111";
|
|
10
|
+
const ORG_2 = "222222222222222222222222";
|
|
11
|
+
|
|
12
|
+
test("a caller deletes their own new file", () => {
|
|
13
|
+
assert.equal(
|
|
14
|
+
mayDeleteFile({ ownerId: A, callerId: A, callerOrgIds: [ORG_1], ownerOrgIds: [ORG_1] }),
|
|
15
|
+
true,
|
|
16
|
+
);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("a caller deletes another tenant's new file — refused", () => {
|
|
20
|
+
assert.equal(
|
|
21
|
+
mayDeleteFile({ ownerId: A, callerId: B, callerOrgIds: [ORG_2], ownerOrgIds: [ORG_1] }),
|
|
22
|
+
false,
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("a legacy row with no ownership behaves unchanged", () => {
|
|
27
|
+
assert.equal(mayDeleteFile({ ownerId: "", callerId: B, callerOrgIds: [ORG_2] }), true);
|
|
28
|
+
assert.equal(fileOwnerId({ name: "old.pdf" }), "");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("same tenant, different person, is still allowed", () => {
|
|
32
|
+
assert.equal(
|
|
33
|
+
mayDeleteFile({ ownerId: A, callerId: B, callerOrgIds: [ORG_2, ORG_1], ownerOrgIds: [ORG_1] }),
|
|
34
|
+
true,
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("an anonymous caller cannot delete a stamped file", () => {
|
|
39
|
+
assert.equal(mayDeleteFile({ ownerId: A, callerId: "", callerOrgIds: [ORG_1] }), false);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("super admin keeps its bypass", () => {
|
|
43
|
+
assert.equal(
|
|
44
|
+
mayDeleteFile({ ownerId: A, callerId: B, callerIsSuperAdmin: true, callerOrgIds: [], ownerOrgIds: [ORG_1] }),
|
|
45
|
+
true,
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("fileOwnerId reads an ObjectId-shaped stamp", () => {
|
|
50
|
+
assert.equal(fileOwnerId({ createdBy: { toString: () => A } }), A);
|
|
51
|
+
assert.equal(fileOwnerId(null), "");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("the controller wires the gate on delete and stamps on upload", () => {
|
|
55
|
+
const src = readFileSync(new URL("../src/controllers/file.controller.ts", import.meta.url), "utf8");
|
|
56
|
+
assert.match(src, /mayDeleteFile/, "delete must consult the ownership gate");
|
|
57
|
+
assert.match(src, /callerId\(req\)/, "the stamp and the gate come from the session, never the body");
|
|
58
|
+
assert.doesNotMatch(src, /req\.body\.createdBy/, "the owner is never taken from the request body");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("the model carries the optional stamp", () => {
|
|
62
|
+
const src = readFileSync(new URL("../src/models/file.model.ts", import.meta.url), "utf8");
|
|
63
|
+
assert.match(src, /createdBy\?:/, "createdBy is optional — no existing row is invalidated");
|
|
64
|
+
});
|