Skip to content

Commit

Permalink
chore: remove online test with network calls
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal Choudhary <[email protected]>
  • Loading branch information
vishal-chdhry committed Sep 28, 2024
1 parent eff3a53 commit f4e9bc9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 36 deletions.
10 changes: 5 additions & 5 deletions pkg/verify/tlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ type verifytlogOptions struct {
getRekorClient GetRekorClientFunc
}

func makeOptions(opts ...VerifyTlogOption) verifytlogOptions {
func makeOptions(opts ...TlogOption) verifytlogOptions {
opt := verifytlogOptions{}
for _, o := range opts {
o(&opt)
}
return opt
}

// VerifyTlogOption is a functional option for transparency log verification.
type VerifyTlogOption func(*verifytlogOptions)
// TlogOption is a functional option for transparency log verification.
type TlogOption func(*verifytlogOptions)

// WithGetRekorClientFunc sets the function that will be used to fetch rekor client from base URL.
// If not provided, rekorClient.GetRekorClient is used.
func WithGetRekorClientFunc(f GetRekorClientFunc) VerifyTlogOption {
func WithGetRekorClientFunc(f GetRekorClientFunc) TlogOption {
return func(opts *verifytlogOptions) {
opts.getRekorClient = f
}
Expand All @@ -66,7 +66,7 @@ func WithGetRekorClientFunc(f GetRekorClientFunc) VerifyTlogOption {
// that must be verified.
//
// If online is true, the log entry is verified against the Rekor server.
func VerifyArtifactTransparencyLog(entity SignedEntity, trustedMaterial root.TrustedMaterial, logThreshold int, trustIntegratedTime, online bool, opts ...VerifyTlogOption) ([]Timestamp, error) { //nolint:revive
func VerifyArtifactTransparencyLog(entity SignedEntity, trustedMaterial root.TrustedMaterial, logThreshold int, trustIntegratedTime, online bool, opts ...TlogOption) ([]Timestamp, error) { //nolint:revive
options := makeOptions(opts...)
entries, err := entity.TlogEntries()
if err != nil {
Expand Down
32 changes: 1 addition & 31 deletions pkg/verify/tlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ import (
rekorGeneratedClient "github.com/sigstore/rekor/pkg/generated/client"
"github.com/sigstore/rekor/pkg/generated/client/entries"
"github.com/sigstore/rekor/pkg/generated/models"
"github.com/sigstore/sigstore-go/pkg/bundle"
"github.com/sigstore/sigstore-go/pkg/root"
"github.com/sigstore/sigstore-go/pkg/testing/ca"
"github.com/sigstore/sigstore-go/pkg/tlog"
"github.com/sigstore/sigstore-go/pkg/tuf"
"github.com/sigstore/sigstore-go/pkg/verify"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -230,17 +227,6 @@ func TestMaxAllowedTlogEntries(t *testing.T) {
assert.ErrorContains(t, err, "too many tlog entries") // too many tlog entries should fail to verify
}

func TestOnlineTlogVerification(t *testing.T) {
b, err := bundle.LoadJSONFromPath("../../examples/bundle-provenance.json")
assert.NoError(t, err)

trustedMaterials, err := getTrustedMaterial()
assert.NoError(t, err)

_, err = verify.VerifyArtifactTransparencyLog(b, trustedMaterials, 1, true, true)
assert.NoError(t, err)
}

type mockEntriesClient struct {
Entries []*models.LogEntry
}
Expand Down Expand Up @@ -271,7 +257,7 @@ func (m *mockEntriesClient) GetLogEntryByUUID(_ *entries.GetLogEntryByUUIDParams
return nil, errors.New("not implemented")
}

func (m *mockEntriesClient) SearchLogQuery(params *entries.SearchLogQueryParams, _ ...entries.ClientOption) (*entries.SearchLogQueryOK, error) {
func (m *mockEntriesClient) SearchLogQuery(_ *entries.SearchLogQueryParams, _ ...entries.ClientOption) (*entries.SearchLogQueryOK, error) {
return nil, errors.New("not implemented")
}

Expand Down Expand Up @@ -299,19 +285,3 @@ func TestTlogVerification(t *testing.T) {
_, err = verify.VerifyArtifactTransparencyLog(entity, virtualSigstore, 1, true, true, verify.WithGetRekorClientFunc(func(_ string) (*rekorGeneratedClient.Rekor, error) { return mockRekor, nil }))
assert.NoError(t, err)
}

func getTrustedMaterial() (root.TrustedMaterial, error) {
client, err := tuf.New(tuf.DefaultOptions())
if err != nil {
return nil, err
}
trustedRootJSON, err := client.GetTarget("trusted_root.json")
if err != nil {
return nil, err
}
trustedRoot, err := root.NewTrustedRootFromJSON(trustedRootJSON)
if err != nil {
return nil, err
}
return trustedRoot, nil
}

0 comments on commit f4e9bc9

Please sign in to comment.