contracts 1.8.0: crosscode.identity-request/1 (import and people.* calls to Accounts)
Product -> Accounts requests at /api/accounts/v1/requests, signed with the link secret: import.begin/batch/finish/abort for moving a product's users in (EVENTS-3.0-PLAN §4), people.* for product admins (§8). sealLinkValue / openLinkValue seal password hashes and TOTP secrets with a key derived from the link secret; importIdsHash for the final check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { identityRequestSchema, importPersonSchema, sealedValueSchema } from "../src";
|
||||
import { importIdsHash, newLinkSecret, openLinkValue, sealLinkValue } from "../src/signing";
|
||||
import { sample } from "./helpers";
|
||||
|
||||
describe("crosscode.identity-request/1", () => {
|
||||
test("a sealed value opens with the same link secret, and only that one", () => {
|
||||
const secret = newLinkSecret();
|
||||
const hash = "$2b$10$abcdefghijklmnopqrstuuJt1Yx0H1iLx3m6nS6m1j0fDqv3p4q5W";
|
||||
const sealed = sealLinkValue(secret, hash);
|
||||
expect(sealedValueSchema.safeParse(sealed).success).toBe(true);
|
||||
expect(sealed).not.toContain("abcdefghij");
|
||||
expect(openLinkValue(secret, sealed)).toBe(hash);
|
||||
expect(() => openLinkValue(newLinkSecret(), sealed)).toThrow();
|
||||
const tampered = sealed.slice(0, -2) + (sealed.endsWith("A") ? "BB" : "AA");
|
||||
expect(() => openLinkValue(secret, tampered)).toThrow();
|
||||
});
|
||||
|
||||
test("the ids hash doesn't depend on order", () => {
|
||||
const a = ["b8f1c2d3-0000-4000-8000-000000000002", "a7e0b1c2-0000-4000-8000-000000000001"];
|
||||
expect(importIdsHash(a)).toBe(importIdsHash([...a].reverse()));
|
||||
expect(importIdsHash(a)).toMatch(/^[0-9a-f]{64}$/);
|
||||
expect(importIdsHash(a)).not.toBe(importIdsHash(a.slice(0, 1)));
|
||||
});
|
||||
|
||||
test("an unsealed password hash is refused", () => {
|
||||
const person = sample<{ people: Record<string, unknown>[] }>("import-batch.json").people[0]!;
|
||||
expect(importPersonSchema.safeParse(person).success).toBe(true);
|
||||
expect(importPersonSchema.safeParse({ ...person, passwordHash: "$2b$10$plain" }).success).toBe(false);
|
||||
});
|
||||
|
||||
test("a batch is at most 200 people", () => {
|
||||
const batch = sample<{ people: unknown[] }>("import-batch.json");
|
||||
const many = { ...batch, people: Array.from({ length: 201 }, () => batch.people[0]) };
|
||||
expect(identityRequestSchema.safeParse(many).success).toBe(false);
|
||||
});
|
||||
|
||||
test("unknown request types are refused", () => {
|
||||
expect(identityRequestSchema.safeParse({ ...sample("people-ensure.json"), type: "people.delete" }).success).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -40,6 +40,12 @@ const SAMPLE_SCHEMA: Record<string, string> = {
|
||||
"link-connect.json": "link-connect",
|
||||
"link-connected.json": "link-connected",
|
||||
"link-disconnect.json": "link-disconnect",
|
||||
"import-begin.json": "identity-request",
|
||||
"import-batch.json": "identity-request",
|
||||
"import-batch-reply.json": "import-batch-reply",
|
||||
"import-finish.json": "identity-request",
|
||||
"people-ensure.json": "identity-request",
|
||||
"people-ensure-reply.json": "people-ensure-reply",
|
||||
};
|
||||
|
||||
describe("JSON Schema (schemas/)", () => {
|
||||
|
||||
@@ -13,6 +13,9 @@ import {
|
||||
linkConnectedSchema,
|
||||
linkDisconnectSchema,
|
||||
identityClaimsSchema,
|
||||
identityRequestSchema,
|
||||
importBatchReplySchema,
|
||||
peopleEnsureReplySchema,
|
||||
userDeletedReplySchema,
|
||||
userExportReplySchema,
|
||||
} from "../src";
|
||||
@@ -44,6 +47,12 @@ const SCHEMAS: Record<string, z.ZodType> = {
|
||||
"link-connect.json": linkConnectSchema,
|
||||
"link-connected.json": linkConnectedSchema,
|
||||
"link-disconnect.json": linkDisconnectSchema,
|
||||
"import-begin.json": identityRequestSchema,
|
||||
"import-batch.json": identityRequestSchema,
|
||||
"import-batch-reply.json": importBatchReplySchema,
|
||||
"import-finish.json": identityRequestSchema,
|
||||
"people-ensure.json": identityRequestSchema,
|
||||
"people-ensure-reply.json": peopleEnsureReplySchema,
|
||||
};
|
||||
|
||||
describe("samples", () => {
|
||||
|
||||
Reference in New Issue
Block a user