MCPcopy Create free account
hub / github.com/cli/cli / TestGetLocalAttestations

Function TestGetLocalAttestations

pkg/cmd/attestation/verification/attestation_test.go:66–118  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

64}
65
66func TestGetLocalAttestations(t *testing.T) {
67 t.Run("with JSON file containing one bundle", func(t *testing.T) {
68 path := "../test/data/sigstore-js-2.1.0-bundle.json"
69 attestations, err := GetLocalAttestations(path)
70
71 require.NoError(t, err)
72 require.Len(t, attestations, 1)
73 })
74
75 t.Run("with JSON lines file containing multiple bundles", func(t *testing.T) {
76 path := "../test/data/sigstore-js-2.1.0_with_2_bundles.jsonl"
77 attestations, err := GetLocalAttestations(path)
78
79 require.NoError(t, err)
80 require.Len(t, attestations, 2)
81 })
82
83 t.Run("with file with unrecognized extension", func(t *testing.T) {
84 path := "../test/data/sigstore-js-2.1.0-bundles.tgz"
85 attestations, err := GetLocalAttestations(path)
86
87 require.ErrorIs(t, err, ErrUnrecognisedBundleExtension)
88 require.Nil(t, attestations)
89 })
90
91 t.Run("with non-existent bundle file and JSON file", func(t *testing.T) {
92 path := "../test/data/not-found-bundle.json"
93 attestations, err := GetLocalAttestations(path)
94
95 require.ErrorContains(t, err, "could not load content from file path")
96 require.Nil(t, attestations)
97 })
98
99 t.Run("with non-existent bundle file and JSON lines file", func(t *testing.T) {
100 path := "../test/data/not-found-bundle.jsonl"
101 attestations, err := GetLocalAttestations(path)
102
103 require.ErrorContains(t, err, "could not load content from file path")
104 require.Nil(t, attestations)
105 })
106
107 t.Run("with missing verification material", func(t *testing.T) {
108 path := "../test/data/github_provenance_demo-0.0.12-py3-none-any-bundle-missing-verification-material.jsonl"
109 _, err := GetLocalAttestations(path)
110 require.ErrorIs(t, err, bundle.ErrMissingVerificationMaterial)
111 })
112
113 t.Run("with missing verification certificate", func(t *testing.T) {
114 path := "../test/data/github_provenance_demo-0.0.12-py3-none-any-bundle-missing-cert.jsonl"
115 _, err := GetLocalAttestations(path)
116 require.ErrorIs(t, err, bundle.ErrMissingBundleContent)
117 })
118}
119
120func TestFilterAttestations(t *testing.T) {
121 attestations := []*api.Attestation{

Callers

nothing calls this directly

Calls 3

GetLocalAttestationsFunction · 0.85
RunMethod · 0.65
LenMethod · 0.65

Tested by

no test coverage detected