-
-
Notifications
You must be signed in to change notification settings - Fork 953
/
Copy pathsecurity.spec.ts
56 lines (48 loc) · 1.62 KB
/
security.spec.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
import { afterEach, describe, expect, it } from 'vitest';
import { faker } from '../src';
import { seededTests } from './support/seededRuns';
const NON_SEEDED_BASED_RUN = 5;
describe('security', () => {
afterEach(() => {
faker.locale = 'en';
});
seededTests(faker, 'security', (t) => {
t.describe('cve', (t) =>
t
.it('with from date', { from: '2022-08-16' })
.it('with to date', { to: '2022-08-16' })
.it('with from and to date', { from: '2002-08-16', to: '2022-08-16' })
);
t.itEach('cwe', 'cvss');
});
describe(`random seeded tests for seed ${JSON.stringify(
faker.seed()
)}`, () => {
for (let i = 1; i <= NON_SEEDED_BASED_RUN; i++) {
describe('cve()', () => {
it('should return a well formed string', () => {
expect(faker.security.cve()).toMatch(/^CVE-[0-9]{4}-[0-9]{4}/);
});
});
describe('cwe()', () => {
it('should return a well formed string', () => {
expect(faker.security.cwe()).toMatch(/^CWE-([0-9]+)$/);
});
});
describe('cvss()', () => {
it('should return an object', () => {
const cvss = faker.security.cvss();
expect(cvss).toBeTypeOf('object');
});
it('should return a numeric value', () => {
expect(faker.security.cvss().score).toEqual(expect.any(Number));
});
it('should return a well formed string', () => {
expect(faker.security.cvss().vector).toMatch(
/^CVSS:3.1\/AV:[NALP]\/AC:[LH]\/PR:[NLH]\/UI:[NR]\/S:[UC]\/C:[NLH]\/I:[NLH]\/A:[NLH]/
);
});
});
}
});
});