fix: pinning digest of latest version (#2359)

If the dependency already is the latest version, filteredVersions is
empty here, and then the early exit skips over the pinning code
This commit is contained in:
Maximilian Gaß 2018-08-11 10:03:57 +02:00 committed by Rhys Arkins
parent eb167f571c
commit 15ee7ab4ae
3 changed files with 39 additions and 3 deletions

View file

@ -108,9 +108,6 @@ async function lookupUpdates(config) {
allVersions, allVersions,
releases releases
); );
if (!filteredVersions.length) {
return res;
}
const buckets = {}; const buckets = {};
for (const toVersion of filteredVersions) { for (const toVersion of filteredVersions) {
const update = { fromVersion, toVersion }; const update = { fromVersion, toVersion };

View file

@ -127,6 +127,26 @@ Object {
} }
`; `;
exports[`manager/npm/lookup .lookupUpdates() handles digest pin for up to date version 1`] = `
Object {
"releases": Array [
Object {
"version": "8.1.0",
},
],
"repositoryUrl": null,
"updates": Array [
Object {
"newDigest": "sha256:aaaaaaaaaaaaaaaa",
"newDigestShort": "aaaaaa",
"newValue": "8.1.0",
"updateType": "pin",
},
],
"warnings": Array [],
}
`;
exports[`manager/npm/lookup .lookupUpdates() handles digest update 1`] = ` exports[`manager/npm/lookup .lookupUpdates() handles digest update 1`] = `
Object { Object {
"releases": Array [ "releases": Array [

View file

@ -919,6 +919,25 @@ describe('manager/npm/lookup', () => {
const res = await lookup.lookupUpdates(config); const res = await lookup.lookupUpdates(config);
expect(res).toMatchSnapshot(); expect(res).toMatchSnapshot();
}); });
it('handles digest pin for up to date version', async () => {
config.currentValue = '8.1.0';
config.depName = 'node';
config.purl = 'pkg:docker/node';
config.pinDigests = true;
docker.getPkgReleases.mockReturnValueOnce({
releases: [
{
version: '8.0.0',
},
{
version: '8.1.0',
},
],
});
docker.getDigest.mockReturnValueOnce('sha256:aaaaaaaaaaaaaaaa');
const res = await lookup.lookupUpdates(config);
expect(res).toMatchSnapshot();
});
it('handles digest pin for non-version', async () => { it('handles digest pin for non-version', async () => {
config.currentValue = 'alpine'; config.currentValue = 'alpine';
config.depName = 'node'; config.depName = 'node';