-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.test.js
100 lines (90 loc) · 3.23 KB
/
cli.test.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import test from 'node:test';
import assert from 'node:assert';
import {execa} from 'execa';
test('Input without "contact" or "expires" flags shows help', async () => {
const {exitCode} = await execa('./cli.js').catch(error => error);
assert.strictEqual(exitCode, 2);
});
test('Input with "contact", but without "expires" flags shows help', async () => {
const {exitCode} = await execa('./cli.js', [
'-c [email protected]',
]).catch(error => error);
assert.strictEqual(exitCode, 2);
});
test('Input with "expires", but without "contact" flags shows help', async () => {
const {exitCode} = await execa('./cli.js', [
'-e 7',
]).catch(error => error);
assert.strictEqual(exitCode, 2);
});
test('Input with minimal flags', async () => {
const {stdout} = await execa('./cli.js', [
'--expires=6',
]);
assert.match(stdout, /Contact:\smailto:[email protected]\n/);
assert.match(stdout, /Expires:\s(.+)/);
});
test('Input with all flags', async () => {
const {stdout} = await execa('./cli.js', [
'--expires=6',
'--lang=en',
'--canonical=https://acme.org/.well-known/security.txt',
'--encryption=https://acme.org/key.asc',
'--ack=https://acme.org/security/acknowledgments.txt',
'--policy=https://acme.org/security/policy.txt',
'--hiring=https://acme.org/jobs',
]);
assert.match(stdout, /Contact:\smailto:[email protected]\n/);
assert.match(stdout, /Expires:\s(.+)\n/);
assert.match(stdout, /Preferred-Languages:\sen\n/);
assert.match(stdout, /Canonical:\shttps:\/\/acme\.org\/\.well-known\/security\.txt\n/);
assert.match(stdout, /Encryption:\shttps:\/\/acme\.org\/key\.asc\n/);
assert.match(stdout, /Acknowledgments:\shttps:\/\/acme\.org\/security\/acknowledgments\.txt\n/);
assert.match(stdout, /Policy:\shttps:\/\/acme\.org\/security\/policy\.txt\n/);
assert.match(stdout, /Hiring:\shttps:\/\/acme\.org\/jobs/);
});
test('Input with more than one contact point', async () => {
const {stdout} = await execa('./cli.js', [
'--contact=https://acme.org/contact',
'--expires=6',
]);
assert.match(stdout, /Contact:\smailto:[email protected]\n/);
assert.match(stdout, /Contact:\shttps:\/\/acme\.org\/contact\n/);
assert.match(stdout, /Expires:\s(.+)/);
});
test('Input with more than one preferred language', async () => {
const {stdout} = await execa('./cli.js', [
'--expires=6',
'--lang=en',
'--lang=fi',
]);
assert.match(stdout, /Contact:\smailto:[email protected]\n/);
assert.match(stdout, /Expires:\s(.+)\n/);
assert.match(stdout, /Preferred-Languages:\sen,\sfi/);
});
test('Input with "expires" as a numeric value', async () => {
const {stdout} = await execa('./cli.js', [
'--expires=6',
]);
assert.match(stdout, /Expires:\s(.+)/);
});
test('Input with "expires" as an ISO date', async () => {
const date = '2080-08-01T15:00:00Z';
const {stdout} = await execa('./cli.js', [
`--expires=${date}`,
]);
assert.match(stdout, /Expires:\s(\w+)/);
});
test('Input with an unparseable "expires" value shows help', async () => {
const {exitCode} = await execa('./cli.js', [
'-c [email protected]',
'-e FAIL',
]).catch(error => error);
assert.strictEqual(exitCode, 2);
});