Skip to content

Commit 7ae5657

Browse files
authored
ACR bug fix: Update 'packageName' metadata check to 'org.opencontainers.image.title' (#1567)
1 parent 23f908e commit 7ae5657

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

src/code/ACRServerAPICalls.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -770,18 +770,18 @@ internal Tuple<string,string> GetMetadataProperty(JObject foundTags, string pack
770770

771771
var metadata = annotations["metadata"].ToString();
772772

773-
var metadataPkgNameJToken = annotations["packageName"];
774-
if (metadataPkgNameJToken == null)
773+
var metadataPkgTitleJToken = annotations["org.opencontainers.image.title"];
774+
if (metadataPkgTitleJToken == null)
775775
{
776-
exception = new InvalidOrEmptyResponse($"Response does not contain 'packageName' element for package '{packageName}' in '{Repository.Name}'.");
776+
exception = new InvalidOrEmptyResponse($"Response does not contain 'org.opencontainers.image.title' element for package '{packageName}' in '{Repository.Name}'.");
777777

778778
return emptyTuple;
779779
}
780780

781-
string metadataPkgName = metadataPkgNameJToken.ToString();
781+
string metadataPkgName = metadataPkgTitleJToken.ToString();
782782
if (string.IsNullOrWhiteSpace(metadataPkgName))
783783
{
784-
exception = new InvalidOrEmptyResponse($"Response element 'packageName' is empty for package '{packageName}' in '{Repository.Name}'.");
784+
exception = new InvalidOrEmptyResponse($"Response element 'org.opencontainers.image.title' is empty for package '{packageName}' in '{Repository.Name}'.");
785785

786786
return emptyTuple;
787787
}
@@ -1244,7 +1244,7 @@ private string CreateJsonContent(
12441244

12451245
jsonWriter.WriteStartObject();
12461246
jsonWriter.WritePropertyName("mediaType");
1247-
jsonWriter.WriteValue("application/vnd.oci.image.layer.nondistributable.v1.tar+gzip'");
1247+
jsonWriter.WriteValue("application/vnd.oci.image.layer.nondistributable.v1.tar+gzip");
12481248
jsonWriter.WritePropertyName("digest");
12491249
jsonWriter.WriteValue($"sha256:{nupkgDigest}");
12501250
jsonWriter.WritePropertyName("size");

src/code/Microsoft.PowerShell.PSResourceGet.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
</PropertyGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="NuGet.Commands" Version="6.8.0" />
18-
<PackageReference Include="NuGet.Common" Version="6.8.1" />
19-
<PackageReference Include="NuGet.Configuration" Version="6.8.1" />
20-
<PackageReference Include="NuGet.Packaging" Version="6.8.1" />
21-
<PackageReference Include="NuGet.ProjectModel" Version="6.8.0" />
22-
<PackageReference Include="NuGet.Protocol" Version="6.8.0" />
17+
<PackageReference Include="NuGet.Commands" Version="6.9.1" />
18+
<PackageReference Include="NuGet.Common" Version="6.9.1" />
19+
<PackageReference Include="NuGet.Configuration" Version="6.9.1" />
20+
<PackageReference Include="NuGet.Packaging" Version="6.9.1" />
21+
<PackageReference Include="NuGet.ProjectModel" Version="6.9.1" />
22+
<PackageReference Include="NuGet.Protocol" Version="6.9.1" />
2323
<PackageReference Include="PowerShellStandard.Library" Version="7.0.0-preview.1" />
2424
<PackageReference Include="System.Net.Http" Version="4.3.4" />
2525
<PackageReference Include="System.Text.Json" Version="8.0.0" />

test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,12 @@ Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' {
2626
$res.Version | Should -Be "5.0.0"
2727
}
2828

29-
It "Find resource given specific Name, Version null" {
30-
# FindName()
31-
$res = Find-PSResource -Name $testModuleName -Repository $ACRRepoName -Prerelease
32-
$res.Name | Should -Be $testModuleName
33-
$res.Version | Should -Be "5.0.0-alpha001"
34-
}
35-
3629
It "Should not find resource given nonexistant Name" {
3730
# FindName()
3831
$res = Find-PSResource -Name NonExistantModule -Repository $ACRRepoName -ErrorVariable err -ErrorAction SilentlyContinue
3932
$res | Should -BeNullOrEmpty
4033
$err.Count | Should -BeGreaterThan 0
41-
$err[0].FullyQualifiedErrorId | Should -BeExactly "ACRPackageNotFoundFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource"
34+
$err[0].FullyQualifiedErrorId | Should -BeExactly "ResourceNotFound,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource"
4235
$res | Should -BeNullOrEmpty
4336
}
4437

@@ -75,6 +68,14 @@ Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' {
7568
$res.Count | Should -BeGreaterOrEqual 1
7669
}
7770

71+
<# TODO: prerelease handling not yet implemented in ACR Server Protocol
72+
It "Find resource given specific Name, Version null but allowing Prerelease" {
73+
# FindName()
74+
$res = Find-PSResource -Name $testModuleName -Repository $ACRRepoName -Prerelease
75+
$res.Name | Should -Be $testModuleName
76+
$res.Version | Should -Be "5.0.0-alpha001"
77+
}
78+
7879
It "Find resource with latest (including prerelease) version given Prerelease parameter" {
7980
# FindName()
8081
# test_local_mod resource's latest version is a prerelease version, before that it has a non-prerelease version
@@ -92,6 +93,7 @@ Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' {
9293
$resWithPrerelease = Find-PSResource -Name $testModuleName -Version "*" -Repository $ACRRepoName -Prerelease
9394
$resWithPrerelease.Count | Should -BeGreaterOrEqual $resWithoutPrerelease.Count
9495
}
96+
#>
9597

9698
It "Should not find resource if Name, Version and Tag property are not all satisfied (single tag)" {
9799
# FindVersionWithTag()

0 commit comments

Comments
 (0)