Skip to content

Commit

Permalink
refactor(vulnerabilities): rename fetchVulnerabilities to appendVulne…
Browse files Browse the repository at this point in the history
…rabilityPackageRules (#21468)
  • Loading branch information
secustor committed Apr 12, 2023
1 parent 9b481c4 commit 9d28710
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 26 deletions.
6 changes: 3 additions & 3 deletions lib/workers/repository/process/extract-update.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ describe('workers/repository/process/extract-update', () => {
suppressNotifications: ['deprecationWarningIssues'],
osvVulnerabilityAlerts: true,
};
const fetchVulnerabilitiesMock = jest.fn();
const appendVulnerabilityPackageRulesMock = jest.fn();
createVulnerabilitiesMock.mockResolvedValueOnce({
fetchVulnerabilities: fetchVulnerabilitiesMock,
appendVulnerabilityPackageRules: appendVulnerabilityPackageRulesMock,
});
repositoryCache.getCache.mockReturnValueOnce({ scan: {} });
git.checkoutBranch.mockResolvedValueOnce('123test');
Expand All @@ -127,7 +127,7 @@ describe('workers/repository/process/extract-update', () => {
await lookup(config, packageFiles);

expect(createVulnerabilitiesMock).toHaveBeenCalledOnce();
expect(fetchVulnerabilitiesMock).toHaveBeenCalledOnce();
expect(appendVulnerabilityPackageRulesMock).toHaveBeenCalledOnce();
});

it('handles exception when fetching vulnerabilities', async () => {
Expand Down
5 changes: 4 additions & 1 deletion lib/workers/repository/process/extract-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ async function fetchVulnerabilities(
if (config.osvVulnerabilityAlerts) {
try {
const vulnerabilities = await Vulnerabilities.create();
await vulnerabilities.fetchVulnerabilities(config, packageFiles);
await vulnerabilities.appendVulnerabilityPackageRules(
config,
packageFiles
);
} catch (err) {
logger.warn({ err }, 'Unable to read vulnerability information');
}
Expand Down
105 changes: 84 additions & 21 deletions lib/workers/repository/process/vulnerabilities.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ describe('workers/repository/process/vulnerabilities', () => {
],
};

await vulnerabilities.fetchVulnerabilities(config, packageFiles);
await vulnerabilities.appendVulnerabilityPackageRules(
config,
packageFiles
);
expect(logger.logger.trace).toHaveBeenCalledWith(
'Cannot map datasource docker to OSV ecosystem'
);
Expand All @@ -97,7 +100,10 @@ describe('workers/repository/process/vulnerabilities', () => {
};
getVulnerabilitiesMock.mockResolvedValueOnce([]);

await vulnerabilities.fetchVulnerabilities(config, packageFiles);
await vulnerabilities.appendVulnerabilityPackageRules(
config,
packageFiles
);
expect(logger.logger.trace).toHaveBeenCalledWith(
'No vulnerabilities found in OSV database for lodash'
);
Expand All @@ -121,7 +127,10 @@ describe('workers/repository/process/vulnerabilities', () => {
},
]);

await vulnerabilities.fetchVulnerabilities(config, packageFiles);
await vulnerabilities.appendVulnerabilityPackageRules(
config,
packageFiles
);
expect(config.packageRules).toHaveLength(0);
});

Expand All @@ -143,7 +152,10 @@ describe('workers/repository/process/vulnerabilities', () => {
},
]);

await vulnerabilities.fetchVulnerabilities(config, packageFiles);
await vulnerabilities.appendVulnerabilityPackageRules(
config,
packageFiles
);
expect(logger.logger.trace).toHaveBeenCalledWith(
'Skipping withdrawn vulnerability GHSA-x5rq-j2xg-h7qm'
);
Expand All @@ -167,7 +179,10 @@ describe('workers/repository/process/vulnerabilities', () => {
};
getVulnerabilitiesMock.mockResolvedValueOnce([lodashVulnerability]);

await vulnerabilities.fetchVulnerabilities(config, packageFiles);
await vulnerabilities.appendVulnerabilityPackageRules(
config,
packageFiles
);
expect(logger.logger.debug).toHaveBeenCalledWith(
'Skipping vulnerability lookup for package lodash due to unsupported version #4.17.11'
);
Expand All @@ -191,7 +206,10 @@ describe('workers/repository/process/vulnerabilities', () => {
};
getVulnerabilitiesMock.mockRejectedValueOnce(err);

await vulnerabilities.fetchVulnerabilities(config, packageFiles);
await vulnerabilities.appendVulnerabilityPackageRules(
config,
packageFiles
);
expect(logger.logger.warn).toHaveBeenCalledWith(
{ err },
'Error fetching vulnerability information for lodash'
Expand Down Expand Up @@ -236,7 +254,10 @@ describe('workers/repository/process/vulnerabilities', () => {
},
]);

await vulnerabilities.fetchVulnerabilities(config, packageFiles);
await vulnerabilities.appendVulnerabilityPackageRules(
config,
packageFiles
);
expect(logger.logger.debug).toHaveBeenCalledWith(
{ event },
'Skipping OSV event with invalid version'
Expand Down Expand Up @@ -266,7 +287,10 @@ describe('workers/repository/process/vulnerabilities', () => {
},
]);

await vulnerabilities.fetchVulnerabilities(config, packageFiles);
await vulnerabilities.appendVulnerabilityPackageRules(
config,
packageFiles
);
expect(config.packageRules).toHaveLength(0);
});

Expand Down Expand Up @@ -294,7 +318,10 @@ describe('workers/repository/process/vulnerabilities', () => {
},
]);

await vulnerabilities.fetchVulnerabilities(config, packageFiles);
await vulnerabilities.appendVulnerabilityPackageRules(
config,
packageFiles
);
expect(logger.logger.info).toHaveBeenCalledWith(
'No fixed version available for vulnerability GHSA-xxxx-yyyy-zzzz in fake 4.17.11'
);
Expand Down Expand Up @@ -333,7 +360,10 @@ describe('workers/repository/process/vulnerabilities', () => {
},
]);

await vulnerabilities.fetchVulnerabilities(config, packageFiles);
await vulnerabilities.appendVulnerabilityPackageRules(
config,
packageFiles
);
expect(logger.logger.info).toHaveBeenCalledWith(
'No fixed version available for vulnerability GHSA-xxxx-yyyy-zzzz in fake 1.5.1'
);
Expand Down Expand Up @@ -379,7 +409,10 @@ describe('workers/repository/process/vulnerabilities', () => {
},
]);

