mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-09-18 08:54:55 +08:00
fix(release): 完成分发证明代际绑定与质量门禁收口
This commit is contained in:
@@ -4,11 +4,13 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"bat-api/internal/backendrpc"
|
||||
)
|
||||
|
||||
func testAttestation(root, releaseID, integrity string, ready bool) *backendrpc.DistributionAttestation {
|
||||
verifiedAt := uint64(time.Now().Unix())
|
||||
return &backendrpc.DistributionAttestation{
|
||||
Available: true,
|
||||
Channel: "official",
|
||||
@@ -23,6 +25,8 @@ func testAttestation(root, releaseID, integrity string, ready bool) *backendrpc.
|
||||
StatusCode: "distribution." + integrity,
|
||||
Ready: ready,
|
||||
VerificationGeneration: 4,
|
||||
VerifiedAt: &verifiedAt,
|
||||
MaxAgeSeconds: 7260,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,10 +89,30 @@ func TestFetchAllManifestEntriesRejectsMixedPages(t *testing.T) {
|
||||
name: "manifest identity",
|
||||
mutate: func(page *backendrpc.ResourceManifestPage) { page.ManifestIdentity = "manifest-b" },
|
||||
},
|
||||
{
|
||||
name: "generation",
|
||||
mutate: func(page *backendrpc.ResourceManifestPage) { page.Generation = 5 },
|
||||
},
|
||||
{
|
||||
name: "publication identity",
|
||||
mutate: func(page *backendrpc.ResourceManifestPage) { page.PublicationIdentity = "publication-b" },
|
||||
},
|
||||
{
|
||||
name: "mapping identity",
|
||||
mutate: func(page *backendrpc.ResourceManifestPage) { page.MappingIdentity = "mapping-b" },
|
||||
},
|
||||
{
|
||||
name: "manifest version",
|
||||
mutate: func(page *backendrpc.ResourceManifestPage) { page.ManifestVersion = 2 },
|
||||
},
|
||||
{
|
||||
name: "total",
|
||||
mutate: func(page *backendrpc.ResourceManifestPage) { page.TotalEntries = 4 },
|
||||
},
|
||||
{
|
||||
name: "limit",
|
||||
mutate: func(page *backendrpc.ResourceManifestPage) { page.Limit = 1 },
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
@@ -134,7 +158,8 @@ func TestFetchAllManifestEntriesAcceptsMatchingGeneration(t *testing.T) {
|
||||
}
|
||||
if len(backend.params) != 2 ||
|
||||
backend.params[1].ReleaseID != attestation.ReleaseID ||
|
||||
backend.params[1].ExpectedManifestIdentity != attestation.ManifestIdentity {
|
||||
backend.params[1].ExpectedManifestIdentity != attestation.ManifestIdentity ||
|
||||
backend.params[1].ExpectedVerificationGeneration != attestation.VerificationGeneration {
|
||||
t.Fatalf("params=%+v", backend.params)
|
||||
}
|
||||
}
|
||||
@@ -239,3 +264,22 @@ func TestStaleOrInvalidMatchingAttestationNeverReadiesIndex(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpiredReadyAttestationNeverReadiesIndex(t *testing.T) {
|
||||
root := fixtureRoot(t)
|
||||
backend := fixtureRPCBackend(t, root)
|
||||
attestation := testAttestation(root, "official-fixture", "verified", true)
|
||||
expired := uint64(time.Now().Unix()) - attestation.MaxAgeSeconds - 1
|
||||
attestation.VerifiedAt = &expired
|
||||
backend.attestation = attestation
|
||||
result, err := DiscoverAndIndex(context.Background(), backend, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result.Index == nil || result.Index.Summary().Ready {
|
||||
t.Fatalf("expired attestation unexpectedly ready: %+v", result.Index.Summary())
|
||||
}
|
||||
if len(backend.manifestParams) != 0 {
|
||||
t.Fatalf("manifest should not be fetched for expired attestation: %+v", backend.manifestParams)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user