-
Notifications
You must be signed in to change notification settings - Fork 0
/
verifier_test.ts
59 lines (57 loc) · 1.7 KB
/
verifier_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { assertEquals } from "https://deno.land/[email protected]/assert/mod.ts";
import { existsSync } from "https://deno.land/[email protected]/fs/mod.ts";
import { verify } from "./index.ts";
import { parse } from "./sig_parser.ts";
for await (const entry of Deno.readDir("fixtures")) {
if (entry.name.endsWith(".sig")) {
Deno.test(
{
permissions: { read: true, write: true, run: true },
ignore: existsSync(
`fixtures/${entry.name.replace(/\.sig$/, ".ignore")}`,
),
name: entry.name,
},
async () => {
const signature = parse(
await Deno.readTextFile(`fixtures/${entry.name}`),
);
assertEquals(
await verify(
signature,
await Deno.readTextFile(
`fixtures/${entry.name.replace(/\.sig$/, "")}`,
),
),
true,
"signature verification should succeed",
);
const allowedSigners = await Deno.makeTempFile();
await Deno.writeTextFile(
allowedSigners,
`[email protected] ${signature.publickey}`,
);
const command = new Deno.Command("ssh-keygen", {
args: [
"-Y",
"verify",
"-f",
allowedSigners,
"-I",
"-n",
"file",
"-s",
`fixtures/${entry.name}`,
],
stdin: "piped",
});
const child = command.spawn();
Deno.openSync(`fixtures/${entry.name.replace(/\.sig$/, "")}`).readable
.pipeTo(child.stdin);
const status = await child.status;
assertEquals(status.success, true);
},
);
}
}