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
Do not install unlisted package in NuGet.exe #3795
Conversation
@@ -128,6 +128,30 @@ private Action<HttpListenerResponse> ServerHandlerV3(HttpListenerRequest request | |||
}); | |||
} | |||
} | |||
else if (path.StartsWith("/packages/")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this /packages
path where newly created packages go by default or why it's so specific?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following are what I learnt, I hope it would help.
FileSystemBackedV3MockServer
is a mock Server used for testing. When we create a mock server and add the service index Uri into our testing NuGet.Config file, then running NuGet.exe install, the mock server will respond like a real V3 http package source.
However, the ServerHandlerV3
method in FileSystemBackedV3MockServer
is not complete to run my newly added tests.
When NuGet.exe tries the registration URL first, it will BuildRegistrationIndexResponse, and CreatePackageRegistrationBlob, and it will set packageContent
blob as "packageContent", $"{server.Uri}packages/{id}.{version}.nupkg"
During NuGet.exe install, package needs to be downloaded, the DownloadResourceV3.cs
will finally get the packageContent Uri , which is $"{server.Uri}packages/{id}.{version}.nupkg
. So that why I need to add the logic to handle path.StartsWith("/packages/")
. Only in this way, the test of install could be completed, or else, the download package could not be done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this server should mimic what a proper v3 server would do.
Can we change
item.Add(new JProperty("packageContent", $"{server.Uri}packages/{id}.{version}.nupkg")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In particular look what https://api.nuget.org/v3/registration5-semver1/newtonsoft.json/index.json packageContent
points to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Nikolche!
I see
"packageContent":"https://api.nuget.org/v3-flatcontainer/newtonsoft.json/3.5.8/newtonsoft.json.3.5.8.nupkg"
So I need to change the line to
item.Add(new JProperty("packageContent", $"{server.Uri}v3-flatcontainer/{id}/{version}/{id}.{version}.nupkg"));
, right?
Then there will be following things need to be changed as well:
- We still need to add logic to handle path.StartsWith("/v3-flatcontainer/") in FileSystemBackedV3MockServer
- 100+ lines of packageContent with "
/packages/
" in JsonData.cs need to be changed to the new format, right? - NetworkCallCountTest.cs also handles the path.StartsWith("/packages/"). We need to change that as well.
- Fixed other tests.
May I know if my understanding is correct? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flat is handled in https://github.com/NuGet/NuGet.Client/blob/dev/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/FileSystemBackedV3MockServer.cs#L58.
You can chang that to v3-flatcontainer if you want, and then change the index.json that it advertises.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Only changed the package content format in util works.
No other change is needed. So my understanding of changing 4 parts is incorrect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicely done 👍
Great test names.
Bug
Fixes: NuGet/Home#7466
Regression: No
Fix
Details:
includeUnlisted
fromtrue
tofalse
inInstallPackageAsync
.2. Change FileSystemBackedV3MockServer.cs to handlepath.StartsWith("/packages/")
.{server.Uri}packages/{id}.{version}.nupkg
to{server.Uri}flat/{id}/{version}/{id}.{version}.nupkg
Testing/Validation
Tests Added: Yes
Reason for not adding tests:
Validation: