Skip to content

Commit d5849fc

Browse files
fix(js): the deno tests grant through the importer
1 parent bbdf38a commit d5849fc

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

‎js/tests/deno.test.js‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,14 @@ Deno.test("deno: a grant belongs to the package it names", async () => {
146146
if (child.out !== "" || child.text !== "True") throw new Error(`unexpected ${JSON.stringify(child)}`);
147147
});
148148

149-
// A package named main answers to its dir, so it never borrows the grant of main.
149+
// A package named main answers to its import key, so it never borrows the grant of main.
150150
Deno.test("deno: a package named main never takes the grant of main", async () => {
151151
const got = await output("named-main", "from clock import now\nprint(now() > 0)", await project({
152152
"clock/edge.json": JSON.stringify({ name: "main" }),
153153
"clock/main.py": "import time\n\ndef now():\n return time.now()\n",
154154
"edge.json": JSON.stringify({ imports: { clock: "./clock/main.py" }, permissions: { main: ["time:wall"] } }),
155155
}));
156-
if (!got.out.includes("'clock/' imports time, which edge.json does not grant it")) throw new Error(`unexpected ${JSON.stringify(got)}`);
156+
if (!got.out.includes("'clock' imports time, which edge.json does not grant it")) throw new Error(`unexpected ${JSON.stringify(got)}`);
157157
});
158158

159159
// No JavaScript loads besides the host's own, so an import of one fails where it is written.
@@ -173,20 +173,22 @@ Deno.test("deno: a helper the root imports by a ./ path belongs to main", async
173173
if (got.out !== "" || got.text !== "True") throw new Error(`unexpected ${JSON.stringify(got)}`);
174174
});
175175

176-
// However deep a package sits, it answers to its own grant, never to the package that imported it.
177-
Deno.test("deno: a grandchild answers to its own grant", async () => {
178-
const files = {
179-
"clock/edge.json": JSON.stringify({ name: "clock", imports: { trace: "./trace/main.py" } }),
176+
// A package below the root holds what its importer passes it, and never more than that importer holds.
177+
Deno.test("deno: a grandchild holds what its importer passes it", async () => {
178+
const files = (passes) => ({
179+
"clock/edge.json": JSON.stringify({ name: "clock", imports: { trace: "./trace/main.py" }, permissions: passes }),
180180
"clock/main.py": "from trace import stamp\n\ndef now():\n return stamp()\n",
181181
"clock/trace/edge.json": JSON.stringify({ name: "trace" }),
182182
"clock/trace/main.py": "import time\n\ndef stamp():\n return time.now() > 0\n",
183-
};
183+
});
184184
const manifest = (permissions) => JSON.stringify({ imports: { clock: "./clock/main.py" }, permissions });
185185
const src = "from clock import now\nprint(now())";
186-
const borrowed = await output("borrowed", src, await project({ ...files, "edge.json": manifest({ main: ["time:wall"], clock: ["time:wall"] }) }));
187-
if (!borrowed.out.includes("'trace' imports time, which edge.json does not grant it")) throw new Error(`unexpected ${JSON.stringify(borrowed)}`);
188-
const own = await output("own", src, await project({ ...files, "edge.json": manifest({ trace: ["time:wall"] }) }));
189-
if (own.out !== "" || own.text !== "True") throw new Error(`unexpected ${JSON.stringify(own)}`);
186+
const unpassed = await output("unpassed", src, await project({ ...files({}), "edge.json": manifest({ main: ["time:wall"], clock: ["time:wall"], trace: ["time:wall"] }) }));
187+
if (!unpassed.out.includes("'trace' imports time, which edge.json does not grant it")) throw new Error(`unexpected ${JSON.stringify(unpassed)}`);
188+
const unheld = await output("unheld", src, await project({ ...files({ trace: ["time:wall"] }), "edge.json": manifest({ main: ["time:wall"] }) }));
189+
if (!unheld.out.includes("'trace' imports time, which edge.json does not grant it")) throw new Error(`unexpected ${JSON.stringify(unheld)}`);
190+
const passed = await output("passed", src, await project({ ...files({ trace: ["time:wall"] }), "edge.json": manifest({ clock: ["time:wall"] }) }));
191+
if (passed.out !== "" || passed.text !== "True") throw new Error(`unexpected ${JSON.stringify(passed)}`);
190192
});
191193

192194
Deno.test("deno: net reaches only the hosts its package holds", async () => {

0 commit comments

Comments
 (0)