-
Notifications
You must be signed in to change notification settings - Fork 643
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent nupkg validation failure for malformed nupkg (#9739)
- Loading branch information
1 parent
921d870
commit 2a982dc
Showing
14 changed files
with
272 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace NuGetGallery | ||
{ | ||
public enum InvalidZipEntry | ||
{ | ||
None, | ||
InFuture, | ||
DoubleForwardSlashesInPath, | ||
DoubleBackwardSlashesInPath | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -829,6 +829,43 @@ public async Task WillRejectBrokenZipFiles() | |
ResultAssert.IsStatusCode(result, HttpStatusCode.BadRequest); | ||
Assert.Equal(Strings.FailedToReadUploadFile, (result as HttpStatusCodeWithBodyResult).StatusDescription); | ||
} | ||
|
||
[Theory] | ||
[InlineData("PackageWithDoubleForwardSlash.1.0.0.nupkg")] | ||
[InlineData("PackageWithDoubleBackwardSlash.1.0.0.nupkg")] | ||
[InlineData("PackageWithVeryLongZipFileEntry.1.0.0.nupkg")] | ||
public async Task WillRejectMalformedZipWithEntryDoubleSlashInPath(string zipPath) | ||
{ | ||
// Arrange | ||
var package = new MemoryStream(TestDataResourceUtility.GetResourceBytes(zipPath)); | ||
|
||
var user = new User() { EmailAddress = "[email protected]" }; | ||
var controller = new TestableApiController(GetConfigurationService()); | ||
controller.SetCurrentUser(user); | ||
controller.SetupPackageFromInputStream(package); | ||
|
||
// Act | ||
ActionResult result = await controller.CreatePackagePut(); | ||
|
||
// Assert | ||
ResultAssert.IsStatusCode(result, HttpStatusCode.BadRequest); | ||
|
||
if(zipPath.Contains("Forward")) | ||
{ | ||
Assert.Equal(String.Format(Strings.PackageEntryWithDoubleForwardSlash, "malformedfile.txt"), (result as HttpStatusCodeWithBodyResult).StatusDescription); | ||
} | ||
else if (zipPath.Contains("Backward")) | ||
{ | ||
Assert.Equal(String.Format(Strings.PackageEntryWithDoubleBackSlash, "malformedfile.txt"), (result as HttpStatusCodeWithBodyResult).StatusDescription); | ||
} | ||
else | ||
{ | ||
string longFileName = "a".PadRight(270, 'a') + ".txt"; | ||
Assert.Equal(String.Format(Strings.PackageEntryWithDoubleForwardSlash, longFileName), (result as HttpStatusCodeWithBodyResult).StatusDescription); | ||
string normalizedZipEntry = ZipArchiveHelpers.NormalizeForwardSlashesInPath(longFileName); | ||
Assert.Equal(260, normalizedZipEntry.Length); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task CreatePackageReturns400IfMinClientVersionIsTooHigh() | ||
|
Oops, something went wrong.