Skip to content

Commit

Permalink
Return 404 when the null version is provided to the license endpoint (#…
Browse files Browse the repository at this point in the history
…9297)

Address #9295
  • Loading branch information
joelverhagen committed Nov 3, 2022
1 parent 6ce4702 commit 4a96d3c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/NuGetGallery/Controllers/PackagesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,11 @@ public virtual ActionResult AtomFeed(string id, bool prerel = true)
[HttpGet]
public virtual async Task<ActionResult> License(string id, string version)
{
if (version == null)
{
return HttpNotFound();
}

var package = _packageService.FindPackageByIdAndVersionStrict(id, version);
if (package == null || package.PackageStatusKey == PackageStatus.Deleted)
{
Expand Down
15 changes: 15 additions & 0 deletions tests/NuGetGallery.Facts/Controllers/PackagesControllerFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10071,6 +10071,21 @@ public async Task GivenInvalidPackageReturns404()
Assert.IsType<HttpNotFoundResult>(result);
}

[Fact]
public async Task GivenNullVersionReturns404()
{
// arrange
var controller = CreateController(
GetConfigurationService(),
packageService: _packageService);

// act
var result = await controller.License(_packageId, version: null);

// assert
Assert.IsType<HttpNotFoundResult>(result);
}

[Fact]
public async Task GivenDeletedPackageReturns404()
{
Expand Down

0 comments on commit 4a96d3c

Please sign in to comment.