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

Return 404 when the null version is provided to the license endpoint #9297

Merged
merged 1 commit into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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