fix: check returned pypi name against requested name

This commit is contained in:
Rhys Arkins 2018-07-05 11:25:48 +02:00
parent db38553d05
commit 9153e3905f
2 changed files with 19 additions and 0 deletions

View file

@ -17,6 +17,13 @@ async function getDependency(purl) {
logger.debug({ depName }, 'pip package not found'); logger.debug({ depName }, 'pip package not found');
return null; return null;
} }
if (!(dep.info && dep.info.name === depName)) {
logger.warn(
{ lookupName: depName, returnedName: dep.name },
'Returned name does not match with requested name'
);
return null;
}
if (dep.info && dep.info.home_page) { if (dep.info && dep.info.home_page) {
if (dep.info.home_page.startsWith('https://github.com')) { if (dep.info.home_page.startsWith('https://github.com')) {
dependency.repositoryUrl = dep.info.home_page; dependency.repositoryUrl = dep.info.home_page;

View file

@ -30,6 +30,7 @@ describe('datasource/pypi', () => {
got.mockReturnValueOnce({ got.mockReturnValueOnce({
body: { body: {
info: { info: {
name: 'something',
home_page: 'https://microsoft.com', home_page: 'https://microsoft.com',
}, },
}, },
@ -38,5 +39,16 @@ describe('datasource/pypi', () => {
await datasource.getDependency('pkg:pypi/something') await datasource.getDependency('pkg:pypi/something')
).toMatchSnapshot(); ).toMatchSnapshot();
}); });
it('returns null if mismatched name', async () => {
got.mockReturnValueOnce({
body: {
info: {
name: 'something-else',
home_page: 'https://microsoft.com',
},
},
});
expect(await datasource.getDependency('pkg:pypi/something')).toBeNull();
});
}); });
}); });