@7365admin1/core 3.73.0 → 3.73.1

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@7365admin1/core",
3
3
  "license": "MIT",
4
- "version": "3.73.0",
4
+ "version": "3.73.1",
5
5
  "author": "7365admin1",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -260,6 +260,63 @@ describe("people writes are scoped to a site the caller can reach", { concurrenc
260
260
  assert.equal(res.status, 200, JSON.stringify(res.body));
261
261
  assert.equal((await load(id.residentPerson)).name, "Resubmitted By Themselves");
262
262
  });
263
+
264
+ // ---- creating a person: POST /api/people -------------------------------
265
+ // The signed-in branch of `add` used to check only that somebody was signed
266
+ // in, while `site`/`org` came from the body. The reach gate is enforced by
267
+ // default now; these cases pin both halves of that.
268
+
269
+ const newPerson = (tag) => ({
270
+ name: `Created ${tag}`,
271
+ contact: "90000001",
272
+ type: "guest",
273
+ isOwner: false,
274
+ org: String(id.orgB),
275
+ site: String(id.siteB),
276
+ });
277
+ const countCreated = (tag) =>
278
+ h.db.collection("site.people").countDocuments({ name: `Created ${tag}` });
279
+
280
+ record("13. an outsider cannot create a person at site B", async () => {
281
+ const res = await h.api("/people", { method: "POST", body: newPerson("outsider"), sid: outsiderSid });
282
+
283
+ assert.equal(res.status, 401, JSON.stringify(res.body));
284
+ assert.equal(await countCreated("outsider"), 0, "nothing may be written");
285
+ });
286
+
287
+ record("14. nor by naming only site B's organisation", async () => {
288
+ const { site, ...orgOnly } = newPerson("outsider-org");
289
+ const res = await h.api("/people", { method: "POST", body: orgOnly, sid: outsiderSid });
290
+
291
+ assert.equal(res.status, 401, JSON.stringify(res.body));
292
+ assert.equal(await countCreated("outsider-org"), 0);
293
+ });
294
+
295
+ record("15. the site's own manager CAN create one", async () => {
296
+ // `web-app-property-management components/PeopleFormMgmt.vue` -> `usePeople.create`
297
+ const res = await h.api("/people", { method: "POST", body: newPerson("manager"), sid: managerSid });
298
+
299
+ assert.equal(res.status, 201, JSON.stringify(res.body));
300
+ assert.equal(await countCreated("manager"), 1);
301
+ });
302
+
303
+ record("16. and so can the agency guard posted at site B", async () => {
304
+ // the field guard app registers visitors at the site it is posted to
305
+ const res = await h.api("/people", { method: "POST", body: newPerson("guard"), sid: guardSid });
306
+
307
+ assert.equal(res.status, 201, JSON.stringify(res.body));
308
+ assert.equal(await countCreated("guard"), 1);
309
+ });
310
+
311
+ record("17. log mode is a real kill switch: the outsider is let through", async () => {
312
+ process.env.PEOPLE_CREATE_REACH_MODE = "log";
313
+ try {
314
+ const res = await h.api("/people", { method: "POST", body: newPerson("logmode"), sid: outsiderSid });
315
+ assert.equal(res.status, 201, JSON.stringify(res.body));
316
+ } finally {
317
+ delete process.env.PEOPLE_CREATE_REACH_MODE;
318
+ }
319
+ });
263
320
  });
264
321
 
265
322
  async function seed(h) {
@@ -7,10 +7,9 @@
7
7
  * `site.people` is the collection every site-reach decision reads its verdict
8
8
  * from, so a row written there manufactures reach into another client's estate.
9
9
  *
10
- * This gate ships SWITCHED OFF (`log`): it records what it would refuse and
11
- * refuses nothing, because a person row carries no `createdBy` and the real
12
- * refusal count is only knowable from live traffic. These tests pin that
13
- * default, so it cannot become enforcing by accident.
10
+ * The gate shipped in `log` first and is ENFORCED by default since 2026-09-15,
11
+ * after a staging measurement showed nobody legitimate is refused. These tests
12
+ * pin that default; `log` stays available as the kill switch.
14
13
  */
15
14
  import test from "node:test";
16
15
  import assert from "node:assert/strict";
@@ -21,11 +20,12 @@ import {
21
20
  peopleCreateVerdict,
22
21
  } from "./.build/utils/people-create-gate.util.mjs";
23
22
 
24
- test("the code default is LOG - it must not ship refusing anybody", () => {
25
- assert.equal(PEOPLE_CREATE_REACH_MODE_DEFAULT, "log");
26
- assert.equal(peopleCreateReachMode({}), "log");
27
- // An unrecognised value falls back to the safe default rather than enforcing.
28
- assert.equal(peopleCreateReachMode({ PEOPLE_CREATE_REACH_MODE: "nonsense" }), "log");
23
+ test("the code default is ENFORCE, with log kept as the kill switch", () => {
24
+ assert.equal(PEOPLE_CREATE_REACH_MODE_DEFAULT, "enforce");
25
+ assert.equal(peopleCreateReachMode({}), "enforce");
26
+ // An unrecognised value falls back to the default, so a typo cannot reopen the hole.
27
+ assert.equal(peopleCreateReachMode({ PEOPLE_CREATE_REACH_MODE: "nonsense" }), "enforce");
28
+ assert.equal(peopleCreateReachMode({ PEOPLE_CREATE_REACH_MODE: "log" }), "log");
29
29
  assert.equal(peopleCreateReachMode({ PEOPLE_CREATE_REACH_MODE: "ENFORCE" }), "enforce");
30
30
  assert.equal(peopleCreateReachMode({ PEOPLE_CREATE_REACH_MODE: "off" }), "off");
31
31
  });
@@ -63,9 +63,12 @@ test("OFF does not even look", () => {
63
63
  });
64
64
 
65
65
  test("the flag is the only thing between counting and refusing", () => {
66
- // If this ever fails, the default has been changed and people who can create
67
- // a person today may stop being able to - which is the RP-5 line.
66
+ // The default refuses an unreachable estate; `log` is the kill switch that
67
+ // counts instead. If either half fails, the hole is open or the switch is gone.
68
68
  const unreachable = { reachable: false };
69
- assert.equal(peopleCreateVerdict({ mode: peopleCreateReachMode({}), ...unreachable }).refuse, false);
70
- assert.equal(peopleCreateVerdict({ mode: "enforce", ...unreachable }).refuse, true);
69
+ assert.equal(peopleCreateVerdict({ mode: peopleCreateReachMode({}), ...unreachable }).refuse, true);
70
+ assert.equal(
71
+ peopleCreateVerdict({ mode: peopleCreateReachMode({ PEOPLE_CREATE_REACH_MODE: "log" }), ...unreachable }).refuse,
72
+ false,
73
+ );
71
74
  });