Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

3.0 KB
Raw Blame
import test from "node:test";
import assert from "node:assert/strict";
import {readFile} from "node:fs/promises";
import {actionShape, allowedUrl, domains, pairingCode, retryDelay, serverOrigin} from "../../dodaios/assets/chrome-extension/policy.mjs";

test("pairing stays on a literal loopback origin without credential or path smuggling", () => {
  assert.equal(serverOrigin("http://127.0.0.1:8765"), "http://127.0.0.1:8765");
  for (const value of ["https://127.0.0.1", "http://localhost", "http://example.com", "http://[email protected]", "http://127.0.0.1/?token=bad", "http://127.0.0.1/api"]) {
    assert.throws(() => serverOrigin(value));
  }
});

test("pairing accepts every URL-safe token character generated by the server", () => {
  assert.equal(pairingCode("abcdefghijklmnopqrstuvwxyzAB_-12"), "abcdefghijklmnopqrstuvwxyzAB_-12");
  for (const code of ["short", "a".repeat(65), "token/with+unsafe", "token with spaces", null]) {
    assert.throws(() => pairingCode(code));
  }
});

test("website grants fail closed for empty lists, scheme, credentials, ports, and suffix confusion", () => {
  const allowed = domains(["X.COM", "example.com"]);
  assert.equal(allowedUrl("https://x.com/home", allowed), true);
  assert.equal(allowedUrl("https://sub.example.com/a", allowed), true);
  for (const value of ["https://evilx.com/", "https://x.com.evil.test/", "https://[email protected]/", "https://[email protected]/", "https://x.com:444/", "file:///tmp/file", "javascript:alert(1)", "https://x.com\\@evil.test/", "https://x.com./", "chrome://settings"]) {
    assert.equal(allowedUrl(value, allowed), false, value);
  }
  assert.equal(allowedUrl("https://x.com", []), false);
  assert.equal(allowedUrl("about:blank", [], true), true);
  assert.equal(allowedUrl("about:blank", []), false);
  for (const list of [["*"], ["localhost"], ["127.0.0.1"], ["https://x.com"], ["x..com"]]) assert.throws(() => domains(list));
});

test("model actions cannot inject CDP, selectors, code, NaN, or extra parameters", () => {
  assert.deepEqual(actionShape({click: {index: 1}}), ["click", {index: 1}]);
  for (const action of [{evaluate: {expression: "1"}}, {click: {index: 1, selector: "body"}}, {click: {index: true}}, {scroll: {dy: NaN}}, {navigate: {url: {}}}, {input: {index: 1, text: "x".repeat(10001)}}]) {
    assert.throws(() => actionShape(action));
  }
});

test("reconnect delays have jitter and bounded exponential backoff", () => {
  assert.notEqual(retryDelay(2, () => 0), retryDelay(2, () => 1));
  assert.ok(retryDelay(30, () => 1) <= 75000);
  assert.ok(retryDelay(0, () => 0) >= 750);
});

test("extension does not export cookies or expose a public message bridge", async () => {
  const manifest = JSON.parse(await readFile(new URL("../../dodaios/assets/chrome-extension/manifest.json", import.meta.url), "utf8"));
  assert.equal(manifest.manifest_version, 3);
  assert.equal(manifest.permissions.includes("cookies"), false);
  assert.equal(manifest.externally_connectable, undefined);
  assert.equal(manifest.content_scripts, undefined);
});