Skip to content

Commit 82e0cee

Browse files
committed
test(plugin-auth): a mapping re-save after the connection moved organization (red), and liveness unit cases
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5mEnsnzoPLq43wQyYy
1 parent b13015e commit 82e0cee

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Unit cases for the SCIM credential liveness check that both the bearer
2+
// verifier and the group-mapping door read (#30959 review nit N3): no stored
3+
// row reaches an expired or falsy-active credential through the suites today.
4+
import { describe, it, expect } from 'vitest';
5+
import { scimCredentialIsLive } from './scim-connection-service.js';
6+
7+
const NOW = Date.parse('2026-11-08T12:00:00.000Z');
8+
9+
describe('scimCredentialIsLive', () => {
10+
it.each([false, 0, null, undefined])('refuses a credential whose active is %s', (active) => {
11+
expect(scimCredentialIsLive({ active, expires_at: null }, NOW)).toBe(false);
12+
});
13+
it('accepts an active credential with no expiry', () => {
14+
expect(scimCredentialIsLive({ active: true, expires_at: null }, NOW)).toBe(true);
15+
expect(scimCredentialIsLive({ active: 1 }, NOW)).toBe(true);
16+
});
17+
it('refuses a credential that expired in the past', () => {
18+
expect(scimCredentialIsLive({ active: true, expires_at: '2026-11-08T11:59:59.999Z' }, NOW)).toBe(false);
19+
});
20+
it('refuses a credential that expires exactly now', () => {
21+
expect(scimCredentialIsLive({ active: true, expires_at: new Date(NOW).toISOString() }, NOW)).toBe(false);
22+
});
23+
it('accepts a credential that expires in the future, and refuses an unreadable expiry', () => {
24+
expect(scimCredentialIsLive({ active: true, expires_at: '2026-11-08T12:00:00.001Z' }, NOW)).toBe(true);
25+
expect(scimCredentialIsLive({ active: true, expires_at: 'not a date' }, NOW)).toBe(false);
26+
});
27+
});

‎packages/plugins/plugin-auth/src/scim-group-projection.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,32 @@ describe('SCIM group push → mapped permission set', () => {
447447
expect(rows.map((r) => r.organization_id)).toEqual([ORG_B]);
448448
});
449449

450+
it('(S5) a re-save after the connection moved organization is refused, never answered with an organization the row does not carry', async () => {
451+
const h = await boot();
452+
const first = await saveMapping(h, { connectionId: CONNECTION, groupExternalId: 'okta-grp-sales', permissionSet: SALES });
453+
expect(first.status, JSON.stringify(first.body)).toBe(200);
454+
const mappingId = mappingIdOf(first);
455+
456+
// CONTROL: a re-save in the same organization is idempotent.
457+
const again = await saveMapping(h, { connectionId: CONNECTION, groupExternalId: 'okta-grp-sales', permissionSet: SALES });
458+
expect(again.status).toBe(200);
459+
expect((again.body as unknown as { data: { mappingId: string; created: boolean; organizationId: string } }).data)
460+
.toMatchObject({ mappingId, created: false, organizationId: ORG });
461+
462+
const ORG_B = 'org_scim_30959_b';
463+
await revokeScimConnectionCredential(h.engine as never, h.credentialId);
464+
await mintScimConnectionCredential(h.engine as never, SECRET, { connectionId: CONNECTION, organizationId: ORG_B });
465+
466+
const refused = await saveMapping(h, { connectionId: CONNECTION, groupExternalId: 'okta-grp-sales', permissionSet: SALES });
467+
expect(refused.status, JSON.stringify(refused.body)).toBe(409);
468+
const error = (refused.body as { error: { code: string; message: string } }).error;
469+
expect(error.code).toBe('RESOURCE_CONFLICT');
470+
expect(error.message).toContain(mappingId);
471+
expect(error.message).toContain(ORG);
472+
const rows = (await h.engine.find('sys_idp_group_mapping', {}, SYSTEM)) as Array<Record<string, unknown>>;
473+
expect(rows.map((r) => [r.id, r.organization_id])).toEqual([[mappingId, ORG]]);
474+
});
475+
450476
it('(S4) a connection whose every credential is revoked is refused at save', async () => {
451477
const h = await boot();
452478
await revokeScimConnectionCredential(h.engine as never, h.credentialId);

0 commit comments

Comments
 (0)