@fluxmail/core 0.23.0 → 0.25.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.
@@ -0,0 +1,89 @@
1
+ import { type AccessCredential, type AccessDecision, type AccessDenialReason, type AccessMailbox, type AccessMember, type MailboxAccess, type MemberRole } from './rules.js';
2
+ export declare const ACCESS_PRODUCTS: readonly ["self-hosted", "cloud"];
3
+ export type AccessProduct = (typeof ACCESS_PRODUCTS)[number];
4
+ /**
5
+ * Members, mailboxes and credentials a product stores before running an action.
6
+ * Every id a world refers to is defined in it, so a product can insert it under
7
+ * its own foreign keys.
8
+ */
9
+ export interface AccessWorld {
10
+ members: readonly AccessMember[];
11
+ mailboxes: readonly AccessMailbox[];
12
+ credentials?: readonly AccessCredential[];
13
+ }
14
+ export type AccessAction = {
15
+ type: 'read_mailbox';
16
+ actorId: string;
17
+ mailboxId: string;
18
+ } | {
19
+ type: 'credential_read_mailbox';
20
+ credentialId: string;
21
+ mailboxId: string;
22
+ } | {
23
+ type: 'see_mailbox_metadata';
24
+ actorId: string;
25
+ mailboxId: string;
26
+ } | {
27
+ type: 'manage_mailbox';
28
+ actorId: string;
29
+ mailboxId: string;
30
+ } | {
31
+ type: 'change_mailbox_connection';
32
+ actorId: string;
33
+ mailboxId: string;
34
+ } | {
35
+ type: 'change_mailbox_access';
36
+ actorId: string;
37
+ mailboxId: string;
38
+ access: MailboxAccess;
39
+ } | {
40
+ type: 'reassign_mailbox';
41
+ actorId: string;
42
+ mailboxId: string;
43
+ newOwnerId: string;
44
+ } | {
45
+ type: 'connect_mailbox';
46
+ actorId: string;
47
+ ownerId: string;
48
+ } | {
49
+ type: 'issue_credential';
50
+ actorId: string;
51
+ ownerId: string;
52
+ mailboxIds: readonly string[] | null;
53
+ } | {
54
+ type: 'manage_member';
55
+ actorId: string;
56
+ targetId: string;
57
+ } | {
58
+ type: 'remove_member';
59
+ actorId: string;
60
+ targetId: string;
61
+ newOwnerId: string | null;
62
+ } | {
63
+ type: 'assign_role';
64
+ actorId: string;
65
+ targetId: string;
66
+ role: MemberRole;
67
+ } | {
68
+ type: 'transfer_ownership';
69
+ actorId: string;
70
+ targetId: string;
71
+ };
72
+ /** Every action type, so products can check that they run each one. */
73
+ export declare const ACCESS_ACTION_TYPES: AccessAction["type"][];
74
+ export interface AccessConformanceCase {
75
+ name: string;
76
+ /**
77
+ * Products that offer this behavior and must pass the case. An empty list marks
78
+ * a rule neither product offers yet, kept so a product that adds it inherits it.
79
+ */
80
+ products: readonly AccessProduct[];
81
+ world: AccessWorld;
82
+ action: AccessAction;
83
+ /** `true`, or the reason it is refused. Read checks are refused with `no_mailbox_access`. */
84
+ expected: true | AccessDenialReason;
85
+ }
86
+ /** Runs one action against the shared rules. Products run the same world and action against their storage. */
87
+ export declare function evaluateAccessAction(world: AccessWorld, action: AccessAction): AccessDecision;
88
+ export declare const ACCESS_CONFORMANCE_CASES: readonly AccessConformanceCase[];
89
+ //# sourceMappingURL=conformance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conformance.d.ts","sourceRoot":"","sources":["../../src/access/conformance.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,556 @@
1
+ import { canAssignRole, canChangeMailboxAccess, canChangeMailboxConnection, canConnectMailbox, canIssueCredential, canManageMailbox, canManageMember, canReassignMailbox, canRemoveMember, canSeeMailboxMetadata, canTransferOwnership, credentialCanReadMailbox, memberCanReadMailbox, } from './rules.js';
2
+ export const ACCESS_PRODUCTS = ['self-hosted', 'cloud'];
3
+ const ACTION_TYPES = {
4
+ read_mailbox: true,
5
+ credential_read_mailbox: true,
6
+ see_mailbox_metadata: true,
7
+ manage_mailbox: true,
8
+ change_mailbox_connection: true,
9
+ change_mailbox_access: true,
10
+ reassign_mailbox: true,
11
+ connect_mailbox: true,
12
+ issue_credential: true,
13
+ manage_member: true,
14
+ remove_member: true,
15
+ assign_role: true,
16
+ transfer_ownership: true,
17
+ };
18
+ /** Every action type, so products can check that they run each one. */
19
+ export const ACCESS_ACTION_TYPES = Object.keys(ACTION_TYPES);
20
+ /** Runs one action against the shared rules. Products run the same world and action against their storage. */
21
+ export function evaluateAccessAction(world, action) {
22
+ const findMember = (id) => world.members.find((member) => member.id === id);
23
+ const mailbox = (id) => {
24
+ const found = world.mailboxes.find((candidate) => candidate.id === id);
25
+ if (!found)
26
+ throw new Error(`Unknown mailbox "${id}" in access world.`);
27
+ return found;
28
+ };
29
+ const member = (id) => {
30
+ const found = findMember(id);
31
+ if (!found)
32
+ throw new Error(`Unknown member "${id}" in access world.`);
33
+ return found;
34
+ };
35
+ const read = (allowed) => allowed ? { allowed: true } : { allowed: false, reason: 'no_mailbox_access' };
36
+ switch (action.type) {
37
+ case 'read_mailbox':
38
+ return read(memberCanReadMailbox(findMember(action.actorId), mailbox(action.mailboxId)));
39
+ case 'credential_read_mailbox': {
40
+ const credential = world.credentials?.find((candidate) => candidate.id === action.credentialId);
41
+ if (!credential)
42
+ throw new Error(`Unknown credential "${action.credentialId}" in access world.`);
43
+ return read(credentialCanReadMailbox(credential, mailbox(action.mailboxId), findMember));
44
+ }
45
+ case 'see_mailbox_metadata':
46
+ return canSeeMailboxMetadata(findMember(action.actorId), mailbox(action.mailboxId));
47
+ case 'manage_mailbox':
48
+ return canManageMailbox(findMember(action.actorId), mailbox(action.mailboxId));
49
+ case 'change_mailbox_connection':
50
+ return canChangeMailboxConnection(findMember(action.actorId), mailbox(action.mailboxId));
51
+ case 'change_mailbox_access':
52
+ return canChangeMailboxAccess(findMember(action.actorId), mailbox(action.mailboxId), action.access, findMember);
53
+ case 'reassign_mailbox':
54
+ return canReassignMailbox(findMember(action.actorId), mailbox(action.mailboxId), action.newOwnerId, findMember);
55
+ case 'connect_mailbox':
56
+ return canConnectMailbox(findMember(action.actorId), action.ownerId, findMember);
57
+ case 'issue_credential':
58
+ return canIssueCredential(findMember(action.actorId), action.ownerId, action.mailboxIds?.map((id) => mailbox(id)) ?? null, findMember);
59
+ case 'manage_member':
60
+ return canManageMember(findMember(action.actorId), member(action.targetId));
61
+ case 'remove_member':
62
+ return canRemoveMember(findMember(action.actorId), member(action.targetId), action.newOwnerId, findMember);
63
+ case 'assign_role':
64
+ return canAssignRole(findMember(action.actorId), member(action.targetId), action.role);
65
+ case 'transfer_ownership':
66
+ return canTransferOwnership(findMember(action.actorId), member(action.targetId));
67
+ }
68
+ }
69
+ // Fixtures. Cloud has one owner and members, with no admins, suspension or
70
+ // sharing. Self-hosted has admins and members, with suspension and sharing.
71
+ const active = (id, role) => ({ id, role, status: 'active' });
72
+ const olivia = active('olivia', 'owner');
73
+ const ada = active('ada', 'admin');
74
+ const grace = active('grace', 'member');
75
+ const linus = active('linus', 'member');
76
+ const sam = { id: 'sam', role: 'member', status: 'suspended' };
77
+ const pat = { id: 'pat', role: 'member', status: 'pending' };
78
+ const suspendedAda = { id: 'ada', role: 'admin', status: 'suspended' };
79
+ const PRIVATE = { kind: 'private' };
80
+ const WORKSPACE = { kind: 'workspace' };
81
+ const box = (id, ownerId, access = PRIVATE) => ({ id, ownerId, access });
82
+ const graceBox = box('grace-box', 'grace');
83
+ const linusBox = box('linus-box', 'linus');
84
+ const samBox = box('sam-box', 'sam');
85
+ const teamBox = box('team-box', 'grace', WORKSPACE);
86
+ const sharedWithLinus = box('linus-shared', 'grace', { kind: 'members', memberIds: ['linus'] });
87
+ // Cases both products must pass use only members, which both offer.
88
+ const common = { members: [grace, linus], mailboxes: [graceBox, linusBox] };
89
+ const cloud = { members: [olivia, grace, linus], mailboxes: [graceBox, linusBox] };
90
+ const selfHostedMailboxes = [graceBox, linusBox, samBox, teamBox, sharedWithLinus];
91
+ const selfHosted = { members: [ada, grace, linus, sam, pat], mailboxes: selfHostedMailboxes };
92
+ const adaSuspended = { members: [suspendedAda, grace, linus, sam, pat], mailboxes: selfHostedMailboxes };
93
+ const withCredentials = (world, credentials) => ({
94
+ ...world,
95
+ credentials,
96
+ });
97
+ const key = (id, ownerId, issuerId, mailboxIds = null) => ({ id, ownerId, issuerId, mailboxIds });
98
+ const both = ['self-hosted', 'cloud'];
99
+ const selfHostedOnly = ['self-hosted'];
100
+ const cloudOnly = ['cloud'];
101
+ export const ACCESS_CONFORMANCE_CASES = [
102
+ // Reading mail
103
+ {
104
+ name: 'an owner reads their private mailbox',
105
+ products: both,
106
+ world: common,
107
+ action: { type: 'read_mailbox', actorId: 'grace', mailboxId: 'grace-box' },
108
+ expected: true,
109
+ },
110
+ {
111
+ name: 'a member cannot read another member’s private mailbox',
112
+ products: both,
113
+ world: common,
114
+ action: { type: 'read_mailbox', actorId: 'linus', mailboxId: 'grace-box' },
115
+ expected: 'no_mailbox_access',
116
+ },
117
+ {
118
+ name: 'the workspace owner cannot read a member’s private mailbox',
119
+ products: cloudOnly,
120
+ world: cloud,
121
+ action: { type: 'read_mailbox', actorId: 'olivia', mailboxId: 'grace-box' },
122
+ expected: 'no_mailbox_access',
123
+ },
124
+ {
125
+ name: 'an admin cannot read a member’s private mailbox',
126
+ products: selfHostedOnly,
127
+ world: selfHosted,
128
+ action: { type: 'read_mailbox', actorId: 'ada', mailboxId: 'grace-box' },
129
+ expected: 'no_mailbox_access',
130
+ },
131
+ {
132
+ name: 'a mailbox shared with the workspace is readable by every active member',
133
+ products: selfHostedOnly,
134
+ world: selfHosted,
135
+ action: { type: 'read_mailbox', actorId: 'ada', mailboxId: 'team-box' },
136
+ expected: true,
137
+ },
138
+ {
139
+ name: 'a listed member reads a mailbox shared with them',
140
+ products: selfHostedOnly,
141
+ world: selfHosted,
142
+ action: { type: 'read_mailbox', actorId: 'linus', mailboxId: 'linus-shared' },
143
+ expected: true,
144
+ },
145
+ {
146
+ name: 'an admin missing from the member list cannot read the mailbox',
147
+ products: selfHostedOnly,
148
+ world: selfHosted,
149
+ action: { type: 'read_mailbox', actorId: 'ada', mailboxId: 'linus-shared' },
150
+ expected: 'no_mailbox_access',
151
+ },
152
+ {
153
+ name: 'a suspended owner cannot read their mailbox',
154
+ products: selfHostedOnly,
155
+ world: selfHosted,
156
+ action: { type: 'read_mailbox', actorId: 'sam', mailboxId: 'sam-box' },
157
+ expected: 'no_mailbox_access',
158
+ },
159
+ {
160
+ name: 'a suspended member cannot read a workspace mailbox',
161
+ products: selfHostedOnly,
162
+ world: selfHosted,
163
+ action: { type: 'read_mailbox', actorId: 'sam', mailboxId: 'team-box' },
164
+ expected: 'no_mailbox_access',
165
+ },
166
+ // Credential reach
167
+ {
168
+ name: 'a member’s own key reaches their mailboxes',
169
+ products: both,
170
+ world: withCredentials(common, [key('grace-key', 'grace', null)]),
171
+ action: { type: 'credential_read_mailbox', credentialId: 'grace-key', mailboxId: 'grace-box' },
172
+ expected: true,
173
+ },
174
+ {
175
+ name: 'a key cannot reach a mailbox left off its allowlist',
176
+ products: both,
177
+ world: withCredentials(common, [key('grace-key', 'grace', null, ['linus-box'])]),
178
+ action: { type: 'credential_read_mailbox', credentialId: 'grace-key', mailboxId: 'grace-box' },
179
+ expected: 'no_mailbox_access',
180
+ },
181
+ {
182
+ name: 'a key cannot reach past its owner',
183
+ products: both,
184
+ world: withCredentials(common, [key('grace-key', 'grace', null)]),
185
+ action: { type: 'credential_read_mailbox', credentialId: 'grace-key', mailboxId: 'linus-box' },
186
+ expected: 'no_mailbox_access',
187
+ },
188
+ {
189
+ name: 'a key an admin created for a member cannot reach that member’s private mailbox',
190
+ products: selfHostedOnly,
191
+ world: withCredentials(selfHosted, [key('issued', 'grace', 'ada')]),
192
+ action: { type: 'credential_read_mailbox', credentialId: 'issued', mailboxId: 'grace-box' },
193
+ expected: 'no_mailbox_access',
194
+ },
195
+ {
196
+ name: 'a key an admin created for a member reaches mailboxes both can read',
197
+ products: selfHostedOnly,
198
+ world: withCredentials(selfHosted, [key('issued', 'grace', 'ada')]),
199
+ action: { type: 'credential_read_mailbox', credentialId: 'issued', mailboxId: 'team-box' },
200
+ expected: true,
201
+ },
202
+ {
203
+ name: 'a key stops reaching a mailbox when its issuer is suspended',
204
+ products: selfHostedOnly,
205
+ world: withCredentials(adaSuspended, [key('issued', 'grace', 'ada')]),
206
+ action: { type: 'credential_read_mailbox', credentialId: 'issued', mailboxId: 'team-box' },
207
+ expected: 'no_mailbox_access',
208
+ },
209
+ {
210
+ name: 'a key stops working when its owner is suspended',
211
+ products: selfHostedOnly,
212
+ world: withCredentials(selfHosted, [key('sam-key', 'sam', null)]),
213
+ action: { type: 'credential_read_mailbox', credentialId: 'sam-key', mailboxId: 'sam-box' },
214
+ expected: 'no_mailbox_access',
215
+ },
216
+ // Mailbox metadata and settings
217
+ {
218
+ name: 'an admin sees a member’s mailbox metadata',
219
+ products: selfHostedOnly,
220
+ world: selfHosted,
221
+ action: { type: 'see_mailbox_metadata', actorId: 'ada', mailboxId: 'grace-box' },
222
+ expected: true,
223
+ },
224
+ {
225
+ name: 'a member cannot see another member’s private mailbox metadata',
226
+ products: both,
227
+ world: common,
228
+ action: { type: 'see_mailbox_metadata', actorId: 'linus', mailboxId: 'grace-box' },
229
+ expected: 'no_mailbox_access',
230
+ },
231
+ {
232
+ name: 'an owner manages their own mailbox',
233
+ products: both,
234
+ world: common,
235
+ action: { type: 'manage_mailbox', actorId: 'grace', mailboxId: 'grace-box' },
236
+ expected: true,
237
+ },
238
+ {
239
+ name: 'an admin removes a member’s mailbox or edits its folders and senders',
240
+ products: selfHostedOnly,
241
+ world: selfHosted,
242
+ action: { type: 'manage_mailbox', actorId: 'ada', mailboxId: 'grace-box' },
243
+ expected: true,
244
+ },
245
+ {
246
+ name: 'a member cannot manage another member’s mailbox',
247
+ products: both,
248
+ world: common,
249
+ action: { type: 'manage_mailbox', actorId: 'linus', mailboxId: 'grace-box' },
250
+ expected: 'missing_capability',
251
+ },
252
+ // Changing a mailbox's connection
253
+ {
254
+ name: 'an owner reauthorizes their mailbox',
255
+ products: both,
256
+ world: common,
257
+ action: { type: 'change_mailbox_connection', actorId: 'grace', mailboxId: 'grace-box' },
258
+ expected: true,
259
+ },
260
+ {
261
+ name: 'an admin cannot change a member’s mailbox server settings',
262
+ products: selfHostedOnly,
263
+ world: selfHosted,
264
+ action: { type: 'change_mailbox_connection', actorId: 'ada', mailboxId: 'grace-box' },
265
+ expected: 'not_mailbox_owner',
266
+ },
267
+ {
268
+ name: 'an admin cannot reauthorize a suspended member’s mailbox',
269
+ products: selfHostedOnly,
270
+ world: selfHosted,
271
+ action: { type: 'change_mailbox_connection', actorId: 'ada', mailboxId: 'sam-box' },
272
+ expected: 'not_mailbox_owner',
273
+ },
274
+ // Changing who can read a mailbox
275
+ {
276
+ name: 'an owner shares their mailbox with the workspace',
277
+ products: selfHostedOnly,
278
+ world: selfHosted,
279
+ action: { type: 'change_mailbox_access', actorId: 'grace', mailboxId: 'grace-box', access: WORKSPACE },
280
+ expected: true,
281
+ },
282
+ {
283
+ name: 'an owner cannot share their mailbox with someone outside the workspace',
284
+ products: selfHostedOnly,
285
+ world: selfHosted,
286
+ action: {
287
+ type: 'change_mailbox_access',
288
+ actorId: 'grace',
289
+ mailboxId: 'grace-box',
290
+ access: { kind: 'members', memberIds: ['linus', 'outsider'] },
291
+ },
292
+ expected: 'unknown_member',
293
+ },
294
+ {
295
+ name: 'an admin cannot share a member’s mailbox with themselves',
296
+ products: selfHostedOnly,
297
+ world: selfHosted,
298
+ action: {
299
+ type: 'change_mailbox_access',
300
+ actorId: 'ada',
301
+ mailboxId: 'grace-box',
302
+ access: { kind: 'members', memberIds: ['ada'] },
303
+ },
304
+ expected: 'not_mailbox_owner',
305
+ },
306
+ {
307
+ name: 'an admin cannot share a member’s mailbox with a member they invited',
308
+ products: selfHostedOnly,
309
+ world: selfHosted,
310
+ action: {
311
+ type: 'change_mailbox_access',
312
+ actorId: 'ada',
313
+ mailboxId: 'grace-box',
314
+ access: { kind: 'members', memberIds: ['pat'] },
315
+ },
316
+ expected: 'not_mailbox_owner',
317
+ },
318
+ {
319
+ name: 'a member a mailbox is shared with cannot re-share it',
320
+ products: selfHostedOnly,
321
+ world: selfHosted,
322
+ action: { type: 'change_mailbox_access', actorId: 'linus', mailboxId: 'linus-shared', access: WORKSPACE },
323
+ expected: 'not_mailbox_owner',
324
+ },
325
+ {
326
+ name: 'an admin cannot share a suspended member’s mailbox',
327
+ products: selfHostedOnly,
328
+ world: selfHosted,
329
+ action: { type: 'change_mailbox_access', actorId: 'ada', mailboxId: 'sam-box', access: WORKSPACE },
330
+ expected: 'not_mailbox_owner',
331
+ },
332
+ // Handing a mailbox to someone else
333
+ {
334
+ name: 'an owner hands their mailbox to another member',
335
+ products: selfHostedOnly,
336
+ world: selfHosted,
337
+ action: { type: 'reassign_mailbox', actorId: 'grace', mailboxId: 'grace-box', newOwnerId: 'linus' },
338
+ expected: true,
339
+ },
340
+ {
341
+ name: 'an owner hands their mailbox to a member who has not enrolled',
342
+ products: selfHostedOnly,
343
+ world: selfHosted,
344
+ action: { type: 'reassign_mailbox', actorId: 'grace', mailboxId: 'grace-box', newOwnerId: 'pat' },
345
+ expected: true,
346
+ },
347
+ {
348
+ name: 'a mailbox cannot go to a suspended member',
349
+ products: selfHostedOnly,
350
+ world: selfHosted,
351
+ action: { type: 'reassign_mailbox', actorId: 'grace', mailboxId: 'grace-box', newOwnerId: 'sam' },
352
+ expected: 'inactive_owner',
353
+ },
354
+ {
355
+ name: 'an admin cannot take over an active member’s mailbox',
356
+ products: selfHostedOnly,
357
+ world: selfHosted,
358
+ action: { type: 'reassign_mailbox', actorId: 'ada', mailboxId: 'grace-box', newOwnerId: 'ada' },
359
+ expected: 'not_mailbox_owner',
360
+ },
361
+ {
362
+ name: 'an admin cannot hand an active member’s mailbox to someone else',
363
+ products: selfHostedOnly,
364
+ world: selfHosted,
365
+ action: { type: 'reassign_mailbox', actorId: 'ada', mailboxId: 'grace-box', newOwnerId: 'linus' },
366
+ expected: 'not_mailbox_owner',
367
+ },
368
+ {
369
+ name: 'an admin cannot take over a suspended member’s mailbox',
370
+ products: selfHostedOnly,
371
+ world: selfHosted,
372
+ action: { type: 'reassign_mailbox', actorId: 'ada', mailboxId: 'sam-box', newOwnerId: 'ada' },
373
+ expected: 'not_mailbox_owner',
374
+ },
375
+ // Connecting a mailbox
376
+ {
377
+ name: 'a member connects their own mailbox',
378
+ products: both,
379
+ world: common,
380
+ action: { type: 'connect_mailbox', actorId: 'grace', ownerId: 'grace' },
381
+ expected: true,
382
+ },
383
+ {
384
+ name: 'an admin connects a mailbox for a member who has not enrolled',
385
+ products: selfHostedOnly,
386
+ world: selfHosted,
387
+ action: { type: 'connect_mailbox', actorId: 'ada', ownerId: 'pat' },
388
+ expected: true,
389
+ },
390
+ {
391
+ name: 'an admin cannot connect a mailbox for a suspended member',
392
+ products: selfHostedOnly,
393
+ world: selfHosted,
394
+ action: { type: 'connect_mailbox', actorId: 'ada', ownerId: 'sam' },
395
+ expected: 'inactive_owner',
396
+ },
397
+ {
398
+ name: 'a member cannot connect a mailbox for someone else',
399
+ products: selfHostedOnly,
400
+ world: selfHosted,
401
+ action: { type: 'connect_mailbox', actorId: 'linus', ownerId: 'grace' },
402
+ expected: 'missing_capability',
403
+ },
404
+ // Creating credentials
405
+ {
406
+ name: 'a member creates a key for themselves',
407
+ products: both,
408
+ world: common,
409
+ action: { type: 'issue_credential', actorId: 'grace', ownerId: 'grace', mailboxIds: ['grace-box'] },
410
+ expected: true,
411
+ },
412
+ {
413
+ name: 'an admin cannot create a key for a mailbox they cannot read',
414
+ products: selfHostedOnly,
415
+ world: selfHosted,
416
+ action: { type: 'issue_credential', actorId: 'ada', ownerId: 'grace', mailboxIds: ['grace-box'] },
417
+ expected: 'outside_issuer_reach',
418
+ },
419
+ {
420
+ name: 'an admin creates a key for a member on a mailbox both can read',
421
+ products: selfHostedOnly,
422
+ world: selfHosted,
423
+ action: { type: 'issue_credential', actorId: 'ada', ownerId: 'grace', mailboxIds: ['team-box'] },
424
+ expected: true,
425
+ },
426
+ {
427
+ name: 'an admin cannot create a key for a suspended member',
428
+ products: selfHostedOnly,
429
+ world: selfHosted,
430
+ action: { type: 'issue_credential', actorId: 'ada', ownerId: 'sam', mailboxIds: null },
431
+ expected: 'inactive_owner',
432
+ },
433
+ {
434
+ name: 'a member cannot create a key for someone else',
435
+ products: selfHostedOnly,
436
+ world: selfHosted,
437
+ action: { type: 'issue_credential', actorId: 'linus', ownerId: 'grace', mailboxIds: null },
438
+ expected: 'missing_capability',
439
+ },
440
+ // Managing members
441
+ {
442
+ name: 'an admin suspends a member',
443
+ products: selfHostedOnly,
444
+ world: selfHosted,
445
+ action: { type: 'manage_member', actorId: 'ada', targetId: 'grace' },
446
+ expected: true,
447
+ },
448
+ {
449
+ name: 'a member cannot manage other members',
450
+ products: both,
451
+ world: common,
452
+ action: { type: 'manage_member', actorId: 'linus', targetId: 'grace' },
453
+ expected: 'missing_capability',
454
+ },
455
+ {
456
+ name: 'a suspended admin cannot manage members',
457
+ products: selfHostedOnly,
458
+ world: adaSuspended,
459
+ action: { type: 'manage_member', actorId: 'ada', targetId: 'grace' },
460
+ expected: 'inactive_actor',
461
+ },
462
+ // Removing members
463
+ {
464
+ name: 'an admin removes a member and hands their mailboxes to a replacement who has not enrolled',
465
+ products: selfHostedOnly,
466
+ world: selfHosted,
467
+ action: { type: 'remove_member', actorId: 'ada', targetId: 'sam', newOwnerId: 'pat' },
468
+ expected: true,
469
+ },
470
+ {
471
+ name: 'a removed member’s mailboxes cannot go back to that member',
472
+ products: selfHostedOnly,
473
+ world: selfHosted,
474
+ action: { type: 'remove_member', actorId: 'ada', targetId: 'sam', newOwnerId: 'sam' },
475
+ expected: 'inactive_owner',
476
+ },
477
+ {
478
+ name: 'a removed member’s mailboxes cannot go to a suspended member',
479
+ products: selfHostedOnly,
480
+ world: selfHosted,
481
+ action: { type: 'remove_member', actorId: 'ada', targetId: 'grace', newOwnerId: 'sam' },
482
+ expected: 'inactive_owner',
483
+ },
484
+ {
485
+ name: 'the workspace owner removes a member and their mailboxes',
486
+ products: cloudOnly,
487
+ world: cloud,
488
+ action: { type: 'remove_member', actorId: 'olivia', targetId: 'grace', newOwnerId: null },
489
+ expected: true,
490
+ },
491
+ {
492
+ name: 'a member cannot remove other members',
493
+ products: both,
494
+ world: common,
495
+ action: { type: 'remove_member', actorId: 'linus', targetId: 'grace', newOwnerId: null },
496
+ expected: 'missing_capability',
497
+ },
498
+ {
499
+ name: 'the workspace owner cannot be removed',
500
+ products: cloudOnly,
501
+ world: cloud,
502
+ action: { type: 'remove_member', actorId: 'olivia', targetId: 'olivia', newOwnerId: null },
503
+ expected: 'owner_protected',
504
+ },
505
+ {
506
+ name: 'an admin cannot remove the workspace owner',
507
+ products: [],
508
+ world: { members: [olivia, ada], mailboxes: [] },
509
+ action: { type: 'remove_member', actorId: 'ada', targetId: 'olivia', newOwnerId: 'ada' },
510
+ expected: 'owner_protected',
511
+ },
512
+ // Roles and ownership
513
+ {
514
+ name: 'an admin promotes a member to admin',
515
+ products: selfHostedOnly,
516
+ world: selfHosted,
517
+ action: { type: 'assign_role', actorId: 'ada', targetId: 'grace', role: 'admin' },
518
+ expected: true,
519
+ },
520
+ {
521
+ name: 'a member cannot promote themselves',
522
+ products: selfHostedOnly,
523
+ world: selfHosted,
524
+ action: { type: 'assign_role', actorId: 'grace', targetId: 'grace', role: 'admin' },
525
+ expected: 'missing_capability',
526
+ },
527
+ {
528
+ name: 'nobody becomes the owner by a role change',
529
+ products: [],
530
+ world: { members: [olivia, grace], mailboxes: [] },
531
+ action: { type: 'assign_role', actorId: 'olivia', targetId: 'grace', role: 'owner' },
532
+ expected: 'owner_protected',
533
+ },
534
+ {
535
+ name: 'the owner transfers ownership to an active member',
536
+ products: [],
537
+ world: { members: [olivia, grace], mailboxes: [] },
538
+ action: { type: 'transfer_ownership', actorId: 'olivia', targetId: 'grace' },
539
+ expected: true,
540
+ },
541
+ {
542
+ name: 'an admin cannot transfer ownership',
543
+ products: [],
544
+ world: { members: [olivia, ada, grace], mailboxes: [] },
545
+ action: { type: 'transfer_ownership', actorId: 'ada', targetId: 'grace' },
546
+ expected: 'owner_protected',
547
+ },
548
+ {
549
+ name: 'ownership cannot go to a member who has not enrolled',
550
+ products: [],
551
+ world: { members: [olivia, pat], mailboxes: [] },
552
+ action: { type: 'transfer_ownership', actorId: 'olivia', targetId: 'pat' },
553
+ expected: 'inactive_owner',
554
+ },
555
+ ];
556
+ //# sourceMappingURL=conformance.js.map