Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

fix(relay): fence sealed moves at their bound sequence [A4,H7]

Corey Olson71e331f6892a
diff --git a/relay/README.md b/relay/README.md
index bedcec05..e979286a 100644
--- a/relay/README.md
+++ b/relay/README.md
@@ -34,7 +34,7 @@ refusals have `error: {code, message, next}`. A bearer credential works for CLI
requests. Cookie-authorized writes must carry the exact configured Origin.
The API layer must call `auth.authenticate(token, {board, write})` before serving
-board data or applying a board move. `write: true` always checks GitHub. For an
+sealed board data or storing a sealed board move. `write: true` always checks GitHub. For an
agent credential, use the returned `agent`, never an agent supplied in a request
body. A credential for one board is refused on another before any board lookup.
Use `auth.boardsFor(token)` for visibility, and `auth.linkBoard(token, board,
@@ -89,10 +89,14 @@ The client owns the encryption format and engine-version checks.
cannot move behind the previous snapshot, and removes the covered move prefix.
- GET /api/v1/boards/:id/state returns
{version: 1, state: {sequence, receivedAt, sealed}}.
-- POST /api/v1/boards/:id/moves takes {sealed}. The relay allocates the next
- sequence atomically and returns {version: 1, event, result: {sequence}}.
- An event is {event_id, event_at, sealed}. Requests use the same sealed append
- through POST /api/v1/boards/:id/requests; clients interpret their contents.
+- POST /api/v1/boards/:id/moves takes {sequence, sealed}. The client proposes
+ the next position before sealing; the relay allocates it atomically only if
+ sequence is its next position and returns {version: 1, event, result: {sequence}}.
+ A loser receives SEQUENCE_REPEAT (409), reads the latest prefix, reseals with
+ a fresh nonce bound to the next position, and retries. Gaps are refused too.
+ An event is {event_id, event_at, kind, sealed}. Requests use the same sealed append
+ through POST /api/v1/boards/:id/requests. The public transport kind is move or
+ request, letting clients select their associated-data binding; content stays sealed.
- GET /api/v1/boards/:id/events?after=N returns sealed events in sequence.
Accept: text/event-stream follows the same records; Last-Event-ID resumes.
A cursor older than the latest snapshot gets SNAPSHOT_REQUIRED (409), naming
diff --git a/relay/journal.js b/relay/journal.js
index 0c94a1d8..acc10576 100644
--- a/relay/journal.js
+++ b/relay/journal.js
@@ -34,7 +34,7 @@ export function createRelayJournal({ directory, boardId, maxBytes = DEFAULT_BYTE
let closed = false;
try {
db.exec('PRAGMA busy_timeout = 30000; PRAGMA journal_mode = WAL; BEGIN IMMEDIATE');
- db.exec('CREATE TABLE IF NOT EXISTS journal_meta (key TEXT PRIMARY KEY, value TEXT NOT NULL); CREATE TABLE IF NOT EXISTS journal_record (sequence INTEGER PRIMARY KEY, received_at TEXT NOT NULL, payload BLOB NOT NULL)');
+ db.exec('CREATE TABLE IF NOT EXISTS journal_meta (key TEXT PRIMARY KEY, value TEXT NOT NULL); CREATE TABLE IF NOT EXISTS journal_record (sequence INTEGER PRIMARY KEY, received_at TEXT NOT NULL, kind TEXT NOT NULL CHECK(kind IN (\'move\',\'request\')), payload BLOB NOT NULL)');
const saved = db.prepare('SELECT key, value FROM journal_meta ORDER BY key').all();
if (saved.length === 0) {
if (db.prepare('SELECT 1 FROM journal_record LIMIT 1').get()) throw new Refused('RELAY_STORAGE', 'restore the journal with its original identity and format metadata');
@@ -55,7 +55,7 @@ export function createRelayJournal({ directory, boardId, maxBytes = DEFAULT_BYTE
function open() { if (closed) throw new Refused('RELAY_CLOSED', 'open the journal before reading or appending records'); }
/** Convert an SQLite row to detached opaque bytes so callers cannot mutate a stored record. */
- function record(row) { return { sequence: row.sequence, receivedAt: row.received_at, bytes: Buffer.from(row.payload) }; }
+ function record(row) { return { sequence: row.sequence, receivedAt: row.received_at, kind: row.kind ?? 'snapshot', bytes: Buffer.from(row.payload) }; }
/** Read the latest committed sequence, including an empty journal's initial cursor. */
function latest() {
@@ -70,10 +70,11 @@ export function createRelayJournal({ directory, boardId, maxBytes = DEFAULT_BYTE
}
/** Serialize prefix checking or sequence allocation with the opaque append. */
- function insert(sequence, bytes) {
+ function insert(sequence, bytes, kind) {
open();
if (sequence !== null && (!Number.isSafeInteger(sequence) || sequence < 1)) throw new Refused('BAD_SEQUENCE', 'upload a positive safe integer sequence');
const sealed = payload(bytes);
+ if (!['move', 'request'].includes(kind)) throw new Refused('BAD_UPLOAD', 'use the move or request transport kind');
db.exec('BEGIN IMMEDIATE');
try {
const next = latest() + 1;
@@ -83,7 +84,7 @@ export function createRelayJournal({ directory, boardId, maxBytes = DEFAULT_BYTE
if (sequence > next) throw new Refused('SEQUENCE_GAP', 'send the next sequence after the latest committed record before later uploads');
const at = now();
if (!(at instanceof Date) || !Number.isFinite(at.getTime())) throw new Refused('RELAY_CONFIG', 'the journal clock must return a valid Date');
- db.prepare('INSERT INTO journal_record (sequence,received_at,payload) VALUES (?,?,?)').run(sequence, at.toISOString(), sealed);
+ db.prepare('INSERT INTO journal_record (sequence,received_at,kind,payload) VALUES (?,?,?,?)').run(sequence, at.toISOString(), kind, sealed);
db.prepare('UPDATE journal_head SET sequence=? WHERE slot=1').run(sequence);
const result = record(db.prepare('SELECT * FROM journal_record WHERE sequence=?').get(sequence));
db.exec('COMMIT');
@@ -95,10 +96,10 @@ export function createRelayJournal({ directory, boardId, maxBytes = DEFAULT_BYTE
}
/** Append a transport retry only at its explicitly named next sequence. */
- function append(sequence, bytes) { return insert(sequence, bytes); }
+ function append(sequence, bytes, kind = 'move') { return insert(sequence, bytes, kind); }
/** Allocate the next sequence under the same lock as the append, as the live relay requires. */
- function appendNext(bytes) { return insert(null, bytes); }
+ function appendNext(bytes, kind = 'move') { return insert(null, bytes, kind); }
/** Read the latest sealed snapshot without interpreting its contents. */
function snapshot() {
diff --git a/relay/service.js b/relay/service.js
index d8bdf736..edc056b6 100644
--- a/relay/service.js
+++ b/relay/service.js
@@ -44,10 +44,10 @@ function trustedOrigin(value) {
}
/** Decode only canonical transport bytes; sealed payloads are never parsed or unsealed. */
-function sealed(body, snapshot = false) {
- const keys = snapshot ? ['sealed', 'sequence'] : ['sealed'];
+function sealed(body) {
+ const keys = ['sealed', 'sequence'];
if (!body || Object.keys(body).some((key) => !keys.includes(key)) || typeof body.sealed !== 'string' || !/^[A-Za-z0-9_-]+$/.test(body.sealed)) {
- throw new Refused('BAD_UPLOAD', 'send only a nonempty base64url sealed payload, plus sequence for a snapshot; keep keys on your device');
+ throw new Refused('BAD_UPLOAD', 'send only sequence and a nonempty base64url sealed payload; keep keys on your device');
}
const bytes = Buffer.from(body.sealed, 'base64url');
if (bytes.length === 0 || bytes.toString('base64url') !== body.sealed) throw new Refused('BAD_UPLOAD', 'send canonical nonempty base64url bytes sealed on your device');
@@ -55,7 +55,7 @@ function sealed(body, snapshot = false) {
}
/** Give live events the common API cursor while keeping all board contents sealed. */
-function event(row) { return { event_id: row.sequence, event_at: row.receivedAt, sealed: row.bytes.toString('base64url') }; }
+function event(row) { return { event_id: row.sequence, event_at: row.receivedAt, kind: row.kind, sealed: row.bytes.toString('base64url') }; }
/** Give a snapshot its coverage cursor; clients unseal it and replay the following sealed events. */
function state(row) { return { sequence: row.sequence, receivedAt: row.receivedAt, sealed: row.bytes.toString('base64url') }; }
@@ -86,11 +86,12 @@ export function createRelayHandler({ directory, auth, pollMs = 200, publicOrigin
}
/** Append ciphertext under its server-allocated sequence, with no engine or filesystem access. */
- async function append(board, body, who) {
+ async function append(board, body, who, kind = 'move') {
const bytes = sealed(body);
+ if (!Number.isSafeInteger(body.sequence) || body.sequence < 1) throw new Refused('BAD_SEQUENCE', 'seal this move for the next positive sequence after the latest committed prefix');
await auth.authenticate(who.credential, { board: board.id, write: true });
return withJournal(board.id, (journal) => {
- const row = journal.appendNext(bytes);
+ const row = journal.append(body.sequence, bytes, kind);
return { status: 200, body: { event: event(row), result: { sequence: row.sequence } } };
});
}
@@ -114,7 +115,7 @@ export function createRelayHandler({ directory, auth, pollMs = 200, publicOrigin
return journal.after(after).map(event);
}),
move: append,
- request: async (board, body, who) => (await append(board, body, who)).body,
+ request: async (board, body, who) => (await append(board, body, who, 'request')).body,
}, { pollMs });
/** Add authenticated snapshot replacement and deletion to the common versioned read/move paths. */
@@ -129,7 +130,7 @@ export function createRelayHandler({ directory, auth, pollMs = 200, publicOrigin
const id = identity(snapshot[1]);
await auth.authenticate(credential(req, origin, true), { board: id, write: true });
const body = await readApiBody(req, { maxBytes: SNAPSHOT_BODY });
- const bytes = sealed(body, true);
+ const bytes = sealed(body);
if (!Number.isSafeInteger(body.sequence) || body.sequence < 0) throw new Refused('BAD_SEQUENCE', 'name the nonnegative sequence covered by the sealed snapshot');
await auth.authenticate(credential(req, origin, true), { board: id, write: true });
const saved = withJournal(id, (journal) => journal.saveSnapshot(body.sequence, bytes), true);
diff --git a/src/api-http.js b/src/api-http.js
index 7a87aa60..276b2e7d 100644
--- a/src/api-http.js
+++ b/src/api-http.js
@@ -142,7 +142,7 @@ export function createApiHandler(adapter, { pollMs = 200 } = {}) {
/** Choose the same HTTP refusal class for local and sealed relay adapters. */
export function apiStatus(error) {
- return { AUTH_REQUIRED: 401, TOKEN_BOARD: 403, API_ORIGIN: 403, BAD_ORIGIN: 403, WRITE_REQUIRED: 403, NO_REPO_ACCESS: 403, NO_BOARD: 404, BOARD_NOT_LINKED: 404, NO_SNAPSHOT: 404, SNAPSHOT_REQUIRED: 409 }[error.code] ?? (error instanceof Refused ? 400 : 500);
+ return { AUTH_REQUIRED: 401, TOKEN_BOARD: 403, API_ORIGIN: 403, BAD_ORIGIN: 403, WRITE_REQUIRED: 403, NO_REPO_ACCESS: 403, NO_BOARD: 404, BOARD_NOT_LINKED: 404, NO_SNAPSHOT: 404, SNAPSHOT_REQUIRED: 409, SEQUENCE_REPEAT: 409, SEQUENCE_GAP: 409 }[error.code] ?? (error instanceof Refused ? 400 : 500);
}
// Relay-only snapshot/delete routes reuse the exact shared bounded-body and refusal boundary.
diff --git a/test/relay-sealed.test.js b/test/relay-sealed.test.js
index 18ffaf85..b22a1c30 100644
--- a/test/relay-sealed.test.js
+++ b/test/relay-sealed.test.js
@@ -12,19 +12,22 @@ import { createGitHubClient } from '../relay/github.js';
import { githubFixture } from './relay-fixture.js';
/** Seal on the test client only; nonce, authentication tag and ciphertext are opaque to the server. */
-function seal(key, value) {
+function seal(key, value, binding) {
const nonce = randomBytes(12);
const cipher = createCipheriv('aes-256-gcm', key, nonce);
+ cipher.setAAD(Buffer.from(JSON.stringify(binding)));
const bytes = Buffer.concat([cipher.update(JSON.stringify(value)), cipher.final()]);
- return Buffer.concat([nonce, cipher.getAuthTag(), bytes]).toString('base64url');
+ return Buffer.concat([Buffer.from([1]), nonce, bytes, cipher.getAuthTag()]).toString('base64url');
}
/** Open on the test client only, proving that received ciphertext still represents the sent record. */
-function unseal(key, value) {
+function unseal(key, value, binding) {
const bytes = Buffer.from(value, 'base64url');
- const decipher = createDecipheriv('aes-256-gcm', key, bytes.subarray(0, 12));
- decipher.setAuthTag(bytes.subarray(12, 28));
- return JSON.parse(Buffer.concat([decipher.update(bytes.subarray(28)), decipher.final()]).toString());
+ const decipher = createDecipheriv('aes-256-gcm', key, bytes.subarray(1, 13));
+ assert.equal(bytes[0], 1);
+ decipher.setAuthTag(bytes.subarray(-16));
+ decipher.setAAD(Buffer.from(JSON.stringify(binding)));
+ return JSON.parse(Buffer.concat([decipher.update(bytes.subarray(13, -16)), decipher.final()]).toString());
}
/** Create a real private CLI board, actual stand-in GitHub sign-in, and an ephemeral relay server. */
@@ -72,7 +75,11 @@ async function fixture(t) {
});
return { status: response.status, body: await response.json() };
}
- return { directory, root, data, cli, document, id, marker, auth, person, one, two, relay, origin, key, call, path: '/api/v1/boards/' + id };
+ /** Bind each client seal to its board, kind and proposed transport position. */
+ function clientSeal(value, kind, sequence, board = id) { return seal(key, value, { board, kind, sequence }); }
+ /** Unseal received records at their actual committed position, never the client's old proposal. */
+ function clientOpen(value, kind, sequence, board = id) { return unseal(key, value, { board, kind, sequence }); }
+ return { directory, root, data, cli, document, id, marker, auth, person, one, two, relay, origin, key, call, clientSeal, clientOpen, path: '/api/v1/boards/' + id };
}
test('[A4,H7] two clients append sealed moves in one order and no plaintext or client key reaches storage', async (t) => {
@@ -80,23 +87,31 @@ test('[A4,H7] two clients append sealed moves in one order and no plaintext or c
const listed = await box.call('/api/v1/boards');
assert.equal(listed.status, 200);
assert.deepEqual(listed.body.boards, [{ id: box.id, repository: 'fixture/repository' }]);
- const initial = seal(box.key, box.document);
+ const initial = box.clientSeal(box.document, 'snapshot', 0);
const uploaded = await box.call(box.path + '/state', { method: 'PUT', body: { sequence: 0, sealed: initial } });
assert.equal(uploaded.status, 200);
assert.equal(uploaded.body.version, 1);
- assert.deepEqual(unseal(box.key, uploaded.body.state.sealed), box.document);
+ assert.deepEqual(box.clientOpen(uploaded.body.state.sealed, 'snapshot', 0), box.document);
const sent = [
{ client: 'one', title: 'PRIVATE_MOVE_FROM_CLIENT_ONE' },
{ client: 'two', title: 'PRIVATE_MOVE_FROM_CLIENT_TWO' },
];
const results = await Promise.all(sent.map((move, index) => box.call(box.path + '/moves', {
- method: 'POST', token: index ? box.two.token : box.one.token, body: { sealed: seal(box.key, move) },
+ method: 'POST', token: index ? box.two.token : box.one.token, body: { sequence: 1, sealed: box.clientSeal(move, 'move', 1) },
})));
- assert.ok(results.every((reply) => reply.status === 200 && reply.body.version === 1));
- assert.deepEqual(results.map((reply) => reply.body.event.event_id).sort(), [1, 2]);
+ assert.equal(results.filter((reply) => reply.status === 200).length, 1);
+ const loser = results.findIndex((reply) => reply.status === 409);
+ assert.notEqual(loser, -1);
+ assert.equal(results[loser].body.error.code, 'SEQUENCE_REPEAT');
+ const retry = await box.call(box.path + '/moves', {
+ method: 'POST', token: loser ? box.two.token : box.one.token,
+ body: { sequence: 2, sealed: box.clientSeal(sent[loser], 'move', 2) },
+ });
+ assert.equal(retry.status, 200);
+ assert.equal(retry.body.event.event_id, 2);
const read = await box.call(box.path + '/events?after=0');
assert.deepEqual(read.body.events.map((row) => row.event_id), [1, 2]);
- assert.deepEqual(read.body.events.map((row) => unseal(box.key, row.sealed)).sort((a, b) => a.client.localeCompare(b.client)), sent);
+ assert.deepEqual(read.body.events.map((row) => box.clientOpen(row.sealed, row.kind, row.event_id)).sort((a, b) => a.client.localeCompare(b.client)), sent);
const bytes = Buffer.concat(readdirSync(box.data).map((file) => readFileSync(join(box.data, file))));
for (const text of [box.marker, ...sent.map((move) => move.title), box.root]) {
assert.equal(bytes.includes(Buffer.from(text)), false, 'a known client plaintext must never occur in relay database bytes');
@@ -107,29 +122,29 @@ test('[A4,H7] two clients append sealed moves in one order and no plaintext or c
test('[A4,H7] snapshots compact covered moves, preserve the tail and deletion removes only its database', async (t) => {
const box = await fixture(t);
- await box.call(box.path + '/state', { method: 'PUT', body: { sequence: 0, sealed: seal(box.key, box.document) } });
+ await box.call(box.path + '/state', { method: 'PUT', body: { sequence: 0, sealed: box.clientSeal(box.document, 'snapshot', 0) } });
for (let n = 1; n <= 3; n++) {
- const reply = await box.call(box.path + '/moves', { method: 'POST', body: { sealed: seal(box.key, { move: n }) } });
+ const reply = await box.call(box.path + '/moves', { method: 'POST', body: { sequence: n, sealed: box.clientSeal({ move: n }, 'move', n) } });
assert.equal(reply.body.event.event_id, n);
}
- const compacted = await box.call(box.path + '/state', { method: 'PUT', body: { sequence: 2, sealed: seal(box.key, { covered: 2 }) } });
+ const compacted = await box.call(box.path + '/state', { method: 'PUT', body: { sequence: 2, sealed: box.clientSeal({ covered: 2 }, 'snapshot', 2) } });
assert.equal(compacted.status, 200);
assert.equal(compacted.body.state.sequence, 2);
- assert.deepEqual(unseal(box.key, (await box.call(box.path + '/state')).body.state.sealed), { covered: 2 });
+ assert.deepEqual(box.clientOpen((await box.call(box.path + '/state')).body.state.sealed, 'snapshot', 2), { covered: 2 });
const oldCursor = await box.call(box.path + '/events?after=0');
assert.equal(oldCursor.status, 409);
assert.equal(oldCursor.body.error.code, 'SNAPSHOT_REQUIRED');
assert.deepEqual((await box.call(box.path + '/events?after=2')).body.events.map((row) => row.event_id), [3]);
- const next = await box.call(box.path + '/moves', { method: 'POST', body: { sealed: seal(box.key, { move: 4 }) } });
+ const next = await box.call(box.path + '/moves', { method: 'POST', body: { sequence: 4, sealed: box.clientSeal({ move: 4 }, 'move', 4) } });
assert.equal(next.body.event.event_id, 4);
const other = 'f'.repeat(32) === box.id ? 'e'.repeat(32) : 'f'.repeat(32);
await box.auth.linkBoard(box.person.token, other, 'fixture/repository');
const otherPath = '/api/v1/boards/' + other;
- assert.equal((await box.call(otherPath + '/state', { method: 'PUT', token: box.person.token, body: { sequence: 0, sealed: seal(box.key, { other: true }) } })).status, 200);
+ assert.equal((await box.call(otherPath + '/state', { method: 'PUT', token: box.person.token, body: { sequence: 0, sealed: box.clientSeal({ other: true }, 'snapshot', 0, other) } })).status, 200);
assert.equal((await box.call(box.path, { method: 'DELETE' })).status, 200);
for (const suffix of ['', '-wal', '-shm']) assert.equal(existsSync(join(box.data, box.id + '.journal.sqlite' + suffix)), false);
assert.equal((await box.call(box.path + '/state')).status, 404);
- assert.deepEqual(unseal(box.key, (await box.call(otherPath + '/state', { token: box.person.token })).body.state.sealed), { other: true });
+ assert.deepEqual(box.clientOpen((await box.call(otherPath + '/state', { token: box.person.token })).body.state.sealed, 'snapshot', 0, other), { other: true });
assert.deepEqual(JSON.parse(box.cli('export')), box.document);
});
@@ -140,25 +155,42 @@ test('[A4,H7] malformed or unauthorized calls cannot store clear records, keys o
const wrong = await box.call('/api/v1/boards/' + other + '/state');
assert.equal(wrong.status, 403);
assert.equal(wrong.body.error.code, 'TOKEN_BOARD');
- for (const body of [{ sequence: 0, sealed: 'a' }, { sequence: 0, sealed: 'abc=' }, { sequence: 0, sealed: seal(box.key, {}), key: 'client key stays on device' }, { sequence: '0', sealed: seal(box.key, {}) }]) {
+ for (const body of [{ sequence: 0, sealed: 'a' }, { sequence: 0, sealed: 'abc=' }, { sequence: 0, sealed: box.clientSeal({}, 'snapshot', 0), key: 'client key stays on device' }, { sequence: '0', sealed: box.clientSeal({}, 'snapshot', 0) }]) {
assert.equal((await box.call(box.path + '/state', { method: 'PUT', body })).status, 400);
}
assert.deepEqual(readdirSync(box.data), []);
- await box.call(box.path + '/state', { method: 'PUT', body: { sequence: 0, sealed: seal(box.key, box.document) } });
+ await box.call(box.path + '/state', { method: 'PUT', body: { sequence: 0, sealed: box.clientSeal(box.document, 'snapshot', 0) } });
assert.equal((await box.call(box.path + '/moves', { method: 'POST', body: { verb: 'add', args: { title: 'clear' } } })).body.error.code, 'BAD_UPLOAD');
- const deniedCookie = await box.call(box.path + '/moves', { method: 'POST', token: null, headers: { cookie: 'pb_session=' + box.person.token, origin: 'https://foreign.example' }, body: { sealed: seal(box.key, {}) } });
+ const deniedCookie = await box.call(box.path + '/moves', { method: 'POST', token: null, headers: { cookie: 'pb_session=' + box.person.token, origin: 'https://foreign.example' }, body: { sequence: 1, sealed: box.clientSeal({}, 'move', 1) } });
assert.equal(deniedCookie.status, 403);
assert.equal(deniedCookie.body.error.code, 'BAD_ORIGIN');
assert.equal((await box.call(box.path + '/state', { token: null, headers: { cookie: 'pb_session=' + box.person.token } })).status, 200);
- const cookieMove = await box.call(box.path + '/moves', { method: 'POST', token: null, headers: { cookie: 'pb_session=' + box.person.token, origin: 'http://127.0.0.1:44444' }, body: { sealed: seal(box.key, { cookie: true }) } });
+ const cookieMove = await box.call(box.path + '/moves', { method: 'POST', token: null, headers: { cookie: 'pb_session=' + box.person.token, origin: 'http://127.0.0.1:44444' }, body: { sequence: 1, sealed: box.clientSeal({ cookie: true }, 'move', 1) } });
assert.equal(cookieMove.status, 200);
+ const request = await box.call(box.path + '/requests', {
+ method: 'POST', body: { sequence: 2, sealed: box.clientSeal({ request: true }, 'request', 2) },
+ });
+ assert.equal(request.status, 200);
+ assert.equal(request.body.event.kind, 'request');
+ assert.deepEqual(box.clientOpen(request.body.event.sealed, request.body.event.kind, request.body.event.event_id), { request: true });
+ assert.throws(() => box.clientOpen(request.body.event.sealed, 'move', request.body.event.event_id));
+
+ const gap = await box.call(box.path + '/moves', {
+ method: 'POST', body: { sequence: 4, sealed: box.clientSeal({ gap: true }, 'move', 4) },
+ });
+ assert.equal(gap.status, 409);
+ assert.equal(gap.body.error.code, 'SEQUENCE_GAP');
+ assert.deepEqual((await box.call(box.path + '/events?after=0')).body.events.map((row) => row.event_id), [1, 2]);
+ assert.equal((await box.call(box.path + '/state', {
+ token: null, headers: { cookie: 'pb_session=' + box.person.token + '; pb_session=' + box.person.token },
+ })).status, 401);
await box.auth.revoke(box.person.token, box.one.id);
assert.equal((await box.call(box.path + '/state')).status, 401);
});
test('[A4,H7] live streams follow the same order, resume by cursor and stop after revocation', async (t) => {
const box = await fixture(t);
- await box.call(box.path + '/state', { method: 'PUT', body: { sequence: 0, sealed: seal(box.key, box.document) } });
+ await box.call(box.path + '/state', { method: 'PUT', body: { sequence: 0, sealed: box.clientSeal(box.document, 'snapshot', 0) } });
const controllers = [];
t.after(() => { for (const controller of controllers) controller.abort(); });
/** Open a live API stream and bound each observation without exposing its credential. */
@@ -190,13 +222,13 @@ test('[A4,H7] live streams follow the same order, resume by cursor and stop afte
}
const first = await stream();
await first.until(': API v1\n');
- const one = await box.call(box.path + '/moves', { method: 'POST', body: { sealed: seal(box.key, { live: 1 }) } });
+ const one = await box.call(box.path + '/moves', { method: 'POST', body: { sequence: 1, sealed: box.clientSeal({ live: 1 }, 'move', 1) } });
assert.equal(one.body.event.event_id, 1);
const firstText = await first.until('id: 1\n');
assert.ok(firstText.includes(JSON.stringify({ version: 1, event: one.body.event })));
const resumed = await stream(1);
await resumed.until(': API v1\n');
- const two = await box.call(box.path + '/moves', { method: 'POST', body: { sealed: seal(box.key, { live: 2 }) } });
+ const two = await box.call(box.path + '/moves', { method: 'POST', body: { sequence: 2, sealed: box.clientSeal({ live: 2 }, 'move', 2) } });
assert.equal(two.body.event.event_id, 2);
const resumedText = await resumed.until('id: 2\n');
assert.equal(resumedText.includes('id: 1\n'), false);
@@ -210,10 +242,10 @@ test('[A4,H7] live streams follow the same order, resume by cursor and stop afte
test('[A4,H7] a bounded large sealed snapshot is independent of the smaller move-body limit', async (t) => {
const box = await fixture(t);
const document = { record: 'a'.repeat(150_000) };
- const uploaded = await box.call(box.path + '/state', { method: 'PUT', body: { sequence: 0, sealed: seal(box.key, document) } });
+ const uploaded = await box.call(box.path + '/state', { method: 'PUT', body: { sequence: 0, sealed: box.clientSeal(document, 'snapshot', 0) } });
assert.equal(uploaded.status, 200);
- assert.deepEqual(unseal(box.key, uploaded.body.state.sealed), document);
- const oversizeMove = await box.call(box.path + '/moves', { method: 'POST', body: { sealed: seal(box.key, document) } });
+ assert.deepEqual(box.clientOpen(uploaded.body.state.sealed, 'snapshot', 0), document);
+ const oversizeMove = await box.call(box.path + '/moves', { method: 'POST', body: { sequence: 1, sealed: box.clientSeal(document, 'move', 1) } });
assert.equal(oversizeMove.status, 400);
assert.equal(oversizeMove.body.error.code, 'BAD_REQUEST');
assert.deepEqual((await box.call(box.path + '/events?after=0')).body.events, []);