-
Notifications
You must be signed in to change notification settings - Fork 906
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
(#3565 #2421) Avoid credential bleed from saved sources with the same hostname #3568
Conversation
src/chocolatey/infrastructure.app/commands/ChocolateyInfoCommand.cs
Outdated
Show resolved
Hide resolved
Previously we looked up any available sources in the config by the hostname, before falling back to trying an exact match if we had collisions. This still allowed credentials to be reused in situations where we don't actually know if they're applicable; many repository servers will support different credentials for individual repositories, so we cannot and should not assume that credentials for one repository will actually match another repository, nor that users want the credentials to be shared for both. It also led to the possibility of users storing one repository first, and then later specifying a different repository on the same server, and choco would try to use the stored credentials for the first repository for the explicitly-entered URL which is nowhere in config. Instead, we should only match the whole URL (which can be done with Uri. Equals to ensure that we match hostnames case-insensitively, but routes case-sensitively), and expect users to provide credentials if they provide a URL that is not explicitly in the sources. Additionally, we try to ensure that if a user has named a specific source, rather than themselves providing a URL at the command line, we prioritise finding that in the already-configured sources and use that source if the URL matches the current URL that NuGet requires a credential for.
These tests ensure that the use cases we expect to handle in the credential provider are appropriately handled according to our expectations, based on the user-provided input and the transformed input that is left in configuration.Sources once the credential provider typically gets queried.
Converting this PR to draft while I add and validate Pester tests. |
I've updated the Pester tests once I got them sorted in Test Kitchen. This is once again ready for review. |
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 general, this looks good. But there are a few things to fix up, or questions needed to be answered.
src/chocolatey.tests/infrastructure.app/nuget/ChocolateyNugetCredentialProviderSpecs.cs
Outdated
Show resolved
Hide resolved
src/chocolatey.tests/infrastructure.app/nuget/ChocolateyNugetCredentialProviderSpecs.cs
Outdated
Show resolved
Hide resolved
src/chocolatey.tests/infrastructure.app/nuget/ChocolateyNugetCredentialProviderSpecs.cs
Outdated
Show resolved
Hide resolved
src/chocolatey.tests/infrastructure.app/nuget/ChocolateyNugetCredentialProviderSpecs.cs
Outdated
Show resolved
Hide resolved
src/chocolatey.tests/infrastructure.app/nuget/ChocolateyNugetCredentialProviderSpecs.cs
Outdated
Show resolved
Hide resolved
src/chocolatey/infrastructure.app/commands/ChocolateyInfoCommand.cs
Outdated
Show resolved
Hide resolved
src/chocolatey/infrastructure.app/nuget/ChocolateyNugetCredentialProvider.cs
Outdated
Show resolved
Hide resolved
src/chocolatey/infrastructure.app/nuget/ChocolateyNugetCredentialProvider.cs
Outdated
Show resolved
Hide resolved
src/chocolatey/infrastructure.app/nuget/ChocolateyNugetCredentialProvider.cs
Show resolved
Hide resolved
src/chocolatey/infrastructure.app/nuget/ChocolateyNugetCredentialProvider.cs
Outdated
Show resolved
Hide resolved
5e0848b
to
7a0b627
Compare
Add Pester tests to ensure we don't inadvertently bleed configured credentials into scenarios where they should not be used.
Since we've added an ExplicitSources property to the top-level configuration object, we do not need the ListCommand.ExplicitSource property. It is being deprecated here to be removed in version 3. To determine if an explicit source was provided, we can look at if ExplicitSources is set.
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.
Looks good to me apart from one minor comment. Thank for picking this up, @corbob :3
src/chocolatey/infrastructure.app/nuget/ChocolateyNugetCredentialProvider.cs
Outdated
Show resolved
Hide resolved
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 have left a comment about something I think needs to be addressed before we can get this merged in.
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.
LGTM, but I think the comment from Gary needs to be answered (updated) before anything is merged.
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.
Minor nit pick, sorry.
Add some comments to the Pester Tests to better describe the purpose of the test and why some commands are expected to exit 0 and others not.
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.
LGTM!
Description Of Changes
--source
on the command line are, and start making use of it here to aid with looking up source credentials.Motivation and Context
See #3565 - the credentials are being reused in places that they shouldn't.
Testing
Unit tests! :3 Including a regression test specifically for #3565
Open VS and run the tests in the
chocolatey.tests
project and make sure they pass.Cory added: Ran
CredentialProvider
tag in Test Kitchen.Operating Systems Testing
Win10
Change Types Made
Change Checklist
Related Issue
Fixes #3565
Fixes #2421 (different symptom, same issue, likely somewhat duplicate issue)