Skip to content

Commit 4a96d3c

Browse files
authored
Return 404 when the null version is provided to the license endpoint (#9297)
Address #9295
1 parent 6ce4702 commit 4a96d3c

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/NuGetGallery/Controllers/PackagesController.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,11 @@ public virtual ActionResult AtomFeed(string id, bool prerel = true)
11741174
[HttpGet]
11751175
public virtual async Task<ActionResult> License(string id, string version)
11761176
{
1177+
if (version == null)
1178+
{
1179+
return HttpNotFound();
1180+
}
1181+
11771182
var package = _packageService.FindPackageByIdAndVersionStrict(id, version);
11781183
if (package == null || package.PackageStatusKey == PackageStatus.Deleted)
11791184
{

tests/NuGetGallery.Facts/Controllers/PackagesControllerFacts.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10071,6 +10071,21 @@ public async Task GivenInvalidPackageReturns404()
1007110071
Assert.IsType<HttpNotFoundResult>(result);
1007210072
}
1007310073

10074+
[Fact]
10075+
public async Task GivenNullVersionReturns404()
10076+
{
10077+
// arrange
10078+
var controller = CreateController(
10079+
GetConfigurationService(),
10080+
packageService: _packageService);
10081+
10082+
// act
10083+
var result = await controller.License(_packageId, version: null);
10084+
10085+
// assert
10086+
Assert.IsType<HttpNotFoundResult>(result);
10087+
}
10088+
1007410089
[Fact]
1007510090
public async Task GivenDeletedPackageReturns404()
1007610091
{

0 commit comments

Comments
 (0)