Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nuget): gracefully accept a lack of a PackageBaseAddress resource #25355

Merged
merged 11 commits into from
Oct 26, 2023
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
dhduvall marked this conversation as resolved.
Show resolved Hide resolved
"version": "3.0.0",
"resources": [
{
"@id": "https://api.nuget.org/v3/query",
"@type": "SearchQueryService",
"comment": "Filter and search for packages by keyword."
},
{
"@id": "https://api.nuget.org/v3/query",
"@type": "SearchQueryService/3.0.0-beta",
"comment": "Filter and search for packages by keyword."
},
{
"@id": "https://api.nuget.org/v3/query",
"@type": "SearchQueryService/3.0.0-rc",
"comment": "Filter and search for packages by keyword."
},
{
"@id": "https://api.nuget.org/v3/metadata",
"@type": "RegistrationsBaseUrl",
"comment": "Get package metadata."
},
{
"@id": "https://api.nuget.org/v3/metadata",
"@type": "RegistrationsBaseUrl/3.0.0-beta",
"comment": "Get package metadata."
},
{
"@id": "https://api.nuget.org/v3/metadata",
"@type": "RegistrationsBaseUrl/3.0.0-rc",
"comment": "Get package metadata."
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"count": 1,
"items": [
{
"@id": "https://api.nuget.org/v3/metadata/nunit/5.0.json",
"lower": "5.0",
"upper": "5.0",
"count": 1,
"items": [
{
"@id": "foo",
"packageContent": "foo",
"catalogEntry": {
"id": "nunit",
"version": "5.0"
}
}
]
}
]
}
25 changes: 25 additions & 0 deletions lib/modules/datasource/nuget/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,31 @@ describe('modules/datasource/nuget/index', () => {
expect(res).toBeNull();
dhduvall marked this conversation as resolved.
Show resolved Hide resolved
});

// This is for coverage and to make sure we don't completely fall over--we
// don't have a way to test if we successfully replaced the TypeError.
dhduvall marked this conversation as resolved.
Show resolved Hide resolved
it(`doesn't trigger a TypeError when PackageBaseAddress is missing from service index`, async () => {
const nugetIndexV3NoPackageBaseAddress = Fixtures.get(
'v3_index_no_packagebaseaddress.json'
);
const nugetRegistrationV3NoPackageBaseAddress = Fixtures.get(
'v3_registration_no_packagebaseaddress.json'
);

httpMock
.scope('https://api.nuget.org')
.get('/v3/index.json')
.reply(200, nugetIndexV3NoPackageBaseAddress)
.get('/v3/metadata/nunit/index.json')
.reply(200, nugetRegistrationV3NoPackageBaseAddress)
.get('/v3/index.json')
.reply(200, nugetIndexV3NoPackageBaseAddress);
const res = await getPkgReleases({
...configV3,
});
expect(res).not.toBeNull();
expect(res!.releases).toHaveLength(1);
});

it('returns null for non 200 (v3v2)', async () => {
httpMock.scope('https://api.nuget.org').get('/v3/index.json').reply(500);
httpMock
Expand Down
6 changes: 6 additions & 0 deletions lib/modules/datasource/nuget/v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ export async function getResourceUrl(
? semver.compare(x.version, y.version)
: /* istanbul ignore next: hard to test */ 0
);

// replace a TypeError in the deconstruction with a custom one
if (services.length === 0) {
throw new Error(`no ${resourceType} services found`);
}
dhduvall marked this conversation as resolved.
Show resolved Hide resolved

const { serviceId, version } = services.pop()!;

// istanbul ignore if
Expand Down