@7365admin1/core 3.106.0 → 3.107.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 +6 -0
- package/dist/index.d.ts +21 -6
- package/dist/index.js +22 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/e2e/invite-roles-owner-reach.e2e.test.mjs +73 -0
- package/test/notification-email.util.test.mjs +67 -0
package/package.json
CHANGED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Regression (prod 2026-09-25, Wing Tai / Winsland House I): the Invite member
|
|
2
|
+
// dialog's own request
|
|
3
|
+
// GET /api/roles?search&page=1&limit=100&type=property_management_agency&org=<org>&site=<site>
|
|
4
|
+
// must answer 200 with the organisation's roles for every way an owner/admin
|
|
5
|
+
// reaches their organisation. Run with: yarn test:e2e
|
|
6
|
+
import { after, before, describe, it } from "node:test";
|
|
7
|
+
import assert from "node:assert/strict";
|
|
8
|
+
import { ObjectId } from "mongodb";
|
|
9
|
+
import { startHarness } from "./harness.mjs";
|
|
10
|
+
|
|
11
|
+
const PASSWORD = "OwnerReach-Passw0rd!";
|
|
12
|
+
const PM = "property_management_agency";
|
|
13
|
+
const CASES = [
|
|
14
|
+
["PM member holding a '*' owner role", "pm-star@e2e.example.com", { type: PM, role: "pmOwner" }],
|
|
15
|
+
["org-console member holding an EMPTY-permission owner role", "org-empty@e2e.example.com", { type: "organization", role: "orgOwnerEmpty" }],
|
|
16
|
+
["member pinned to this site", "pinned@e2e.example.com", { type: PM, role: "pmOwner", pinSite: true }],
|
|
17
|
+
["org creator with no membership row yet", "creator@e2e.example.com", { creator: true }],
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
describe("Invite member role list: owner/admin reach", { concurrency: 1 }, () => {
|
|
21
|
+
let h; const id = {};
|
|
22
|
+
before(async () => { h = await startHarness(); Object.assign(id, await seed(h)); }, { timeout: 300000 });
|
|
23
|
+
after(async () => { if (h) await h.stop(); });
|
|
24
|
+
|
|
25
|
+
for (const [name, email] of CASES) {
|
|
26
|
+
it(`${name}: 200 with the org's roles`, async () => {
|
|
27
|
+
const sid = await h.login(email, PASSWORD);
|
|
28
|
+
const res = await h.api(`/roles?search&page=1&limit=100&type=${PM}&org=${id.org}&site=${id.site}`, { sid });
|
|
29
|
+
assert.equal(res.status, 200, JSON.stringify(res.body));
|
|
30
|
+
const names = res.body.items.map((r) => r.name).sort();
|
|
31
|
+
assert.ok(names.includes("owner"), JSON.stringify(names));
|
|
32
|
+
assert.equal(names.includes("Other site role"), false);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
it("CONTROL: a member of ANOTHER organisation is refused", async () => {
|
|
37
|
+
const sid = await h.login("outsider@e2e.example.com", PASSWORD);
|
|
38
|
+
const res = await h.api(`/roles?search&page=1&limit=100&type=${PM}&org=${id.org}&site=${id.site}`, { sid });
|
|
39
|
+
assert.equal(res.status, 401);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
async function seed(h) {
|
|
44
|
+
const now = new Date().toISOString();
|
|
45
|
+
const org = new ObjectId(), other = new ObjectId(), site = new ObjectId(), site2 = new ObjectId();
|
|
46
|
+
const r = { pmOwner: new ObjectId(), orgOwnerEmpty: new ObjectId(), otherSite: new ObjectId(), otherOrg: new ObjectId() };
|
|
47
|
+
const emails = [...CASES.map((c) => c[1]), "outsider@e2e.example.com"];
|
|
48
|
+
const users = await h.db.collection("users").insertMany(emails.map((email) => ({ email, name: email.split("@")[0], status: "active", createdAt: now })));
|
|
49
|
+
const uid = (e) => users.insertedIds[emails.indexOf(e)];
|
|
50
|
+
await h.db.collection("users").updateMany({ email: { $in: emails } }, { $set: { password: await h.hashPassword(PASSWORD) } });
|
|
51
|
+
await h.db.collection("organizations").insertMany([
|
|
52
|
+
{ _id: org, name: "Wing E2E", email: "wing-org@e2e.example.com", type: "org", nature: PM, status: "active", createdBy: uid("creator@e2e.example.com"), createdAt: now },
|
|
53
|
+
{ _id: other, name: "Other E2E", email: "other-org@e2e.example.com", type: "org", nature: PM, status: "active", createdAt: now },
|
|
54
|
+
]);
|
|
55
|
+
await h.db.collection("sites").insertMany([
|
|
56
|
+
{ _id: site, name: "Winsland E2E I", org, orgId: org, status: "active" },
|
|
57
|
+
{ _id: site2, name: "Winsland E2E II", org, orgId: org, status: "active" },
|
|
58
|
+
]);
|
|
59
|
+
await h.db.collection("roles").insertMany([
|
|
60
|
+
{ _id: r.pmOwner, name: "owner", type: PM, org, site: "", permissions: ["*"], default: true, status: "active" },
|
|
61
|
+
{ _id: r.orgOwnerEmpty, name: "owner", type: "organization", org, site: "", permissions: [], default: true, status: "active" },
|
|
62
|
+
{ _id: r.otherSite, name: "Other site role", type: PM, org, site: site2, permissions: [], status: "active" },
|
|
63
|
+
{ _id: r.otherOrg, name: "owner", type: PM, org: other, site: "", permissions: ["*"], status: "active" },
|
|
64
|
+
]);
|
|
65
|
+
const rows = [];
|
|
66
|
+
for (const [, email, m] of CASES) {
|
|
67
|
+
if (m.creator) continue;
|
|
68
|
+
rows.push({ user: uid(email), org, type: m.type, role: r[m.role], status: "active", ...(m.pinSite ? { siteId: site } : {}) });
|
|
69
|
+
}
|
|
70
|
+
rows.push({ user: uid("outsider@e2e.example.com"), org: other, type: PM, role: r.otherOrg, status: "active" });
|
|
71
|
+
await h.db.collection("members").insertMany(rows);
|
|
72
|
+
return { org, site };
|
|
73
|
+
}
|
|
@@ -7,10 +7,12 @@ import {
|
|
|
7
7
|
DEFAULT_EMAIL_ALLOWLIST,
|
|
8
8
|
EMAIL_PER_MODULE_PER_HOUR,
|
|
9
9
|
codeMatches,
|
|
10
|
+
effectiveEmailAllowlist,
|
|
10
11
|
emailOpenToEveryone,
|
|
11
12
|
escapeHtml,
|
|
12
13
|
hashCode,
|
|
13
14
|
isEmailAllowed,
|
|
15
|
+
isProductionWebBase,
|
|
14
16
|
newCode,
|
|
15
17
|
notificationEmail,
|
|
16
18
|
offLink,
|
|
@@ -57,6 +59,71 @@ describe("allow-list (staging shares the production mailer)", () => {
|
|
|
57
59
|
});
|
|
58
60
|
});
|
|
59
61
|
|
|
62
|
+
const PROD = "https://account.app.iservice365.org";
|
|
63
|
+
const STAGING = "https://iservice365-staging-account.apptesting.work";
|
|
64
|
+
|
|
65
|
+
describe("which environment is production (positive identification only)", () => {
|
|
66
|
+
it("the production web domain is production", () => {
|
|
67
|
+
assert.equal(isProductionWebBase(PROD), true);
|
|
68
|
+
assert.equal(isProductionWebBase("https://app.iservice365.org"), true);
|
|
69
|
+
assert.equal(isProductionWebBase("https://iservice365.org/"), true);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("staging, local, unset, unparsable and look-alikes are not", () => {
|
|
73
|
+
for (const base of [
|
|
74
|
+
STAGING,
|
|
75
|
+
"https://iservice365-staging-main.apptesting.work",
|
|
76
|
+
"http://localhost:3000",
|
|
77
|
+
"localhost",
|
|
78
|
+
"http:localhost:3000",
|
|
79
|
+
"",
|
|
80
|
+
"https://iservice365.org.evil.com",
|
|
81
|
+
"https://eviliservice365.org",
|
|
82
|
+
]) {
|
|
83
|
+
assert.equal(isProductionWebBase(base), false, base);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe("the default when EMAIL_NOTIFICATIONS_ALLOWLIST is not set", () => {
|
|
89
|
+
it("env set: the list wins, on production too", () => {
|
|
90
|
+
assert.equal(effectiveEmailAllowlist("*@example.org", PROD), "*@example.org");
|
|
91
|
+
assert.equal(isEmailAllowed("someone@gmail.com", "*@seven365.com.sg", PROD), false);
|
|
92
|
+
assert.equal(emailOpenToEveryone("*@seven365.com.sg", PROD), false);
|
|
93
|
+
assert.equal(isEmailAllowed("someone@gmail.com", "*", STAGING), true);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("production, unset: every verified address, and email is offered to everyone", () => {
|
|
97
|
+
for (const unset of [undefined, "", " "]) {
|
|
98
|
+
assert.equal(effectiveEmailAllowlist(unset, PROD), "*");
|
|
99
|
+
assert.equal(isEmailAllowed("someone@gmail.com", unset, PROD), true);
|
|
100
|
+
assert.equal(isEmailAllowed("security@seven365.com.sg", unset, PROD), true);
|
|
101
|
+
assert.equal(emailOpenToEveryone(unset, PROD), true);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("staging, unset: Seven365 addresses only, email offered only to them", () => {
|
|
106
|
+
assert.equal(effectiveEmailAllowlist(undefined, STAGING), DEFAULT_EMAIL_ALLOWLIST);
|
|
107
|
+
assert.equal(isEmailAllowed("someone@gmail.com", undefined, STAGING), false);
|
|
108
|
+
assert.equal(isEmailAllowed("security@seven365.com.sg", undefined, STAGING), true);
|
|
109
|
+
assert.equal(emailOpenToEveryone(undefined, STAGING), false);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("unknown or local, unset: fails closed like staging", () => {
|
|
113
|
+
for (const base of ["", "http://localhost:3000", "not a url"]) {
|
|
114
|
+
assert.equal(isEmailAllowed("someone@gmail.com", undefined, base), false, base);
|
|
115
|
+
assert.equal(isEmailAllowed("security@seven365.com.sg", undefined, base), true, base);
|
|
116
|
+
assert.equal(emailOpenToEveryone(undefined, base), false, base);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("garbage is never allowed, even on production", () => {
|
|
121
|
+
for (const bad of ["", null, undefined, "no-at-sign", 42]) {
|
|
122
|
+
assert.equal(isEmailAllowed(bad, undefined, PROD), false, String(bad));
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
60
127
|
describe("turn-off token (no sign-in, tamper-proof)", () => {
|
|
61
128
|
const t = offToken(U, "feedback", SECRET);
|
|
62
129
|
|