Skip to content

Commit

Permalink
fix: better align with CWE id convention
Browse files Browse the repository at this point in the history
  • Loading branch information
thisislawatts committed Aug 17, 2022
1 parent e2fdb08 commit 2795aa9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/modules/security/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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
*
Expand Down
6 changes: 3 additions & 3 deletions test/__snapshots__/security.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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"`;
2 changes: 1 addition & 1 deletion test/security.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]+)$/);
});
});

Expand Down

0 comments on commit 2795aa9

Please sign in to comment.