@7365admin1/core 3.124.3 → 3.125.0
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 +22 -0
- package/dist/index.d.ts +31 -6
- package/dist/index.js +12269 -12101
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12403 -12237
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/e2e/invite-site-scope.e2e.test.mjs +351 -0
- package/test/e2e/privilege-escalation.e2e.test.mjs +3 -1
- package/test/invite-origin.test.mjs +1 -1
- package/test/verification-scope.test.mjs +8 -4
package/package.json
CHANGED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
// Guard tests for the invitation subsystem's SITE scope (owner report
|
|
2
|
+
// 2026-09-28, Wing Tai Holdings / The LakeGarden Residences): a site app's
|
|
3
|
+
// Invitations list showed every site's invitations, and the owner's rule
|
|
4
|
+
// "if they are invited in a specific site then make sure they are able to see
|
|
5
|
+
// only those sites that they were invited to".
|
|
6
|
+
//
|
|
7
|
+
// Matrix, against a real in-process MongoDB: one organisation with three sites
|
|
8
|
+
// (A, B, C), invitations at each, an org-level invitation, expired ones, a
|
|
9
|
+
// service provider engaged at A, a second client, and Seven365 staff.
|
|
10
|
+
// list (pending / expired) - by site, by org, org console, counts
|
|
11
|
+
// cancel - only your own site's invitations
|
|
12
|
+
// create - only your own site; never another client's site
|
|
13
|
+
// accept - the membership lands on the invited site only,
|
|
14
|
+
// a cancelled invitation cannot be accepted
|
|
15
|
+
// sites - a site-invited member sees only the invited
|
|
16
|
+
// site(s), even with an organisation-level role;
|
|
17
|
+
// an org admin sees all three.
|
|
18
|
+
//
|
|
19
|
+
// Nothing outside the harness is touched. Run with: yarn test:e2e
|
|
20
|
+
|
|
21
|
+
import { after, before, describe, it } from "node:test";
|
|
22
|
+
import assert from "node:assert/strict";
|
|
23
|
+
import { ObjectId } from "mongodb";
|
|
24
|
+
|
|
25
|
+
import { startHarness } from "./harness.mjs";
|
|
26
|
+
|
|
27
|
+
const PASSWORD = "InviteSiteScope-Passw0rd!";
|
|
28
|
+
const PM = "property_management_agency";
|
|
29
|
+
const U = {
|
|
30
|
+
orgAdmin: "isc-org-admin@e2e.example.com",
|
|
31
|
+
siteA: "isc-site-a@e2e.example.com",
|
|
32
|
+
siteAB: "isc-site-ab@e2e.example.com",
|
|
33
|
+
invitedOrgRole: "isc-invited-org-role@e2e.example.com",
|
|
34
|
+
strayOwner: "isc-stray-owner@e2e.example.com",
|
|
35
|
+
provider: "isc-provider@e2e.example.com",
|
|
36
|
+
staff: "isc-staff@e2e.example.com",
|
|
37
|
+
// the organisation's creator (its owner), with NO membership in it
|
|
38
|
+
owner: "isc-owner@e2e.example.com",
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
describe("invitations and sites: site scope", { concurrency: 1 }, () => {
|
|
42
|
+
let h;
|
|
43
|
+
const sid = {};
|
|
44
|
+
const id = {};
|
|
45
|
+
|
|
46
|
+
before(async () => {
|
|
47
|
+
h = await startHarness();
|
|
48
|
+
Object.assign(id, await seed(h));
|
|
49
|
+
for (const [k, email] of Object.entries(U)) sid[k] = await h.login(email, PASSWORD);
|
|
50
|
+
}, { timeout: 300000 });
|
|
51
|
+
|
|
52
|
+
after(async () => {
|
|
53
|
+
if (h) await h.stop();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const list = (who, { site = "", status = "pending", app = PM, org = id.org } = {}) =>
|
|
57
|
+
h.api(
|
|
58
|
+
`/verifications?status=${status}&type=member-invite&app=${app}&orgId=${org}&siteId=${site}&limit=50`,
|
|
59
|
+
{ sid: sid[who] },
|
|
60
|
+
);
|
|
61
|
+
// A site the caller cannot reach answers like one that does not exist (404),
|
|
62
|
+
// so ids cannot be probed; either refusal is the right answer.
|
|
63
|
+
const refused = (res) => [401, 403, 404].includes(res.status);
|
|
64
|
+
const emails = (res) => res.body.items.map((i) => i.email).sort();
|
|
65
|
+
const sitesOf = (res) => [...new Set(res.body.items.map((i) => String(i.metadata?.siteId ?? "")))];
|
|
66
|
+
|
|
67
|
+
// ---------------------------------------------------------------- lists
|
|
68
|
+
it("1. org admin: site A lists only A's 3 pending invitations", async () => {
|
|
69
|
+
const res = await list("orgAdmin", { site: id.siteA });
|
|
70
|
+
assert.equal(res.status, 200, JSON.stringify(res.body));
|
|
71
|
+
assert.deepEqual(emails(res), ["a1@x.example.com", "a2@x.example.com", "a3@x.example.com"]);
|
|
72
|
+
assert.deepEqual(sitesOf(res), [String(id.siteA)]);
|
|
73
|
+
assert.match(res.body.pageRange, /of 3$/);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("2. org admin: sites B and C show none of A's invitations", async () => {
|
|
77
|
+
for (const [site, expected] of [[id.siteB, ["b1@x.example.com", "isc-joiner@e2e.example.com"]], [id.siteC, ["c1@x.example.com"]]]) {
|
|
78
|
+
const res = await list("orgAdmin", { site });
|
|
79
|
+
assert.equal(res.status, 200, JSON.stringify(res.body));
|
|
80
|
+
assert.deepEqual(emails(res), expected);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("3. expired tab is per site too", async () => {
|
|
85
|
+
const a = await list("orgAdmin", { site: id.siteA, status: "expired" });
|
|
86
|
+
const b = await list("orgAdmin", { site: id.siteB, status: "expired" });
|
|
87
|
+
assert.deepEqual(emails(a), ["ax@x.example.com"]);
|
|
88
|
+
assert.deepEqual(emails(b), ["bx@x.example.com"]);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("4. site-A member: A lists, B and C are refused (401)", async () => {
|
|
92
|
+
assert.equal((await list("siteA", { site: id.siteA })).status, 200);
|
|
93
|
+
for (const site of [id.siteB, id.siteC]) {
|
|
94
|
+
assert.ok(refused(await list("siteA", { site })));
|
|
95
|
+
assert.ok(refused(await list("siteA", { site, status: "expired" })));
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("5. site-A member naming no site gets only A's invitations", async () => {
|
|
100
|
+
const res = await list("siteA");
|
|
101
|
+
assert.equal(res.status, 200, JSON.stringify(res.body));
|
|
102
|
+
assert.deepEqual(sitesOf(res), [String(id.siteA)]);
|
|
103
|
+
assert.equal(res.body.items.length, 3);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("6. A+B member: A and B list, C is refused", async () => {
|
|
107
|
+
assert.equal((await list("siteAB", { site: id.siteA })).status, 200);
|
|
108
|
+
assert.equal((await list("siteAB", { site: id.siteB })).status, 200);
|
|
109
|
+
assert.ok(refused(await list("siteAB", { site: id.siteC })));
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("7. org console (app organization, no site): org admin sees the org-level invitation; a site member sees none", async () => {
|
|
113
|
+
const admin = await list("orgAdmin", { app: "organization" });
|
|
114
|
+
assert.deepEqual(emails(admin), ["org1@x.example.com"]);
|
|
115
|
+
const site = await list("siteA", { app: "organization" });
|
|
116
|
+
assert.equal(site.status, 200);
|
|
117
|
+
assert.deepEqual(emails(site), []);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("8. an engaged service provider cannot list the client's site invitations", async () => {
|
|
121
|
+
assert.ok(refused(await list("provider", { site: id.siteA })));
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("9. another client's site id returns nothing of this org", async () => {
|
|
125
|
+
const res = await list("orgAdmin", { site: id.otherSite });
|
|
126
|
+
assert.ok(refused(res) || (res.status === 200 && res.body.items.length === 0), JSON.stringify(res.body));
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("10. Seven365 staff list any site", async () => {
|
|
130
|
+
const res = await list("staff", { site: id.siteB });
|
|
131
|
+
assert.equal(res.status, 200, JSON.stringify(res.body));
|
|
132
|
+
assert.deepEqual(emails(res), ["b1@x.example.com", "isc-joiner@e2e.example.com"]);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// ---------------------------------------------------------------- cancel
|
|
136
|
+
const cancel = (who, inv) => h.api(`/verifications/${inv}/cancel`, { method: "PUT", sid: sid[who] });
|
|
137
|
+
|
|
138
|
+
it("11. site-A member cannot cancel B's or the org-level invitation", async () => {
|
|
139
|
+
assert.ok(refused(await cancel("siteA", id.inv.b1)));
|
|
140
|
+
assert.ok(refused(await cancel("siteA", id.inv.org1)));
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("12. site-A member cancels A's; org admin cancels C's", async () => {
|
|
144
|
+
assert.equal((await cancel("siteA", id.inv.a3)).status, 200);
|
|
145
|
+
assert.equal((await cancel("orgAdmin", id.inv.c1)).status, 200);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// ---------------------------------------------------------------- create
|
|
149
|
+
const invite = (who, { site, role = id.roleOrgPM, org = id.org, email = `n-${new ObjectId()}@x.example.com` } = {}) =>
|
|
150
|
+
h.api("/auth/invite/member", {
|
|
151
|
+
method: "POST",
|
|
152
|
+
sid: sid[who],
|
|
153
|
+
body: { email, app: PM, org: String(org), role: String(role), siteId: site ? String(site) : "", siteName: site ? "Site" : "" },
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("13. site-A member invites into A, not into B, and not at org level", async () => {
|
|
157
|
+
assert.equal((await invite("siteA", { site: id.siteA })).status, 201);
|
|
158
|
+
assert.ok(refused(await invite("siteA", { site: id.siteB })));
|
|
159
|
+
assert.ok(refused(await invite("siteA", {})));
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("14. nobody can name another client's site on this org's invitation", async () => {
|
|
163
|
+
const res = await invite("orgAdmin", { site: id.otherSite });
|
|
164
|
+
assert.equal(res.status, 400, JSON.stringify(res.body));
|
|
165
|
+
assert.match(JSON.stringify(res.body), /does not belong/);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// ---------------------------------------------------------------- accept
|
|
169
|
+
it("15. a cancelled invitation cannot be accepted", async () => {
|
|
170
|
+
const res = await h.api(`/members/verification/${id.inv.a3}`, { method: "POST", sid: sid.orgAdmin });
|
|
171
|
+
assert.equal(res.status, 400, JSON.stringify(res.body));
|
|
172
|
+
assert.match(JSON.stringify(res.body), /cancelled/);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("16. accepting a site-B invitation lands the membership on B only", async () => {
|
|
176
|
+
const res = await h.api(`/members/verification/${id.inv.bNew}`, { method: "POST", sid: sid.siteA });
|
|
177
|
+
assert.equal(res.status, 201, JSON.stringify(res.body));
|
|
178
|
+
const m = await h.db.collection("members").findOne({ email: "isc-joiner@e2e.example.com" });
|
|
179
|
+
assert.equal(String(m.siteId), String(id.siteB));
|
|
180
|
+
assert.equal(String(m.org), String(id.org));
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// ---------------------------------------------------------------- sites
|
|
184
|
+
const sitesFor = async (who) => {
|
|
185
|
+
const res = await h.api(`/customer-sites?org=${id.org}&status=active&limit=50`, { sid: sid[who] });
|
|
186
|
+
assert.equal(res.status, 200, JSON.stringify(res.body));
|
|
187
|
+
return res.body.items.map((s) => String(s.site ?? s._id)).sort();
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
it("17. sites: org admin sees A, B and C", async () => {
|
|
191
|
+
assert.deepEqual(await sitesFor("orgAdmin"), [id.siteA, id.siteB, id.siteC].map(String).sort());
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("18. sites: site-A member sees only A; A+B member sees A and B", async () => {
|
|
195
|
+
assert.deepEqual(await sitesFor("siteA"), [String(id.siteA)]);
|
|
196
|
+
assert.deepEqual(await sitesFor("siteAB"), [id.siteA, id.siteB].map(String).sort());
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("19. sites: invited to A with an ORGANISATION-level role still sees only A", async () => {
|
|
200
|
+
assert.deepEqual(await sitesFor("invitedOrgRole"), [String(id.siteA)]);
|
|
201
|
+
assert.ok(refused(await list("invitedOrgRole", { site: id.siteB })));
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("20. sites: an org owner whose row carries a stray siteId (no site invitation) keeps every site", async () => {
|
|
205
|
+
assert.deepEqual(await sitesFor("strayOwner"), [id.siteA, id.siteB, id.siteC].map(String).sort());
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it("22. the owner with no membership in the org: lists, invites into and cancels at any of their sites, and sees every site", async () => {
|
|
209
|
+
const res = await list("owner", { site: id.siteB });
|
|
210
|
+
assert.equal(res.status, 200, JSON.stringify(res.body));
|
|
211
|
+
const inv = await invite("owner", { site: id.siteC });
|
|
212
|
+
assert.equal(inv.status, 201, JSON.stringify(inv.body));
|
|
213
|
+
const can = await cancel("owner", id.inv.b1);
|
|
214
|
+
assert.equal(can.status, 200, JSON.stringify(can.body));
|
|
215
|
+
const sites = await h.api(`/sites?org=${id.org}&limit=50`, { sid: sid.owner });
|
|
216
|
+
assert.equal(sites.status, 200, JSON.stringify(sites.body));
|
|
217
|
+
assert.equal(sites.body.items.length, 3);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("23. GET /sites: a site-A member gets only A; the org admin gets all three", async () => {
|
|
221
|
+
const a = await h.api(`/sites?org=${id.org}&limit=50`, { sid: sid.siteA });
|
|
222
|
+
assert.deepEqual(a.body.items.map((s) => String(s._id)), [String(id.siteA)]);
|
|
223
|
+
const all = await h.api(`/sites?org=${id.org}&limit=50`, { sid: sid.orgAdmin });
|
|
224
|
+
assert.equal(all.body.items.length, 3);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it("24. a provider engaged at the client's site A invites its own staff into A (org != site owner), and cancels it", async () => {
|
|
228
|
+
const res = await h.api("/auth/invite/member", {
|
|
229
|
+
method: "POST",
|
|
230
|
+
sid: sid.provider,
|
|
231
|
+
body: { email: `g-${new ObjectId()}@x.example.com`, app: "security_agency", org: String(id.provider), role: String(id.providerRole), siteId: String(id.siteA), siteName: "LakeGarden ISC" },
|
|
232
|
+
});
|
|
233
|
+
assert.equal(res.status, 201, JSON.stringify(res.body));
|
|
234
|
+
const inv = await h.db.collection("verifications").findOne({ "metadata.org": id.provider, status: "pending" });
|
|
235
|
+
assert.ok(inv);
|
|
236
|
+
assert.ok(refused(await cancel("siteA", inv._id)), "the client's site member cannot cancel the provider's invitation");
|
|
237
|
+
assert.equal((await cancel("provider", inv._id)).status, 200);
|
|
238
|
+
// ...but the provider cannot name a client site it does not serve
|
|
239
|
+
const b = await h.api("/auth/invite/member", {
|
|
240
|
+
method: "POST",
|
|
241
|
+
sid: sid.provider,
|
|
242
|
+
body: { email: `g-${new ObjectId()}@x.example.com`, app: "security_agency", org: String(id.provider), role: String(id.providerRole), siteId: String(id.siteB), siteName: "Winsland ISC I" },
|
|
243
|
+
});
|
|
244
|
+
assert.equal(b.status, 400, JSON.stringify(b.body));
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
// ---------------------------------------------------------------- assign role
|
|
248
|
+
const assign = (who, member, role) =>
|
|
249
|
+
h.api(`/members/id/${member}/role/${role}/type/${PM}/org/${id.org}`, { method: "PUT", sid: sid[who] });
|
|
250
|
+
|
|
251
|
+
it("25. assign role: another site's role is refused for a site-C member; this site's / org-wide role is accepted", async () => {
|
|
252
|
+
const other = await assign("orgAdmin", id.memberC, id.roleA);
|
|
253
|
+
assert.equal(other.status, 400, JSON.stringify(other.body));
|
|
254
|
+
assert.match(JSON.stringify(other.body), /different site|belongs to/);
|
|
255
|
+
assert.equal((await assign("orgAdmin", id.memberC, id.roleOrgPM)).status, 200);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it("26. assign role: a site-A admin cannot re-role a site-C member", async () => {
|
|
259
|
+
assert.ok(refused(await assign("siteA", id.memberC, id.roleOrgPM)));
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it("21. a direct request for another site's data is refused", async () => {
|
|
263
|
+
const res = await h.api(`/customer-sites?org=${id.org}&status=active&site=${id.siteC}&limit=50`, { sid: sid.siteA });
|
|
264
|
+
assert.ok(res.status === 401 || res.status === 404 || !res.body.items?.some((s) => String(s.site ?? s._id) === String(id.siteC)), JSON.stringify(res.body));
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
async function seed(h) {
|
|
269
|
+
const now = new Date().toISOString();
|
|
270
|
+
const later = new Date(Date.now() + 72 * 3600e3).toISOString();
|
|
271
|
+
const org = new ObjectId(), other = new ObjectId(), provider = new ObjectId();
|
|
272
|
+
const siteA = new ObjectId(), siteB = new ObjectId(), siteC = new ObjectId(), otherSite = new ObjectId();
|
|
273
|
+
const roleOwner = new ObjectId(), roleOrgPM = new ObjectId(), roleA = new ObjectId(), roleB = new ObjectId();
|
|
274
|
+
const memberC = new ObjectId();
|
|
275
|
+
const roleOrgAdmin = new ObjectId(), staffRole = new ObjectId(), providerRole = new ObjectId();
|
|
276
|
+
|
|
277
|
+
await h.db.collection("organizations").insertMany([
|
|
278
|
+
{ _id: org, name: "Wing ISC", email: "wing-isc@e2e.example.com", type: "org", nature: PM, status: "active", createdAt: now },
|
|
279
|
+
{ _id: other, name: "Other ISC", email: "other-isc@e2e.example.com", type: "org", nature: PM, status: "active", createdAt: now },
|
|
280
|
+
{ _id: provider, name: "Aigle ISC", email: "aigle-isc@e2e.example.com", type: "org", nature: "security_agency", status: "active", createdAt: now },
|
|
281
|
+
]);
|
|
282
|
+
const site = (_id, name, o) => ({ _id, name, org: o, orgId: o, status: "active", createdAt: now });
|
|
283
|
+
await h.db.collection("sites").insertMany([
|
|
284
|
+
site(siteA, "LakeGarden ISC", org), site(siteB, "Winsland ISC I", org), site(siteC, "Winsland ISC II", org), site(otherSite, "Other ISC site", other),
|
|
285
|
+
]);
|
|
286
|
+
// The org's sites as customer-site rows (what the site switcher lists).
|
|
287
|
+
await h.db.collection("customer.sites").insertMany([
|
|
288
|
+
...[[siteA, "LakeGarden ISC"], [siteB, "Winsland ISC I"], [siteC, "Winsland ISC II"]].map(([s, name]) => ({ name, site: s, siteOrg: org, siteOrgName: "Wing ISC", org, status: "active", createdAt: now })),
|
|
289
|
+
{ name: "LakeGarden ISC", site: siteA, siteOrg: org, siteOrgName: "Wing ISC", org: provider, status: "active", createdAt: now },
|
|
290
|
+
]);
|
|
291
|
+
await h.db.collection("roles").insertMany([
|
|
292
|
+
{ _id: roleOwner, name: "owner", type: "organization", org, site: "", permissions: ["*"], default: true, status: "active" },
|
|
293
|
+
{ _id: roleOrgAdmin, name: "Org Admin", type: "organization", org, site: "", permissions: ["*"], status: "active" },
|
|
294
|
+
{ _id: roleOrgPM, name: "Org-wide PM", type: PM, org, site: "", permissions: ["*"], status: "active" },
|
|
295
|
+
{ _id: roleA, name: "Site Super Admin", type: PM, org, site: siteA, permissions: ["*"], status: "active" },
|
|
296
|
+
{ _id: roleB, name: "Site B Admin", type: PM, org, site: siteB, permissions: ["*"], status: "active" },
|
|
297
|
+
{ _id: staffRole, name: "Super Admin", type: "admin", default: true, permissions: [], status: "active" },
|
|
298
|
+
{ _id: providerRole, name: "owner", type: "security_agency", org: provider, site: "", permissions: ["*"], status: "active" },
|
|
299
|
+
]);
|
|
300
|
+
for (const o of [org, provider]) {
|
|
301
|
+
await h.db.collection("subscriptions").insertOne({ org: o, type: "organization", status: "active", maxSeats: 0, paidSeats: 0, currentSeats: 0, createdAt: now });
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const users = {};
|
|
305
|
+
for (const [k, email] of Object.entries({ ...U, joiner: "isc-joiner@e2e.example.com" })) {
|
|
306
|
+
const { insertedId } = await h.db.collection("users").insertOne({ email, name: k, status: "active", createdAt: now });
|
|
307
|
+
await h.db.collection("users").updateOne({ _id: insertedId }, { $set: { password: await h.hashPassword(PASSWORD) } });
|
|
308
|
+
users[k] = insertedId;
|
|
309
|
+
}
|
|
310
|
+
await h.db.collection("organizations").updateOne({ _id: org }, { $set: { createdBy: users.owner } });
|
|
311
|
+
const m = (user, extra) => ({ user, email: Object.values(U).find(() => false) ?? "", org, type: PM, status: "active", createdAt: now, ...extra });
|
|
312
|
+
await h.db.collection("members").insertMany([
|
|
313
|
+
{ ...m(users.orgAdmin), email: U.orgAdmin, role: roleOwner },
|
|
314
|
+
{ ...m(users.siteA), email: U.siteA, role: roleA, siteId: siteA, siteName: "LakeGarden ISC" },
|
|
315
|
+
{ ...m(users.siteAB), email: U.siteAB, role: roleA, siteId: siteA, siteName: "LakeGarden ISC" },
|
|
316
|
+
{ ...m(users.siteAB), email: U.siteAB, role: roleB, siteId: siteB, siteName: "Winsland ISC I" },
|
|
317
|
+
// invited to A, but offered an organisation-level role
|
|
318
|
+
{ ...m(users.invitedOrgRole), email: U.invitedOrgRole, type: "organization", role: roleOrgAdmin, siteId: siteA, siteName: "LakeGarden ISC" },
|
|
319
|
+
// an org owner row with a stray siteId and no site invitation (owner rule 2026-09-02)
|
|
320
|
+
{ ...m(users.strayOwner), email: U.strayOwner, type: "organization", role: roleOwner, siteId: siteB, siteName: "Winsland ISC I" },
|
|
321
|
+
{ user: users.provider, email: U.provider, org: provider, type: "security_agency", role: providerRole, status: "active", createdAt: now },
|
|
322
|
+
// the owner belongs to another organisation only (a session needs one); none in this one
|
|
323
|
+
{ user: users.owner, email: U.owner, org: other, type: PM, role: roleOrgPM, status: "active", createdAt: now },
|
|
324
|
+
{ _id: memberC, ...m(users.joiner), email: "isc-c-member@e2e.example.com", role: roleOrgPM, siteId: siteC, siteName: "Winsland ISC II" },
|
|
325
|
+
{ user: users.staff, email: U.staff, type: "admin", role: staffRole, status: "active", createdAt: now },
|
|
326
|
+
]);
|
|
327
|
+
|
|
328
|
+
const inv = {};
|
|
329
|
+
const v = (key, email, status, site, app = PM, expireAt = later) => {
|
|
330
|
+
inv[key] = new ObjectId();
|
|
331
|
+
return {
|
|
332
|
+
_id: inv[key], type: "member-invite", email, status, createdAt: now, expireAt,
|
|
333
|
+
metadata: { app, org, role: !site ? roleOwner : String(site) === String(siteA) ? roleA : String(site) === String(siteB) ? roleB : roleOrgPM, name: "", siteId: site ?? "", siteName: site ? "Site" : "" },
|
|
334
|
+
};
|
|
335
|
+
};
|
|
336
|
+
await h.db.collection("verifications").insertMany([
|
|
337
|
+
v("a1", "a1@x.example.com", "pending", siteA),
|
|
338
|
+
v("a2", "a2@x.example.com", "pending", siteA),
|
|
339
|
+
v("a3", "a3@x.example.com", "pending", siteA),
|
|
340
|
+
v("b1", "b1@x.example.com", "pending", siteB),
|
|
341
|
+
v("c1", "c1@x.example.com", "pending", siteC),
|
|
342
|
+
v("ax", "ax@x.example.com", "expired", siteA),
|
|
343
|
+
v("bx", "bx@x.example.com", "expired", siteB),
|
|
344
|
+
v("org1", "org1@x.example.com", "pending", null, "organization"),
|
|
345
|
+
v("bNew", "isc-joiner@e2e.example.com", "pending", siteB),
|
|
346
|
+
// provenance: the org-role member's accepted invitation into site A
|
|
347
|
+
{ ...v("done", U.invitedOrgRole, "complete", siteA, "organization"), metadata: { app: "organization", org, role: roleOrgAdmin, siteId: siteA, siteName: "LakeGarden ISC" } },
|
|
348
|
+
]);
|
|
349
|
+
|
|
350
|
+
return { memberC, org, other, provider, providerRole, siteA, siteB, siteC, otherSite, roleOrgPM, roleA, inv };
|
|
351
|
+
}
|
|
@@ -202,7 +202,9 @@ describe("privilege escalation to platform staff, end to end", { concurrency: 1
|
|
|
202
202
|
{ method: "PUT", sid: mallorySid },
|
|
203
203
|
);
|
|
204
204
|
|
|
205
|
-
|
|
205
|
+
// 400 since 2026-09-28: the role-fits-this-membership check
|
|
206
|
+
// (`requireRoleAssignable`) refuses a console role before the service does.
|
|
207
|
+
assert.ok([400, 401].includes(res.status), JSON.stringify(res.body));
|
|
206
208
|
|
|
207
209
|
const after = await h.db.collection("members").findOne({ _id: id.malloryMember });
|
|
208
210
|
assert.equal(
|
|
@@ -37,6 +37,6 @@ test("every member/user invite handler records its origin after its reach check"
|
|
|
37
37
|
test("the list endpoint takes origin and gates it to Seven365 staff", () => {
|
|
38
38
|
const v1 = src("controllers/verification.controller.ts");
|
|
39
39
|
assert.match(v1, /origin: Joi\.string\(\)\.valid\(SEVEN365_INVITE_ORIGIN\)/);
|
|
40
|
-
assert.match(v1, /requireVerificationListReach\(req
|
|
40
|
+
assert.match(v1, /requireVerificationListReach\(\s*req,\s*origin \? null : orgId,/);
|
|
41
41
|
assert.match(src("repositories/verification.repo.ts"), /seven365InviteQuery\(\)/);
|
|
42
42
|
});
|
|
@@ -72,16 +72,20 @@ test("the cancel gate reads the STORED verification, never the request", () => {
|
|
|
72
72
|
test("the v1 list gate is handed the caller's own orgId, not a literal", () => {
|
|
73
73
|
const body = fn(v1, "getVerifications");
|
|
74
74
|
// Seven365's own list (origin) is staff-only whatever org is named.
|
|
75
|
-
assert.match(body, /requireVerificationListReach\(req
|
|
75
|
+
assert.match(body, /requireVerificationListReach\(\s*req,\s*origin \? null : orgId,\s*origin \? null : siteId\s*\)/);
|
|
76
|
+
// The site scope the gate returns is what the repository filters by.
|
|
77
|
+
assert.match(body, /siteIds: scope\.siteIds/);
|
|
76
78
|
});
|
|
77
79
|
|
|
78
80
|
test("an omitted organisation costs Seven365 staff identity", () => {
|
|
79
81
|
const gate = fn(consoleAuthz, "requireVerificationListReach");
|
|
80
82
|
assert.ok(gate.includes("requireOrgReach(req, orgId)"), "the org branch is gone");
|
|
81
83
|
assert.ok(gate.includes("requirePlatformStaff(req)"), "the estate-wide branch is gone");
|
|
82
|
-
// The
|
|
83
|
-
// staff identity as well and every
|
|
84
|
-
assert.match(gate, /
|
|
84
|
+
// The staff branch runs only when NO org is named, or a reaching member would
|
|
85
|
+
// be asked for staff identity as well and every invitations screen would 401.
|
|
86
|
+
assert.match(gate, /if \(!orgId\) \{\s*await requirePlatformStaff\(req\);\s*return \{\};/);
|
|
87
|
+
// A named site must be reachable (owner report 2026-09-28).
|
|
88
|
+
assert.match(gate, /if \(siteId\) \{\s*await requireSiteReachInOrg\(req, siteId, orgId\);/);
|
|
85
89
|
});
|
|
86
90
|
|
|
87
91
|
test("a verification that names no organisation behaves exactly as before", () => {
|