Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/code/FindHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ internal IEnumerable<PSResourceInfo> FindDependencyPackages(
else if(dep.VersionRange.MaxVersion != null && dep.VersionRange.MinVersion != null && dep.VersionRange.MaxVersion.OriginalVersion.Equals(dep.VersionRange.MinVersion.OriginalVersion))
{
string depPkgVersion = dep.VersionRange.MaxVersion.OriginalVersion;
FindResults responses = currentServer.FindVersion(dep.Name, version: dep.VersionRange.MaxVersion.OriginalVersion, _type, out ErrorRecord errRecord);
FindResults responses = currentServer.FindVersion(dep.Name, version: dep.VersionRange.MaxVersion.ToNormalizedString(), _type, out ErrorRecord errRecord);
if (errRecord != null)
{
if (errRecord.Exception is ResourceNotFoundException)
Expand Down
14 changes: 13 additions & 1 deletion src/code/V2ServerAPICalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,17 @@ public override FindResults FindVersion(string packageName, string version, Reso
// Quotations around package name and version do not matter, same metadata gets returned.
// We need to explicitly add 'Id eq <packageName>' whenever $filter is used, otherwise arbitrary results are returned.

// version passed in must be a valid NuGet version
if (!NuGetVersion.TryParse(version, out NuGetVersion nugetVersion))
{
errRecord = new ErrorRecord(
new ArgumentException($"Version '{version}' cannot be converted to a valid NuGet version."),
"InvalidVersionFormat",
ErrorCategory.InvalidArgument,
this);
return new FindResults(stringResponse: Utils.EmptyStrArray, hashtableResponse: emptyHashResponses, responseType: v2FindResponseType);
}

var queryBuilder = new NuGetV2QueryBuilder(new Dictionary<string, string>{
{ "$inlinecount", "allpages" },
{ "id", $"'{packageName}'" },
Expand All @@ -650,7 +661,8 @@ public override FindResults FindVersion(string packageName, string version, Reso
filterBuilder.AddCriterion($"Id eq '{packageName}'");
}

filterBuilder.AddCriterion($"NormalizedVersion eq '{version}'");
// a NormalizedVersion is required for the query filter
filterBuilder.AddCriterion($"NormalizedVersion eq '{nugetVersion.ToNormalizedString()}'");
if (type != ResourceType.None) {
filterBuilder.AddCriterion(GetTypeFilterForRequest(type));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Describe 'Test Install-PSResource for V2 Server scenarios' -tags 'CI' {
AfterEach {
Uninstall-PSResource "test_module", "test_module2", "test_script", "TestModule99", "testModuleWithlicense", `
"TestFindModule", "ClobberTestModule1", "ClobberTestModule2", "PackageManagement", "TestTestScript", `
"TestModuleWithDependency", "TestModuleWithPrereleaseDep", "PrereleaseModule", "test-nugetversion-parent", "test-nugetversion" -SkipDependencyCheck -ErrorAction SilentlyContinue
"TestModuleWithDependency", "TestModuleWithPrereleaseDep", "PrereleaseModule", "test-nugetversion-parent", "test-nugetversion", "test-pkg-normalized-dependency" -SkipDependencyCheck -ErrorAction SilentlyContinue
}

AfterAll {
Expand Down Expand Up @@ -631,6 +631,22 @@ Describe 'Test Install-PSResource for V2 Server scenarios' -tags 'CI' {
$depRes.Name | Should -Be $depPkgName
$depRes.Version | Should -Be $depPkgVer
}

It "Install resource that takes a dependency on package with specific version with differing normalized and semver versions" {
$moduleName = 'test-pkg-normalized-dependency'
$version = '3.9.2'
$depPkgName1 = "PowerShellGet"
$depPkgName2 = "PackageManagement"

Install-PSResource -Name $moduleName -Prerelease -Repository $PSGalleryName -TrustRepository
$res = Get-InstalledPSResource $moduleName
$res.Name | Should -Be $moduleName
$res.Version | Should -Be $version

$depRes = Get-InstalledPSResource $depPkgName1, $depPkgName2
$depRes.Name | Should -Contain $depPkgName1
$depRes.Name | Should -Contain $depPkgName2
}
}

Describe 'Test Install-PSResource for V2 Server scenarios' -tags 'ManualValidationOnly' {
Expand Down