Skip to content

Commit 2795aa9

Browse files
committed
fix: better align with CWE id convention
1 parent e2fdb08 commit 2795aa9

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/modules/security/index.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export class Security {
2020

2121
/**
2222
* Generates a random CVE between the given boundaries.
23+
* Based on:
24+
* https://www.cve.org/
2325
*
2426
* @param options The options to use. Defaults to `{}`.
2527
* @param options.from The early date boundary. Defaults to `1999-01-01T00:00:00.000Z`.
@@ -48,17 +50,19 @@ export class Security {
4850
}
4951

5052
/**
51-
* Generates a random CWE
53+
* Generates a random CWE (Common Weakness Enumeration) identifier.
54+
* Based on:
55+
* https://cwe.mitre.org/data/index.html
5256
*
5357
* @example
5458
* faker.security.cwe() // 'CWE-####'
5559
*/
5660
cwe(): string {
57-
return ['CWE', this.faker.random.numeric(4)].join('-');
61+
return ['CWE', this.faker.datatype.number({ min: 0, max: 1388 })].join('-');
5862
}
5963

6064
/**
61-
* Generates a random CVSS return
65+
* Generates a random CVSS.
6266
* Based on:
6367
* https://www.first.org/cvss/calculator/3.1
6468
*

test/__snapshots__/security.spec.ts.snap

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
exports[`security > seed: 42 > cve() 1`] = `"CVE-2007-79177"`;
44

5-
exports[`security > seed: 42 > cwe() 1`] = `"CWE-4791"`;
5+
exports[`security > seed: 42 > cwe() 1`] = `"CWE-520"`;
66

77
exports[`security > seed: 1211 > cve() 1`] = `"CVE-2020-48721"`;
88

9-
exports[`security > seed: 1211 > cwe() 1`] = `"CWE-9487"`;
9+
exports[`security > seed: 1211 > cwe() 1`] = `"CWE-1289"`;
1010

1111
exports[`security > seed: 1337 > cve() 1`] = `"CVE-2005-51225"`;
1212

13-
exports[`security > seed: 1337 > cwe() 1`] = `"CWE-3512"`;
13+
exports[`security > seed: 1337 > cwe() 1`] = `"CWE-363"`;

test/security.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('security', () => {
3939

4040
describe('cwe()', () => {
4141
it('should return a well formed string', () => {
42-
expect(faker.security.cwe()).toMatch(/^CWE-[0-9]{4}/);
42+
expect(faker.security.cwe()).toMatch(/^CWE-([0-9]+)$/);
4343
});
4444
});
4545

0 commit comments

Comments
 (0)