await vulnerabilities.fetchVulnerabilities(config, packageFiles);
await vulnerabilities.appendVulnerabilityPackageRules(
config,
packageFiles
);
expect(logger.logger.debug).toHaveBeenCalledWith(
'Vulnerability GO-2022-0187 affects stdlib 1.7.5'
);
Expand Down Expand Up @@ -454,7 +487,10 @@ describe('workers/repository/process/vulnerabilities', () => {
},
]);

await vulnerabilities.fetchVulnerabilities(config, packageFiles);
await vulnerabilities.appendVulnerabilityPackageRules(
config,
packageFiles
);
expect(config.packageRules).toHaveLength(1);
expect(config.packageRules).toMatchObject([
{
Expand Down Expand Up @@ -513,7 +549,10 @@ describe('workers/repository/process/vulnerabilities', () => {
},
]);

await vulnerabilities.fetchVulnerabilities(config, packageFiles);
await vulnerabilities.appendVulnerabilityPackageRules(
config,
packageFiles
);
expect(config.packageRules).toHaveLength(2);
expect(config.packageRules).toMatchObject([
{
Expand Down Expand Up @@ -546,7 +585,10 @@ describe('workers/repository/process/vulnerabilities', () => {
};
getVulnerabilitiesMock.mockResolvedValueOnce([lodashVulnerability]);

await vulnerabilities.fetchVulnerabilities(config, packageFiles);
await vulnerabilities.appendVulnerabilityPackageRules(
config,
packageFiles
);
expect(config.packageRules).toHaveLength(0);
});

Expand Down Expand Up @@ -607,7 +649,10 @@ describe('workers/repository/process/vulnerabilities', () => {
},
]);

await vulnerabilities.fetchVulnerabilities(config, packageFiles);
await vulnerabilities.appendVulnerabilityPackageRules(
config,
packageFiles
);

expect(config.packageRules).toHaveLength(1);
expect(config.packageRules).toMatchObject([
Expand Down Expand Up @@ -686,7 +731,10 @@ describe('workers/repository/process/vulnerabilities', () => {
},
]);

await vulnerabilities.fetchVulnerabilities(config, packageFiles);
await vulnerabilities.appendVulnerabilityPackageRules(
config,
packageFiles
);

expect(config.packageRules).toHaveLength(2);
expect(config.packageRules).toMatchObject([
Expand Down Expand Up @@ -740,7 +788,10 @@ describe('workers/repository/process/vulnerabilities', () => {
},
]);

await vulnerabilities.fetchVulnerabilities(config, packageFiles);
await vulnerabilities.appendVulnerabilityPackageRules(
config,
packageFiles
);
expect(logger.logger.debug).not.toHaveBeenCalledWith(
'OSV advisory GHSA-xxxx-yyyy-zzzz lists quokka 1.2.3 as vulnerable'
);
Expand Down Expand Up @@ -784,7 +835,10 @@ describe('workers/repository/process/vulnerabilities', () => {
},
]);

await vulnerabilities.fetchVulnerabilities(config, packageFiles);
await vulnerabilities.appendVulnerabilityPackageRules(
config,
packageFiles
);
expect(config.packageRules).toHaveLength(1);
expect(config.packageRules).toMatchObject([
{
Expand Down Expand Up @@ -859,7 +913,10 @@ describe('workers/repository/process/vulnerabilities', () => {
},
]);

await vulnerabilities.fetchVulnerabilities(config, packageFiles);
await vulnerabilities.appendVulnerabilityPackageRules(
config,
packageFiles
);

expect(logger.logger.debug).toHaveBeenCalledWith(
'Error processing CVSS vector some-invalid-score'
Expand Down Expand Up @@ -921,7 +978,10 @@ describe('workers/repository/process/vulnerabilities', () => {
},
]);

await vulnerabilities.fetchVulnerabilities(config, packageFiles);
await vulnerabilities.appendVulnerabilityPackageRules(
config,
packageFiles
);

expect(config.packageRules).toHaveLength(1);
expect(config.packageRules).toMatchObject([
Expand Down Expand Up @@ -1003,7 +1063,10 @@ describe('workers/repository/process/vulnerabilities', () => {
},
]);

await vulnerabilities.fetchVulnerabilities(config, packageFiles);
await vulnerabilities.appendVulnerabilityPackageRules(
config,
packageFiles
);

expect(config.packageRules).toHaveLength(1);
expect(config.packageRules).toMatchObject([
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/repository/process/vulnerabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class Vulnerabilities {
return instance;
}

async fetchVulnerabilities(
async appendVulnerabilityPackageRules(
config: RenovateConfig,
packageFiles: Record<string, PackageFile[]>
): Promise<void> {
Expand Down

0 comments on commit 9d28710

Please sign in to comment.