LifeMate — Personal, Family & Learning Companion
test: prevent membership role escalation through invitations
davoodmehraban89 committed
Oct 5, 2026 at 09:13 UTC
b9b94dc0f275b0356498fef48a448764cd3749d9
1 file changed
+69
backend/tests/api.test.js
+69
@@ -31,6 +31,7 @@ test('identity + family vertical slice', async () => {
31
const suffix = Date.now().toString(36);
32
const parentEmail = `parent-${suffix}@example.test`;
33
const teenEmail = `teen-${suffix}@example.test`;
34
+ const supporterEmail = `supporter-${suffix}@example.test`;
35
const initialPassword = 'StrongPass!123';
36
const changedPassword = 'StrongerPass!456';
37
@@ -150,6 +151,74 @@ test('identity + family vertical slice', async () => {
151
});
152
assert.equal(teenInviteAttempt.status, 403);
153
154
+ const reinviteActiveTeen = await request(
155
+ `/v1/families/${family.body.id}/invitations`,
156
+ {
157
+ method: 'POST',
158
+ token: refreshed.body.accessToken,
159
+ body: {
160
+ email: teenEmail,
161
+ role: 'parent_guardian',
162
+ themePreference: 'adult_blue',
163
+ },
164
+ },
165
+ );
166
+ assert.equal(reinviteActiveTeen.status, 409);
167
+
168
+ const supporterRegister = await request('/v1/auth/register', {
169
+ method: 'POST',
170
+ body: {
171
+ displayName: 'Supporter',
172
+ email: supporterEmail,
173
+ password: initialPassword,
174
+ },
175
+ });
176
+ assert.equal(supporterRegister.status, 201);
177
+ assert.equal(
178
+ (
179
+ await request('/v1/auth/verify-email', {
180
+ method: 'POST',
181
+ body: { token: supporterRegister.body.verificationToken },
182
+ })
183
+ ).status,
184
+ 204,
185
+ );
186
+ const supporterLogin = await request('/v1/auth/login', {
187
+ method: 'POST',
188
+ body: { email: supporterEmail, password: initialPassword },
189
+ });
190
+ assert.equal(supporterLogin.status, 200);
191
+
192
+ const supporterInvite = await request(
193
+ `/v1/families/${family.body.id}/invitations`,
194
+ {
195
+ method: 'POST',
196
+ token: refreshed.body.accessToken,
197
+ body: { email: supporterEmail, role: 'parent_guardian' },
198
+ },
199
+ );
200
+ assert.equal(supporterInvite.status, 201);
201
+ assert.equal(
202
+ (
203
+ await request('/v1/invitations/accept', {
204
+ method: 'POST',
205
+ token: supporterLogin.body.accessToken,
206
+ body: { token: supporterInvite.body.invitationToken },
207
+ })
208
+ ).status,
209
+ 204,
210
+ );
211
+
212
+ const nonAdminParentInviteAttempt = await request(
213
+ `/v1/families/${family.body.id}/invitations`,
214
+ {
215
+ method: 'POST',
216
+ token: supporterLogin.body.accessToken,
217
+ body: { email: 'blocked-by-policy@example.test', role: 'adult_member' },
218
+ },
219
+ );
220
+ assert.equal(nonAdminParentInviteAttempt.status, 403);
221
+
222
const guardian = await request(`/v1/families/${family.body.id}/guardians`, {
223
method: 'POST',
224
token: refreshed.body.accessToken,