Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions test/helpers/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ export async function startHarness(extraEnv: Record<string, string> = {}): Promi
// bin/bloks-server.mjs sets this, so a test run from inside a Bloks
// agent would inherit it and find pairing forced on
BLOKS_LOOPBACK_ONLY: "",
// and this, which makes any request without that start's key a
// stranger's (server/local-key.ts), the readiness check below
// included; a test of the key turns it on in extraEnv
BLOKS_LOCAL_KEY: "",
// and these, which would make a test's server think it was
// started by bloks-server and may update itself; a test that
// wants releases serves its own (server/server-update.ts)
Expand Down
16 changes: 16 additions & 0 deletions test/local-key.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ test("the app's own server needs no key: its window is its own page", async (t)
assert.equal((await fetch(`${h.url}/api/config`)).status, 200);
});

test("tests run inside bloks-server still get a server without the key", async (t) => {
// bin/bloks-server.mjs sets the flag for everything it starts, an agent
// running these tests included; a harness that kept it would never pass
// its own readiness check, which carries no key
const before = process.env.BLOKS_LOCAL_KEY;
process.env.BLOKS_LOCAL_KEY = "1";
t.after(() => {
if (before === undefined) delete process.env.BLOKS_LOCAL_KEY;
else process.env.BLOKS_LOCAL_KEY = before;
});
const h = await startHarness();
t.after(() => h.stop());
assert.equal((await fetch(`${h.url}/api/config`)).status, 200);
assert.equal(existsSync(join(h.home, ".bloks", LOCAL_KEY_FILE)), false, "the server made a key");
});

test("an agent's own turn credential works on a server started with the key, and nothing wider does", async (t) => {
// #480: the agent block let the credential through, then the remote
// surface took the request for a stranger's and sent it to pair
Expand Down