Skip to content

Commit

Permalink
resolve comments
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Pan <[email protected]>
  • Loading branch information
Patrick Pan committed Dec 23, 2024
1 parent b20a202 commit 07d8e06
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
7 changes: 0 additions & 7 deletions src/OrasProject.Oras/Oci/Descriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,4 @@ internal static bool IsNullOrInvalid(Descriptor? descriptor)
{
return descriptor == null || string.IsNullOrEmpty(descriptor.Digest) || string.IsNullOrEmpty(descriptor.MediaType);
}

internal static Descriptor ZeroDescriptor() => new ()
{
MediaType = "",
Digest = "",
Size = 0
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,14 @@ public static void VerifyContentDigest(this HttpResponseMessage response, string
/// <param name="repository"></param>
internal static void CheckOciSubjectHeader(this HttpResponseMessage response, Repository repository)
{
if (response.Headers.Contains("OCI-Subject"))
if (repository.ReferrersState == Referrers.ReferrersState.Unknown && response.Headers.Contains("OCI-Subject"))
{
// Set it to Supported when the response header contains OCI-Subject
repository.ReferrersState = Referrers.ReferrersState.Supported;
}

// If the "OCI-Subject" header is NOT set, it means that either the manifest
// has no subject OR the referrers API is NOT supported by the registry.
//
// Since we don't know whether the pushed manifest has a subject or not,
// we do not set the ReferrerState to NotSupported here.
}
Expand Down
4 changes: 2 additions & 2 deletions tests/OrasProject.Oras.Tests/Remote/ReferrersTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public void ApplyReferrerChanges_ShouldNotAddNewDuplicateReferrers()
[Fact]
public void ApplyReferrerChanges_ShouldNotKeepOldEmptyReferrers()
{
var emptyDesc1 = Descriptor.ZeroDescriptor();
var emptyDesc1 = ZeroDescriptor();
Descriptor? emptyDesc2 = null;
var newDescriptor = RandomDescriptor();

Expand Down Expand Up @@ -261,7 +261,7 @@ public void ApplyReferrerChanges_ShouldNotKeepOldEmptyReferrers()
public void ApplyReferrerChanges_NoUpdateWhenOldAndNewReferrersAreEmpty()
{
var oldReferrers = new List<Descriptor>();
var referrerChange = new Referrers.ReferrerChange(Descriptor.ZeroDescriptor(), Referrers.ReferrerOperation.Add);
var referrerChange = new Referrers.ReferrerChange(ZeroDescriptor(), Referrers.ReferrerOperation.Add);

var (updatedReferrers, updateRequired) = Referrers.ApplyReferrerChanges(oldReferrers, referrerChange);
Assert.Empty(updatedReferrers);
Expand Down
7 changes: 7 additions & 0 deletions tests/OrasProject.Oras.Tests/Remote/Util/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,11 @@ public static HttpClient CustomClient(Func<HttpRequestMessage, CancellationToken
).Returns(func);
return new HttpClient(moqHandler.Object);
}

public static Descriptor ZeroDescriptor() => new()
{
MediaType = "",
Digest = "",
Size = 0
};
}

0 comments on commit 07d8e06

Please sign in to comment.