conststore=openStore(dir),p=store.get('policy');p.evidence={enabled:true,captureDownloads:true,captureInteractions:true};store.put('policy',p);consttoken='synthetic-pq-evidence-device-token-123456789',otherToken='synthetic-pq-evidence-other-token-123456789',id='device-a';store.db.prepare('INSERT INTO devices(id,token_hash,revoked) VALUES(?,?,0)').run(id,digest(token));store.db.prepare('INSERT INTO devices(id,token_hash,revoked) VALUES(?,?,0)').run('device-b',digest(otherToken));
assert.equal(f.store.db.prepare('SELECT count(*) n FROM protected_evidence').get().n,1);assert.equal(f.store.db.prepare("SELECT count(*) n FROM events WHERE kind='evidence.recorded'").get().n,1);
assert.equal(JSON.stringify(f.wire.filter(r=>r.route.includes('/channel/'))).includes(f.payload.payload.pageUrl),false);assert.equal(f.store.db.prepare('SELECT metadata FROM events').all().some(r=>r.metadata.includes(f.payload.payload.pageUrl)),false);
constrow=f.store.db.prepare('SELECT ciphertext FROM protected_evidence').get();assert.equal(Buffer.from(row.ciphertext).includes(Buffer.from(f.payload.payload.pageUrl)),false);
test('central disable after issuance returns encrypted denial and revoked credentials cannot upload',asynct=>{
constf=awaitfixture(t),a=awaitf.make(),p=f.store.get('policy');p.evidence.enabled=false;f.store.put('policy',p);constresponse=awaitf.api('/api/device/channel/evidence',a.context.request);assert.equal(response.status,200);assert.equal(channel.evidenceChannel.finish(response.body,a.bundle,a.context).status,403);assert.equal(f.store.db.prepare('SELECT count(*) n FROM protected_evidence').get().n,0);assert.equal((awaitf.api('/api/device/channel/evidence/challenge',{})).status,403);a.context.responseKey.fill(0);
p.evidence.enabled=true;f.store.put('policy',p);constb=awaitf.make();f.store.db.prepare('UPDATE devices SET revoked=1 WHERE id=?').run(f.device.id);assert.equal((awaitf.api('/api/device/channel/evidence',b.context.request)).status,401);b.context.responseKey.fill(0);
});
test('expired evidence challenge never decrypts or stores payload and remains one-use',asynct=>{
constnow=Date.now();t.mock.timers.enable({apis:['Date'],now});constf=awaitfixture(t),a=awaitf.make();t.mock.timers.setTime(now+60001);assert.equal((awaitf.api('/api/device/channel/evidence',a.context.request)).status,403);assert.equal((awaitf.api('/api/device/channel/evidence',a.context.request)).status,403);assert.equal(f.store.db.prepare('SELECT count(*) n FROM protected_evidence').get().n,0);a.context.responseKey.fill(0);