-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolicy.test.ts
80 lines (73 loc) · 2.21 KB
/
policy.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import * as policy from 'snyk-policy';
import { test } from 'tap';
import { extendExpiries } from './utils';
import * as path from 'path';
test('policy is callable with string', async (t) => {
const dir = path.resolve(__dirname + '/fixtures/jsbin-snyk-config');
try {
await policy.load(dir);
t.pass('called with string');
t.end();
} catch (e) {
t.fail(e);
}
});
test('policy is callable with array', async (t) => {
const dir = path.resolve(__dirname + '/fixtures/jsbin-snyk-config');
try {
await policy.load([dir]);
t.pass('called with array');
t.end();
} catch (e) {
t.fail(e);
}
});
test('policy is callable with string and options', async (t) => {
const dir = path.resolve(__dirname + '/fixtures/jsbin-snyk-config');
try {
await policy.load(dir, { 'ignore-policy': true });
t.pass('called with string and options');
t.end();
} catch (e) {
t.fail(e);
}
});
test('test sensibly bails if gets an old .snyk format', async (t) => {
const dir = path.resolve(__dirname + '/fixtures/jsbin-snyk-config');
const vulns = require('./fixtures/test-jsbin-vulns-updated.json');
const id = 'npm:semver:20150403';
const vuln = vulns.vulnerabilities
.filter((v) => {
return v.id === id;
})
.pop();
try {
const config = await policy.load(dir);
const rule = policy.getByVuln(config, vuln);
t.equal(id, rule.id);
t.equal(rule.type, 'ignore', 'rule is correctly flagged as ignore');
const notfound = policy.getByVuln(config, 'unknown');
t.equal(notfound, null, 'unknown policies are null');
t.end();
} catch (e) {
console.log(e.stack);
t.fail('could not load the policy file');
t.end();
}
});
test('policy ignores correctly', async (t) => {
const dir = path.resolve(__dirname + '/fixtures/hapi-azure-post-update/');
const vulns = require(dir + '/test.json');
try {
const config = await policy.load(dir);
// strip the ignored modules from the results
extendExpiries(config);
const vuln = config.filter(vulns);
t.equal(vuln.vulnerabilities.length, 2, 'only qs vuln should remain');
t.end();
} catch (e) {
console.log(e.stack);
t.fail('could not load the policy file');
t.end();
}
});