Create OwnerDetailsUriTemplateResourceV3 and provider#5763
Conversation
| private static bool IsValidUriTemplate(string absoluteUri) | ||
| { | ||
| Uri? uri; | ||
| var isValidUri = Uri.TryCreate(absoluteUri, UriKind.Absolute, out uri); |
There was a problem hiding this comment.
We are converting the URI parameter value to a string in the CreateOrNull method, which then calls the IsValidUriTemplate method, passing in that string. I am not sure why we are converting that string again to verify if it is a valid URI. How about just passing the URI object that was passed to the CreateOrNull method instead of creating another URI object here?
Security considerations section in docs suggest that, You can check a URI string for validity by calling the Uri.IsWellFormedOriginalString method. Can this method be used in this case?
There was a problem hiding this comment.
I noticed that method as well, but unfortunately, it returns false because of the braces in the URI template provided by the server resource, as shown below.
My suspicion is this is why the PackageDetailsUriResourceV3 does this custom validation, and it's why I copied that for the OwnerDetailsUriTemplateResourceV3 as well.
If you have other suggestions, let me know. I'm a little hesitant to modify the PackageDetailsUriResourceV3 in this PR, but could consider refactoring it as well separately.
There was a problem hiding this comment.
CreateOrNull method in PackageDetailsUriResourceV3 takes a string as parameter but in this resource the same method has Uri as parameter. Is this could be a reason why we are converting the Uri to string and then string to Uri for validation purposes?
There was a problem hiding this comment.
I've reduced some of the validation logic there, have a look and see if that addresses your concern.
src/NuGet.Core/NuGet.Protocol/Resources/OwnerDetailsUriTemplateResourceV3.cs
Show resolved
Hide resolved
test/NuGet.Core.Tests/NuGet.Protocol.Tests/Resources/OwnerDetailsUriTemplateResourceV3Tests.cs
Show resolved
Hide resolved
test/NuGet.Core.Tests/NuGet.Protocol.Tests/Resources/OwnerDetailsUriTemplateResourceV3Tests.cs
Show resolved
Hide resolved
src/NuGet.Core/NuGet.Protocol/Resources/OwnerDetailsUriTemplateResourceV3.cs
Outdated
Show resolved
Hide resolved
src/NuGet.Core/NuGet.Protocol/Providers/OwnerDetailsUriResourceV3Provider.cs
Outdated
Show resolved
Hide resolved
| return new OwnerDetailsUriTemplateResourceV3(absoluteUri); | ||
| } | ||
|
|
||
| private static bool IsValidUriTemplate(string absoluteUri) |
There was a problem hiding this comment.
You have a Uri type in the method calling this, so you shouldn't need to pass a string.
I'd just all the validations in 1 method and use the Uri type that's already there.
There was a problem hiding this comment.
Hm, I was trying not to invent any new validation strategy, as mentioned in #5763 (comment), PackageDetailsUriResourceV3 does this custom validation, and it's why I copied that for the OwnerDetailsUriTemplateResourceV3 as well.
I'll see if I can reduce this validation.
There was a problem hiding this comment.
Ok, I don't like this any better than what was there, but now I'm throwing if a null is provided, and now must check for null in the Provider. We don't want providers to throw when they can't find the resource, because it's not required for a package source to implement this resource.
kartheekp-ms
left a comment
There was a problem hiding this comment.
I know this PR has already been merged, but I would like to provide some feedback and am happy to discuss it further offline. If my comments are valid, perhaps we could consider opening a follow-up issue.

Bug
Fixes: NuGet/Home#13409
Regression? Last working version:
Description
Note: this resource is not yet consumed by the Client, but will be in #5766
Adds a resource,
OwnerDetailsUriTemplateResourceV3, similar to the PackageDetailsUriResourceV3.GetUriwill replace a template's substring,{owner}, with each Owner returned from the NuGet Search API.A new resource provider,
OwnerDetailsUriResourceV3Provider, retrieves the resource from the service index, if available.I've tested in Visual Studio by consuming this resource from package source, https://apidev.nugettest.org/v3/index.json, which @martinrrm has been developing for nuget.org (Thank you! 🙏).
PR Checklist
PR has a meaningful title
PR has a linked issue.
Described changes
Tests
Documentation