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

Add strict version check for dependencies in NuspecReader #1262

Merged
merged 5 commits into from
Mar 28, 2017

Conversation

shishirx34
Copy link
Contributor

This is part 1 of the work for fixing issue:
NuGet/NuGetGallery#3482 - Gallery accepts packages with illegal package dependency version ranges.

Gallery uses NuGet.Packaging Nuspec reader, which currently does not do any strict version check for invalid versions in dependencies, for processing packages. This PR adds that ability and throws an exception based of which the gallery will reject bad packages.

I have refactored code a bit, for reusability. Added unit tests for this feature. All unit tests seem to be passing for me. Let me know if I am missing something here.

Feel free to add more reviewers to this PR.

@dnfclas
Copy link

dnfclas commented Mar 23, 2017

@shishirx34,
Thanks for having already signed the Contribution License Agreement. Your agreement was validated by .NET Foundation. We will now review your pull request.
Thanks,
.NET Foundation Pull Request Bot

/// </summary>
public IEnumerable<PackageDependencyGroup> GetDependencyGroups(bool useStrictVersionCheck)
{
return GetAllDependencyGroups(useStrictVersionCheck);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason the implementation is in a private method instead of this one? It seems like it would be simpler to add it here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new private method is now being called from two places:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to keep the implementation within the public method, we should consider merging the two public methods. To avoid breaking change in the public API of this class, the bool useStrictVersionCheck argument should be made optional: bool useStrictVersionCheck = false. Is that preferable @emgarten?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can keep the exact same public API service area:

  1. NuSpecReader.GetDependencyGroups()
  2. NuSpecReader.GetDependencyGroups(bool useStrictVersionCheck)

Number 1 will just call number two with useStrictVersionCheck = false right?

Optional argument is actually less preferable since this is actually a breaking change at runtime (but not at build time).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, agreed. Will change it accordingly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fixed with 0a35c93

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes @joelverhagen's comment. It can just be two methods instead of 3. And on the client we avoid optional params for public things.

@@ -129,6 +129,9 @@
<data name="ErrorInvalidPackageVersion" xml:space="preserve">
<value>Invalid package version for package id '{0}': '{1}'</value>
</data>
<data name="ErrorInvalidPackageVersionForDependency" xml:space="preserve">
<value>Invalid package version for a dependency with id '{0}' in package '{1}': '{2}'</value>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please document what each placeholder corresponds to (<comment>)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yield return "1238234.198231.2924324.2343432+final";
yield return "00.00.00.00-alpha";
yield return "0.0-alpha.1";
yield return "9.9.9-9";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some examples with [ and ) and floating would be good. This looks like a list of just versions (not version ranges).

Also, you don't need this many test cases. You can just cover the major different sorts of formats and leave the big test list to NuGet.Versioning unit tests.

try
{
var dependencies = reader.GetDependencyGroups().ToList();
Assert.Equal(1, dependencies.Count);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assert.Throws

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, invalid should map to (, ) right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If so, we should assert that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be (, ) when it can't parse which represents all

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@xavierdecoster xavierdecoster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking over this PR from @shishirx34 who's on vacation. May reopen a new one and rename branch to dev-* to benefit from CI private builds :)

Will address the test comments and PR feedback. Have one question in my comments for @emgarten.

/// </summary>
public IEnumerable<PackageDependencyGroup> GetDependencyGroups(bool useStrictVersionCheck)
{
return GetAllDependencyGroups(useStrictVersionCheck);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new private method is now being called from two places:

/// </summary>
public IEnumerable<PackageDependencyGroup> GetDependencyGroups(bool useStrictVersionCheck)
{
return GetAllDependencyGroups(useStrictVersionCheck);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to keep the implementation within the public method, we should consider merging the two public methods. To avoid breaking change in the public API of this class, the bool useStrictVersionCheck argument should be made optional: bool useStrictVersionCheck = false. Is that preferable @emgarten?

@xavierdecoster
Copy link
Member

@emgarten @joelverhagen pushed a commit that should address review feedback (except for the open question), and also fixed tests. Pushed another branch dev-xadeco-galleryissue3482 containing the exact same code as this one, which went through CI private-build with an all-green result.

Copy link
Member

@joelverhagen joelverhagen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit: once we iron out @emgarten's comment.

Copy link
Member

@emgarten emgarten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

Great work on the extra clean up/de-duplication in the file 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants