Skip to content

Commit

Permalink
ACR bug fix: Update 'packageName' metadata check to 'org.opencontaine…
Browse files Browse the repository at this point in the history
…rs.image.title' (PowerShell#1567)
  • Loading branch information
alerickson committed Apr 2, 2024
1 parent c6d6e46 commit 20d6121
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
12 changes: 6 additions & 6 deletions src/code/ACRServerAPICalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -770,18 +770,18 @@ internal Tuple<string,string> GetMetadataProperty(JObject foundTags, string pack

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

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

return emptyTuple;
}

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

return emptyTuple;
}
Expand Down Expand Up @@ -1244,7 +1244,7 @@ private string CreateJsonContent(

jsonWriter.WriteStartObject();
jsonWriter.WritePropertyName("mediaType");
jsonWriter.WriteValue("application/vnd.oci.image.layer.nondistributable.v1.tar+gzip'");
jsonWriter.WriteValue("application/vnd.oci.image.layer.nondistributable.v1.tar+gzip");
jsonWriter.WritePropertyName("digest");
jsonWriter.WriteValue($"sha256:{nupkgDigest}");
jsonWriter.WritePropertyName("size");
Expand Down
12 changes: 6 additions & 6 deletions src/code/Microsoft.PowerShell.PSResourceGet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NuGet.Commands" Version="6.8.0" />
<PackageReference Include="NuGet.Common" Version="6.8.1" />
<PackageReference Include="NuGet.Configuration" Version="6.8.1" />
<PackageReference Include="NuGet.Packaging" Version="6.8.1" />
<PackageReference Include="NuGet.ProjectModel" Version="6.8.0" />
<PackageReference Include="NuGet.Protocol" Version="6.8.0" />
<PackageReference Include="NuGet.Commands" Version="6.9.1" />
<PackageReference Include="NuGet.Common" Version="6.9.1" />
<PackageReference Include="NuGet.Configuration" Version="6.9.1" />
<PackageReference Include="NuGet.Packaging" Version="6.9.1" />
<PackageReference Include="NuGet.ProjectModel" Version="6.9.1" />
<PackageReference Include="NuGet.Protocol" Version="6.9.1" />
<PackageReference Include="PowerShellStandard.Library" Version="7.0.0-preview.1" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.Json" Version="8.0.0" />
Expand Down
18 changes: 10 additions & 8 deletions test/FindPSResourceTests/FindPSResourceACRServer.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,12 @@ Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' {
$res.Version | Should -Be "5.0.0"
}

It "Find resource given specific Name, Version null" {
# FindName()
$res = Find-PSResource -Name $testModuleName -Repository $ACRRepoName -Prerelease
$res.Name | Should -Be $testModuleName
$res.Version | Should -Be "5.0.0-alpha001"
}

It "Should not find resource given nonexistant Name" {
# FindName()
$res = Find-PSResource -Name NonExistantModule -Repository $ACRRepoName -ErrorVariable err -ErrorAction SilentlyContinue
$res | Should -BeNullOrEmpty
$err.Count | Should -BeGreaterThan 0
$err[0].FullyQualifiedErrorId | Should -BeExactly "ACRPackageNotFoundFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource"
$err[0].FullyQualifiedErrorId | Should -BeExactly "ResourceNotFound,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource"
$res | Should -BeNullOrEmpty
}

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

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

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

0 comments on commit 20d6121

Please sign in to comment.