diff --git a/src/modules/security/index.ts b/src/modules/security/index.ts index e98d528fbe7..56d6623ed13 100644 --- a/src/modules/security/index.ts +++ b/src/modules/security/index.ts @@ -20,6 +20,8 @@ export class Security { /** * Generates a random CVE between the given boundaries. + * Based on: + * https://www.cve.org/ * * @param options The options to use. Defaults to `{}`. * @param options.from The early date boundary. Defaults to `1999-01-01T00:00:00.000Z`. @@ -48,17 +50,19 @@ export class Security { } /** - * Generates a random CWE + * Generates a random CWE (Common Weakness Enumeration) identifier. + * Based on: + * https://cwe.mitre.org/data/index.html * * @example * faker.security.cwe() // 'CWE-####' */ cwe(): string { - return ['CWE', this.faker.random.numeric(4)].join('-'); + return ['CWE', this.faker.datatype.number({ min: 0, max: 1388 })].join('-'); } /** - * Generates a random CVSS return + * Generates a random CVSS. * Based on: * https://www.first.org/cvss/calculator/3.1 * diff --git a/test/__snapshots__/security.spec.ts.snap b/test/__snapshots__/security.spec.ts.snap index d7b727847c2..f8c672a7148 100644 --- a/test/__snapshots__/security.spec.ts.snap +++ b/test/__snapshots__/security.spec.ts.snap @@ -2,12 +2,12 @@ exports[`security > seed: 42 > cve() 1`] = `"CVE-2007-79177"`; -exports[`security > seed: 42 > cwe() 1`] = `"CWE-4791"`; +exports[`security > seed: 42 > cwe() 1`] = `"CWE-520"`; exports[`security > seed: 1211 > cve() 1`] = `"CVE-2020-48721"`; -exports[`security > seed: 1211 > cwe() 1`] = `"CWE-9487"`; +exports[`security > seed: 1211 > cwe() 1`] = `"CWE-1289"`; exports[`security > seed: 1337 > cve() 1`] = `"CVE-2005-51225"`; -exports[`security > seed: 1337 > cwe() 1`] = `"CWE-3512"`; +exports[`security > seed: 1337 > cwe() 1`] = `"CWE-363"`; diff --git a/test/security.spec.ts b/test/security.spec.ts index 42547884a89..b6c126791bf 100644 --- a/test/security.spec.ts +++ b/test/security.spec.ts @@ -39,7 +39,7 @@ describe('security', () => { describe('cwe()', () => { it('should return a well formed string', () => { - expect(faker.security.cwe()).toMatch(/^CWE-[0-9]{4}/); + expect(faker.security.cwe()).toMatch(/^CWE-([0-9]+)$/); }); });