Repository navigation
Expand file tree
/
Copy pathpackaged-permission-set-lock.test.ts
More file actions
462 lines (417 loc) · 27.2 KB
/
Copy pathpackaged-permission-set-lock.test.ts
File metadata and controls
462 lines (417 loc) · 27.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
/**
* Maintainer ruling 2026-08-24 (verbatim: 「同意 第一步(创业阶段,Salesforce
* 式)」) — step 1: LOCK THE BASE, CLONE TO CUSTOMIZE.
*
* A Studio/API save targeting a package-declared permission set is refused at
* the server with a message that names the sanctioned path (clone it), so no
* silent overlay row is ever minted again.
*
* The lock's one door is the metadata door's authoring gate
* (`packaged-permission-set-lock-gate.ts`, pinned end to end in
* `packaged-permission-set-lock-gate.test.ts`). The `sys_permission_set` data
* door that also consulted it retired with the catalog row objects (ADR-0131
* D3), and its pins with it. This file pins the two halves that do not depend
* on a door:
*
* - the CLASSIFIER — "shipped by a code package" is judged from the
* provenance the SchemaRegistry carries, never from a name-keyed page read
* over a table (#21789);
* - the refusal's END-USER copy — the guidance reaches the wire as
* `userMessage`, through the producer's own error resolution.
*/
import { describe, it, expect } from 'vitest';
import { resolveThrownHttpError } from '@objectstack/types';
import {
classifyPackagedPermissionSet,
PackagedPermissionSetLockedError,
PackagedPermissionSetProvenanceUnknownError,
} from './packaged-permission-set-lock.js';
import { registerPackagedPermissionSetLockGate } from './packaged-permission-set-lock-gate.js';
import { ObjectStackProtocolImplementation } from '@objectstack/metadata-protocol';
import { SchemaRegistry } from '@objectstack/objectql';
// ─────────────────────────────────────────────────────────────────────────────
// Doubles
// ─────────────────────────────────────────────────────────────────────────────
/**
* The engine surface the classifier reads: its SchemaRegistry, and nothing
* else. `null` models a kernel with no readable registry.
*/
function makeQl(declared: any[] | null = null) {
const ql: any = {};
if (declared !== null) {
ql.registry = { listItems: (type: string) => (type === 'permission' ? declared : []) };
}
return ql;
}
/** Register the lock on a protocol double and hand back the gate it registered. */
function lockGate(
ql: any,
getMetaItemLayered: (req: { name: string }) => Promise<unknown> = async ({ name }) =>
({ type: 'permission', name, code: null, overlay: null, effective: null }),
) {
let gate: ((ctx: { type: string; name: string; body: unknown }) => Promise<void>) | undefined;
const protocol = {
registerAuthoringGate: (_type: string, g: typeof gate) => { gate = g; },
getMetaItemLayered,
};
expect(registerPackagedPermissionSetLockGate(protocol, ql)).toBe(true);
return gate!;
}
/** A shipped artifact: a body as the SchemaRegistry stamps it (ADR-0010). */
const packagedSet = (over: Record<string, any> = {}) => ({
name: 'ehr_quality_inspector',
label: 'Quality Inspector',
objects: { obj_a: { allowRead: true }, obj_b: { allowRead: true } },
systemPermissions: ['pkg.baseline'],
_packageId: 'com.example.ehr',
...over,
});
/** An env-authored definition — the same body shape, with no package behind it. */
const orgSet = (over: Record<string, any> = {}) => ({
name: 'org_support_agent',
label: 'Support Agent',
objects: { ticket: { allowRead: true } },
systemPermissions: ['support.use'],
...over,
});
// ─────────────────────────────────────────────────────────────────────────────
// [#21789] The lock reads the ROW's provenance, not the presence of a package id
// ─────────────────────────────────────────────────────────────────────────────
/**
* The registry holds stored rows as well as artifacts. The metadata layer
* hydrates every env-wide `sys_metadata` row into it (a list read, and the
* boot) as `mergeArtifactProtection(stateTenantAuthorship(row), artifact)`: the
* row's `package_id` column stamped on as `_packageId`, `_provenance: 'org'`
* written over it, and, only where a code artifact ships the name, the
* artifact's envelope written over that. These builders produce exactly those
* three bodies, so the verdicts below are about the shapes the boot really
* registers, measured on a booted showcase.
*/
const RUNTIME_PACKAGE = 'app.crm_workspace';
/** Shape 1: a set saved into a writable runtime package, as hydrated. */
const hydratedRuntimePackageRow = (over: Record<string, any> = {}) => ({
...orgSet({ name: 'workspace_rep' }),
_packageId: RUNTIME_PACKAGE,
_provenance: 'org',
...over,
});
/** Shapes 2 and 3: the org's own set, and a clone, as hydrated (no package column). */
const hydratedOrgRow = (over: Record<string, any> = {}) => ({ ...orgSet(), _provenance: 'org', ...over });
/** A code-shipped artifact as the loader registers it (`applyProtection` with a package id). */
const shippedArtifact = (over: Record<string, any> = {}) => packagedSet({ _provenance: 'package', ...over });
describe('[#21789] the lock judges "shipped by a code package" from the row\'s provenance', () => {
it('a set in a writable runtime package, hydrated with its package id, is NOT packaged', () => {
expect(classifyPackagedPermissionSet('workspace_rep', makeQl([hydratedRuntimePackageRow()])))
.toEqual({ status: 'org' });
});
it('an org-owned set and a clone, hydrated as stored rows, are NOT packaged', () => {
const ql = makeQl([hydratedOrgRow(), hydratedOrgRow({ name: 'ehr_quality_inspector_local' })]);
expect(classifyPackagedPermissionSet('org_support_agent', ql)).toEqual({ status: 'org' });
expect(classifyPackagedPermissionSet('ehr_quality_inspector_local', ql)).toEqual({ status: 'org' });
});
it('control: a code-shipped set stays packaged, alone and beside a stored row of its name', () => {
expect(classifyPackagedPermissionSet('ehr_quality_inspector', makeQl([shippedArtifact()])))
.toEqual({ status: 'packaged', packageId: 'com.example.ehr', packageIds: ['com.example.ehr'] });
// A legacy overlay of a shipped name is hydrated wearing the artifact's
// envelope, and the artifact is in the same list: still packaged, in either order.
const legacyOverlay = shippedArtifact({ systemPermissions: ['overlaid'] });
for (const items of [[legacyOverlay, shippedArtifact()], [shippedArtifact(), legacyOverlay]]) {
expect(classifyPackagedPermissionSet('ehr_quality_inspector', makeQl(items)))
.toEqual({ status: 'packaged', packageId: 'com.example.ehr', packageIds: ['com.example.ehr'] });
}
});
it('the layered read\'s code layer is judged the same way when there is no registry', () => {
const ql = makeQl(null);
const read = (code: unknown) => ({ status: 'read' as const, envelope: { code, overlay: null, effective: code } });
expect(classifyPackagedPermissionSet('workspace_rep', ql, read(hydratedRuntimePackageRow())))
.toEqual({ status: 'org' });
expect(classifyPackagedPermissionSet('ehr_quality_inspector', ql, read(shippedArtifact())))
.toEqual({ status: 'packaged', packageId: 'com.example.ehr', packageIds: ['com.example.ehr'] });
});
it('the metadata door accepts a runtime-package set and still refuses a code-shipped one with 403 NOT_OVERRIDABLE', async () => {
const gate = lockGate(makeQl([hydratedRuntimePackageRow(), shippedArtifact()]));
await expect(gate({ type: 'permission', name: 'workspace_rep', body: orgSet({ name: 'workspace_rep' }) }))
.resolves.toBeUndefined();
await expect(gate({ type: 'permission', name: 'ehr_quality_inspector', body: packagedSet() }))
.rejects.toMatchObject({ code: 'NOT_OVERRIDABLE', status: 403 });
});
});
// ─────────────────────────────────────────────────────────────────────────────
// [ADR-0086 D3] The lock reads a set's package from its BINDING only
// ─────────────────────────────────────────────────────────────────────────────
/**
* A set's owner is the package it is registered under (`_packageId`); its
* body's `packageId` is an author's declaration, refused at every door where it
* disagrees with that binding. The lock used to fall back to the body key when
* the binding was absent, so a set filed into no package whose body named one
* was locked as that package's: the one reader still treating the declaration
* as provenance.
*/
describe('[ADR-0086 D3] the lock never reads a set\'s body `packageId` as its package', () => {
/** Filed with no binding, its body naming a package: the shape the fallback locked. */
const unboundNamingAPackage = () => orgSet({ name: 'ehr_quality_inspector', packageId: 'com.example.ehr' });
it('a registry item with no binding is NOT packaged, whatever its body declares', () => {
expect(classifyPackagedPermissionSet('ehr_quality_inspector', makeQl([unboundNamingAPackage()])))
.toEqual({ status: 'org' });
});
it('the layered read\'s code layer, the same', () => {
const read = { status: 'read' as const, envelope: { code: unboundNamingAPackage(), overlay: null, effective: null } };
expect(classifyPackagedPermissionSet('ehr_quality_inspector', makeQl(null), read)).toEqual({ status: 'org' });
});
it('CONTROL: the binding decides, and a body key naming another package does not move it', () => {
expect(classifyPackagedPermissionSet('ehr_quality_inspector', makeQl([packagedSet()])))
.toEqual({ status: 'packaged', packageId: 'com.example.ehr', packageIds: ['com.example.ehr'] });
expect(classifyPackagedPermissionSet('ehr_quality_inspector', makeQl([packagedSet({ packageId: 'com.example.other' })])))
.toEqual({ status: 'packaged', packageId: 'com.example.ehr', packageIds: ['com.example.ehr'] });
});
});
// ─────────────────────────────────────────────────────────────────────────────
// The refusal's guidance reaches the END USER — `userMessage` on the wire
// ─────────────────────────────────────────────────────────────────────────────
/**
* The console renders a refusal's `userMessage` verbatim and substitutes its
* generic "You don't have permission to save this record." for every 403 that
* carries none (the objectui#5210 producer-side opt-in; `declaredUserMessage`
* in `@objectstack/types` is the one read every door applies). An unmarked
* lock refusal therefore told the admin nothing about the clone path, which is
* the whole point of the ruling the lock implements.
*
* The wire envelope is computed by the producer's own mapping, not restated:
* `resolveThrownHttpError` is the dispatcher door's resolution of the throw the
* metadata door's gate raises.
*
* Every case asserts the envelope (`status` + `code`) AND the `userMessage`:
* the code and status are the refusal's identity and must not move, and the
* marked text is what this block is about. The text itself is not pinned word
* for word — what is pinned is what the end user must and must not be shown:
* the guidance (clone it), and none of the diagnostic's machine names, package
* ids or API paths (the console's friendly-copy rule, objectstack#3821).
*/
describe('the lock refusal carries its guidance as `userMessage` on the wire envelope', () => {
const PACKAGE_ID = 'com.example.ehr';
const SET_NAME = 'ehr_quality_inspector';
/** End-user copy: a non-empty string carrying none of the diagnostic's machine identifiers. */
const expectEndUserCopy = (text: unknown, ...machineNames: string[]) => {
expect(typeof text, 'userMessage must be present on the wire').toBe('string');
expect(String(text).trim().length).toBeGreaterThan(0);
for (const machineName of machineNames) {
expect(text, `userMessage must not name '${machineName}'`).not.toContain(machineName);
}
expect(text, 'userMessage must not carry an API path').not.toMatch(/\/api\//);
};
it('a save of a package-declared set: 403 NOT_OVERRIDABLE with the clone guidance in `userMessage`', async () => {
const gate = lockGate(makeQl([shippedArtifact()]));
const rejection = await gate({ type: 'permission', name: SET_NAME, body: packagedSet() })
.then(() => null, (e: any) => e);
expect(rejection).toBeInstanceOf(PackagedPermissionSetLockedError);
const resolved = resolveThrownHttpError(rejection);
expect(resolved.status).toBe(403);
expect(resolved.code).toBe('NOT_OVERRIDABLE');
expectEndUserCopy(resolved.userMessage, SET_NAME, PACKAGE_ID);
expect(String(resolved.userMessage)).toMatch(/clone it instead/i);
// The diagnostic channel is untouched: it still names the set and the
// package for logs and developers. The mark never replaces `message`.
expect(String(rejection.message)).toContain(SET_NAME);
expect(String(rejection.message)).toContain(PACKAGE_ID);
});
it('the fail-closed sibling (provenance unknown): 403 NOT_OVERRIDABLE with retry-or-clone guidance, and no diagnostic reason', async () => {
const ql = makeQl([]);
ql.registry = { listItems: () => { throw new Error('registry unavailable'); } };
const gate = lockGate(ql, async () => { throw new Error('metadata store unavailable'); });
const rejection = await gate({ type: 'permission', name: 'unknown_provenance', body: {} })
.then(() => null, (e: any) => e);
expect(rejection).toBeInstanceOf(PackagedPermissionSetProvenanceUnknownError);
const resolved = resolveThrownHttpError(rejection);
expect(resolved.status).toBe(403);
expect(resolved.code).toBe('NOT_OVERRIDABLE');
expectEndUserCopy(
resolved.userMessage, 'unknown_provenance', 'registry unavailable', 'metadata store unavailable',
);
expect(String(resolved.userMessage)).toMatch(/try again/i);
expect(String(resolved.userMessage)).toMatch(/clone/i);
// The reason stays where it was: the diagnostic channel.
expect(String(rejection.message)).toContain('registry unavailable');
});
// [#32656] Ruling C on #32440: the producer composes the sentence in the
// request's language, else the workspace default, else `en`. The write door
// states the two locales on the gate's context (`userTextLocales`).
it('[#32656] the refusal speaks the caller\'s language: request locale, then the workspace default, then en', async () => {
const gate = lockGate(makeQl([shippedArtifact()]));
const refuse = (userTextLocales?: string[]) => gate({
type: 'permission', name: SET_NAME, body: packagedSet(), ...(userTextLocales ? { userTextLocales } : {}),
} as any).then(() => null, (e: any) => e);
const zh = await refuse(['zh-CN', 'en']);
expect(zh).toBeInstanceOf(PackagedPermissionSetLockedError);
expect(zh.userMessage).toContain('此权限集由已安装的软件包提供');
expectEndUserCopy(zh.userMessage, SET_NAME, PACKAGE_ID);
const ja = await refuse(['ja-JP', 'zh-CN']);
expect(ja.userMessage, 'the request language wins when it has text').toContain('この権限セット');
const workspace = await refuse(['tlh', 'zh-TW']);
expect(workspace.userMessage, 'an unsupported request language falls back to the workspace default').toContain('此權限集');
const floor = await refuse(['tlh', 'tlh']);
const unstated = await refuse();
expect(floor.userMessage).toBe(unstated.userMessage);
expect(String(unstated.userMessage)).toMatch(/clone it instead/i);
// Only the user's half moves: code, status and the diagnostic are the same in every language.
for (const r of [zh, ja, workspace, floor]) {
expect(r.code).toBe('NOT_OVERRIDABLE');
expect(r.status).toBe(403);
expect(r.message).toBe(unstated.message);
}
});
it('[#32656] the provenance-unknown refusal follows the same ladder', async () => {
const ql = makeQl([]);
ql.registry = { listItems: () => { throw new Error('registry unavailable'); } };
const gate = lockGate(ql, async () => { throw new Error('metadata store unavailable'); });
const rejection = await gate({ type: 'permission', name: 'unknown_provenance', body: {}, userTextLocales: ['de-DE'] } as any)
.then(() => null, (e: any) => e);
expect(rejection).toBeInstanceOf(PackagedPermissionSetProvenanceUnknownError);
expect(rejection.userMessage).toContain('kann gerade nicht gespeichert werden');
expectEndUserCopy(rejection.userMessage, 'unknown_provenance', 'registry unavailable', 'metadata store unavailable');
});
it('a SchemaRegistry that answers with a NON-LIST is the same ambiguity: the save is refused, not read as "nothing declared"', async () => {
const ql = makeQl([]);
ql.registry = { listItems: () => undefined as any };
expect(classifyPackagedPermissionSet('unknown_provenance', ql)).toMatchObject({ status: 'unknown' });
const gate = lockGate(ql, async () => { throw new Error('metadata store unavailable'); });
const rejection = await gate({ type: 'permission', name: 'unknown_provenance', body: {} })
.then(() => null, (e: any) => e);
expect(rejection).toBeInstanceOf(PackagedPermissionSetProvenanceUnknownError);
expect(resolveThrownHttpError(rejection)).toMatchObject({ status: 403, code: 'NOT_OVERRIDABLE' });
expect(String(rejection.message)).toContain('schema registry returned no list of declared permission sets');
});
});
// ─────────────────────────────────────────────────────────────────────────────
// [ADR-0150 D2/D3, #31698] A name two packages declare: every holder is named
// ─────────────────────────────────────────────────────────────────────────────
/**
* A set is one per `(package, name)`: two packages may each declare one of a
* name (a cross-namespace pair). The lock refuses an edit of that name through
* the metadata door, and its refusal names EVERY declaring package. On a kernel
* with no readable registry, the layered read naming no package is refused
* across the holders (`409`, ADR-0150 D5); each holder's layers are then read at
* its package. BASE: the refusal named the first package in registry order,
* and the registry-less refusal answered "provenance unknown".
*/
describe('[#31698] a name two packages declare: the lock names every holder', () => {
const A = 'com.acme.alpha';
const B = 'com.acme.beta';
const declared = (packageId: string) => shippedArtifact({ name: 'ops_reader', _packageId: packageId });
const twoHolderRefusal = () => Object.assign(new Error('permission set "ops_reader" is held by more than one package'), {
code: 'RESOURCE_CONFLICT', status: 409,
refusal: { reason: 'ambiguous-in-environment', candidates: [{ kind: 'package', packageId: A }, { kind: 'package', packageId: B }] },
});
it('with a registry: the verdict and the 403 name both packages (BASE: the first one only)', async () => {
const ql = makeQl([declared(A), declared(B)]);
expect(classifyPackagedPermissionSet('ops_reader', ql)).toEqual({ status: 'packaged', packageId: A, packageIds: [A, B] });
const refusal = await lockGate(ql)({ type: 'permission', name: 'ops_reader', body: {} }).catch((e: unknown) => e);
expect(refusal).toBeInstanceOf(PackagedPermissionSetLockedError);
expect((refusal as Error).message).toContain(`declared by packages '${A}' and '${B}'`);
});
it('with no registry: each holder\'s layers are read at its package, and the 403 names both (BASE: provenance unknown)', async () => {
const asked: Array<string | undefined> = [];
const gate = lockGate(makeQl(null), async (req: { name: string; packageId?: string }) => {
asked.push(req.packageId);
if (req.packageId === undefined) throw twoHolderRefusal();
return { type: 'permission', name: req.name, code: declared(req.packageId), overlay: null, effective: declared(req.packageId) };
});
const refusal = await gate({ type: 'permission', name: 'ops_reader', body: {} }).catch((e: unknown) => e);
expect(asked).toEqual([undefined, A, B]);
expect(refusal).toBeInstanceOf(PackagedPermissionSetLockedError);
expect((refusal as Error).message).toContain(`declared by packages '${A}' and '${B}'`);
});
it('CONTROL one holder: the refusal text is unchanged; a failed per-holder read is still provenance-unknown', async () => {
const one = await lockGate(makeQl([declared(A)]))({ type: 'permission', name: 'ops_reader', body: {} }).catch((e: unknown) => e);
expect((one as Error).message).toContain(`declared by package '${A}' and is locked`);
const gate = lockGate(makeQl(null), async (req: { name: string; packageId?: string }) => {
if (req.packageId === undefined) throw twoHolderRefusal();
throw new Error('store down');
});
const unknown = await gate({ type: 'permission', name: 'ops_reader', body: {} }).catch((e: unknown) => e);
expect(unknown).toBeInstanceOf(PackagedPermissionSetProvenanceUnknownError);
});
});
// ─────────────────────────────────────────────────────────────────────────────
// [ADR-0150 D2, #32780] A stored set in its package's registry slot is tenant-authored
// ─────────────────────────────────────────────────────────────────────────────
/**
* The host kernel's boot hydration (`loadMetaFromDb`, the real
* `ObjectStackProtocolImplementation` over a real `SchemaRegistry`) keeps each
* package's stored set of a name in that package's own registry slot. The
* classifier reads those slots as the tenant-authored sets they are, in either
* order the store reads the rows: two namespaces' stored sets of one name lock
* nothing, and a set stored beside a set another namespace ships never lends
* the lock its own package.
*/
describe('[#32780] a stored permission set in its package\'s registry slot is never read as shipped', () => {
const CRM = 'com.qa.crm';
const HR = 'com.qa.hr';
const N = 'qa_shared_reader';
const set = (label: string) => ({ name: N, label, objects: {} });
async function hydrate(rows: Array<{ packageId: string; label: string }>, ships?: string) {
const registry = new SchemaRegistry();
registry.logLevel = 'silent';
for (const id of [CRM, HR]) {
registry.installPackage({ id, name: id, version: '1.0.0', type: 'app', namespace: id.split('.').pop() } as never, 'authored');
}
if (ships) registry.registerItem('permission', set(`shipped:${ships}`) as never, 'name' as never, ships);
const stored = rows.map((r, i) => ({
id: `row_${i}`, type: 'permission', name: N, organization_id: null, package_id: r.packageId, state: 'active',
metadata: JSON.stringify(set(r.label)),
}));
const engine: any = {
async find(table: string, opts?: { where?: Record<string, unknown>; limit?: number }) {
if (table !== 'sys_metadata') return [];
const where = opts?.where ?? {};
const found = stored.filter((r) => Object.entries(where).every(([k, v]) => v === undefined || typeof v === 'object' || (r as any)[k] === v));
return typeof opts?.limit === 'number' ? found.slice(0, opts.limit) : found;
},
registry,
};
const load = await new ObjectStackProtocolImplementation(engine, () => new Map(), 'env_prod').loadMetaFromDb();
const label = (id: string) => (registry.getPackageScopedItem('permission', N, id) as { label?: string } | undefined)?.label;
return { load, ql: { registry }, label };
}
for (const order of [[CRM, HR], [HR, CRM]] as const) {
it(`two packages' stored sets (${order[0].split('.').pop()}'s row read first): each is its package's own, and the name is not locked`, async () => {
const { load, ql, label } = await hydrate(order.map((id) => ({ packageId: id, label: `row:${id}` })));
expect(load).toMatchObject({ loaded: 2, errors: 0 });
expect([label(CRM), label(HR)]).toEqual([`row:${CRM}`, `row:${HR}`]);
expect(classifyPackagedPermissionSet(N, ql)).toEqual({ status: 'org' });
});
}
it('a set stored beside the set another namespace ships: the lock names the shipper alone, and each package serves its own set', async () => {
const { ql, label } = await hydrate([{ packageId: HR, label: `row:${HR}` }], CRM);
expect([label(CRM), label(HR)]).toEqual([`shipped:${CRM}`, `row:${HR}`]);
expect(classifyPackagedPermissionSet(N, ql)).toEqual({ status: 'packaged', packageId: CRM, packageIds: [CRM] });
});
});
// The control the refusal sends the admin to is named by the label the console
// draws on it: "New similar" (Studio's Access pillar and Setup, the console's
// `perm.clone.action`), "新建类似" in a Chinese session, Traditional included,
// and the English label in every language the console's designer strings do
// not ship. A sentence naming a "Clone" button points at a control that is not there.
describe('the lock refusals name the clone control by its console label', () => {
const LOCALES = ['en', 'zh-Hans', 'zh-Hant', 'ja', 'ko', 'es', 'fr', 'de', 'pt-BR', 'ru', 'ar'];
const CHINESE = new Set(['zh-Hans', 'zh-Hant']);
const refusals = (locale: string) => [
new PackagedPermissionSetLockedError('crm_sales', 'com.example.crm', 'update', [locale]),
new PackagedPermissionSetProvenanceUnknownError('crm_sales', 'registry unavailable', [locale]),
];
for (const locale of LOCALES) {
it(`${locale}: the guidance names the "${CHINESE.has(locale) ? '新建类似' : 'New similar'}" action`, () => {
for (const refusal of refusals(locale)) {
expect(refusal.code).toBe('NOT_OVERRIDABLE');
expect(refusal.status).toBe(403);
expect(refusal.userMessage).toContain(CHINESE.has(locale) ? '新建类似' : 'New similar');
expect(refusal.userMessage).not.toMatch(/Clone action|“克隆”|「複製」動作|「複製」アクション|Clonar|Cloner|„Klonen“|«Клонировать»|복제 작업/);
}
});
}
it('the diagnostic names the same control', () => {
const [locked] = refusals('en');
expect(locked.message).toContain('the "New similar" action on the permission set, or POST /api/v1/security/permission-sets/crm_sales/clone');
expect(locked.message).not.toContain('"Clone" action');
});
});