@crawlcheck/sdk 1.8.0 → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/log.d.ts +1 -0
- package/dist/log.js +28 -5
- package/dist/verify.js +4 -1
- package/package.json +1 -1
- package/test/fixtures/key-policy.json +390 -221
- package/test/split-view.test.js +14 -0
package/test/split-view.test.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Worker's own log code in a test harness) must be detected offline, and the live log must check out consistent.
|
|
3
3
|
import test from "node:test"; import assert from "node:assert/strict"; import fs from "node:fs";
|
|
4
4
|
import { CrawlCheck, newLogStore, logObserve, logGossip, logHeads, verifyWitnessToken, verifyDocument } from "../dist/index.js";
|
|
5
|
+
import { walkHeads } from "../src/log.js";
|
|
5
6
|
const F = JSON.parse(fs.readFileSync(new URL("./fixtures/split-view.json", import.meta.url), "utf8"));
|
|
6
7
|
|
|
7
8
|
test("a forked log is detected by gossip: two signed heads for one batch", async () => {
|
|
@@ -26,6 +27,19 @@ test("the witness token binds one head: valid for it, refused for the forked hea
|
|
|
26
27
|
assert.equal((await verifyWitnessToken(F.witness.token, F.A[2].sha256, F.jwks)).ok, true);
|
|
27
28
|
assert.equal((await verifyWitnessToken(F.witness.token, F.B[2].sha256, F.jwks)).ok, false);
|
|
28
29
|
});
|
|
30
|
+
test("1.9.0: the chain walk reads 200 heads per request, and falls back to one per batch on an older server", async () => {
|
|
31
|
+
const calls = [];
|
|
32
|
+
const batched = async (p) => { calls.push(p); const m = /sths\?to=(\d+)&n=(\d+)/.exec(p); if (!m) throw new Error("404");
|
|
33
|
+
const to = +m[1], n = +m[2]; return { sths: Array.from({ length: n }, (_, i) => ({ kind: "crawlcheck-log-sth", batch: to - i })) }; };
|
|
34
|
+
let r = await walkHeads(batched, 449, 0);
|
|
35
|
+
assert.equal(r.length, 450); assert.deepEqual(r.slice(0, 2).map((x) => x.batch), [449, 448]); assert.equal(r[449].batch, 0);
|
|
36
|
+
assert.deepEqual(calls, ["/api/v1/log/sths?to=449&n=200", "/api/v1/log/sths?to=249&n=200", "/api/v1/log/sths?to=49&n=50"]);
|
|
37
|
+
calls.length = 0;
|
|
38
|
+
const old = async (p) => { calls.push(p); const m = /sth\/(\d+)$/.exec(p); if (!m) throw new Error("404"); return { sth: { kind: "crawlcheck-log-sth", batch: +m[1] } }; };
|
|
39
|
+
r = await walkHeads(old, 4, 2);
|
|
40
|
+
assert.deepEqual(r.map((x) => x.batch), [4, 3, 2]); assert.equal(calls.length, 4, "one refused batched call, then one per head");
|
|
41
|
+
assert.deepEqual(await walkHeads(batched, 3, 4), []);
|
|
42
|
+
});
|
|
29
43
|
test("live: the production log is consistent and GitHub's witness co-signature verifies", async () => {
|
|
30
44
|
const c = new CrawlCheck(); await c.resolve("github.com");
|
|
31
45
|
const r = await c.logCheck({ report: false });
|