update tests to account for logic flip

Signed-off-by: Meredith Lancaster <malancas@github.com>
This commit is contained in:
Meredith Lancaster 2025-01-30 09:26:41 -07:00
parent ddb8855198
commit 70ae9f39ef
2 changed files with 10 additions and 5 deletions

View file

@ -178,6 +178,7 @@ func (c *LiveClient) fetchBundleFromAttestations(attestations []*Attestation) ([
// If the bundle field is nil, try to fetch the bundle with the provided URL
if a.Bundle == nil {
c.logger.VerbosePrintf("Bundle field is empty. Trying to fetch with bundle URL\n\n")
b, err := c.GetBundle(a.BundleURL)
if err != nil {
return fmt.Errorf("failed to fetch bundle with URL: %w", err)
@ -185,10 +186,11 @@ func (c *LiveClient) fetchBundleFromAttestations(attestations []*Attestation) ([
fetched[i] = &Attestation{
Bundle: b,
}
return nil
}
// otherwise fall back to the bundle field
c.logger.VerbosePrintf("Bundle URL is empty. Falling back to bundle field\n\n")
c.logger.VerbosePrintf("Fetching bundle from Bundle field\n\n")
fetched[i] = &Attestation{
Bundle: a.Bundle,
}

View file

@ -180,7 +180,7 @@ func TestGetByDigest_Error(t *testing.T) {
require.Nil(t, attestations)
}
func TestFetchBundleFromAttestations_Fallback_Bundle_Field(t *testing.T) {
func TestFetchBundleFromAttestations_BundleURL(t *testing.T) {
httpClient := &mockHttpClient{}
client := LiveClient{
httpClient: httpClient,
@ -188,13 +188,16 @@ func TestFetchBundleFromAttestations_Fallback_Bundle_Field(t *testing.T) {
}
att1 := makeTestAttestation()
att1.Bundle = nil
att2 := makeTestAttestation()
att2.Bundle = nil
// zero out the bundle field so it tries fetching by URL
attestations := []*Attestation{&att1, &att2}
fetched, err := client.fetchBundleFromAttestations(attestations)
require.NoError(t, err)
require.Len(t, fetched, 2)
require.Equal(t, "application/vnd.dev.sigstore.bundle.v0.3+json", fetched[0].Bundle.GetMediaType())
httpClient.AssertNumberOfCalls(t, "OnGetSuccess", 0)
require.NotNil(t, "application/vnd.dev.sigstore.bundle.v0.3+json", fetched[0].Bundle.GetMediaType())
httpClient.AssertNumberOfCalls(t, "OnGetSuccess", 2)
}
func TestFetchBundleFromAttestations_InvalidAttestation(t *testing.T) {
@ -211,7 +214,7 @@ func TestFetchBundleFromAttestations_InvalidAttestation(t *testing.T) {
require.Nil(t, fetched, 2)
}
func TestFetchBundleFromAttestations_Fail(t *testing.T) {
func TestFetchBundleFromAttestations_Fail_BundleURL(t *testing.T) {
httpClient := &failAfterOneCallHttpClient{}
c := &LiveClient{