From 1c4b4f4a87245d31921ea857ec960d550685c88e Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Tue, 6 Sep 2022 16:27:11 -0700 Subject: [PATCH 1/6] Run harness tests against 2 previous versions and HEAD Signed-off-by: Priya Wadhwa --- cmd/rekor-cli/app/pflag_groups.go | 19 +++++++++ cmd/rekor-cli/app/pflags_test.go | 32 ++++++++++++++- cmd/rekor-cli/app/upload.go | 65 ++++++++++++++++++++++--------- pkg/types/intoto/intoto.go | 2 +- tests/rekor-harness.sh | 11 +++++- 5 files changed, 106 insertions(+), 23 deletions(-) diff --git a/cmd/rekor-cli/app/pflag_groups.go b/cmd/rekor-cli/app/pflag_groups.go index ccbf2be62..ee30219b3 100644 --- a/cmd/rekor-cli/app/pflag_groups.go +++ b/cmd/rekor-cli/app/pflag_groups.go @@ -199,3 +199,22 @@ func ParseTypeFlag(typeStr string) (string, string, error) { } return "", "", errors.New("malformed type string") } + +func GetSupportedVersions(typeStr string) ([]string, error) { + typeStrings := strings.SplitN(typeStr, ":", 2) + tf, ok := types.TypeMap.Load(typeStrings[0]) + if !ok { + return nil, fmt.Errorf("unknown type %v", typeStrings[0]) + } + ti := tf.(func() types.TypeImpl)() + if ti == nil { + return nil, fmt.Errorf("type %v is not implemented", typeStrings[0]) + } + switch len(typeStrings) { + case 1: + return ti.SupportedVersions(), nil + case 2: + return []string{typeStrings[1]}, nil + } + return nil, errors.New("malformed type string") +} diff --git a/cmd/rekor-cli/app/pflags_test.go b/cmd/rekor-cli/app/pflags_test.go index 2e3501774..16f490bc6 100644 --- a/cmd/rekor-cli/app/pflags_test.go +++ b/cmd/rekor-cli/app/pflags_test.go @@ -23,6 +23,7 @@ import ( "os" "testing" + "github.com/google/go-cmp/cmp" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -762,7 +763,7 @@ func TestParseTypeFlag(t *testing.T) { { caseDesc: "explicit intoto v0.0.1", typeStr: "intoto:0.0.1", - expectSuccess: false, + expectSuccess: true, }, { caseDesc: "explicit intoto v0.0.2", @@ -842,3 +843,32 @@ func TestParseTypeFlag(t *testing.T) { } } } + +func TestGetSupportedVersions(t *testing.T) { + tests := []struct { + description string + typeStr string + expectedVersions []string + }{ + { + description: "intoto specified with version", + typeStr: "intoto:0.0.1", + expectedVersions: []string{"0.0.1"}, + }, { + description: "intoto no version specified", + typeStr: "intoto", + expectedVersions: []string{"0.0.2", "0.0.1"}, + }, + } + for _, test := range tests { + t.Run(test.description, func(t *testing.T) { + got, err := GetSupportedVersions(test.typeStr) + if err != nil { + t.Fatal(err) + } + if d := cmp.Diff(test.expectedVersions, got); d != "" { + t.Fatalf("got unexpected versions: %s", d) + } + }) + } +} diff --git a/cmd/rekor-cli/app/upload.go b/cmd/rekor-cli/app/upload.go index a5ec22340..c75691cb9 100644 --- a/cmd/rekor-cli/app/upload.go +++ b/cmd/rekor-cli/app/upload.go @@ -72,11 +72,12 @@ var uploadCmd = &cobra.Command{ if err != nil { return nil, err } - var entry models.ProposedEntry params := entries.NewCreateLogEntryParams() params.SetTimeout(viper.GetDuration("timeout")) entryStr := viper.GetString("entry") + var resp *entries.CreateLogEntryCreated + if entryStr != "" { var entryReader io.Reader entryURL, err := url.Parse(entryStr) @@ -94,36 +95,62 @@ var uploadCmd = &cobra.Command{ return nil, fmt.Errorf("error processing entry file: %w", err) } } - entry, err = models.UnmarshalProposedEntry(entryReader, runtime.JSONConsumer()) + entry, err := models.UnmarshalProposedEntry(entryReader, runtime.JSONConsumer()) if err != nil { return nil, fmt.Errorf("error parsing entry file: %w", err) } + params.SetProposedEntry(entry) + r, err := rekorClient.Entries.CreateLogEntry(params) + if err != nil { + switch e := err.(type) { + case *entries.CreateLogEntryConflict: + return &uploadCmdOutput{ + Location: e.Location.String(), + AlreadyExists: true, + }, nil + default: + return nil, err + } + } + resp = r } else { - typeStr, versionStr, err := ParseTypeFlag(viper.GetString("type")) + // Start with the default entry and work your way down + typeStr, _, err := ParseTypeFlag(viper.GetString("type")) + if err != nil { + return nil, err + } + supportedVersions, err := GetSupportedVersions(viper.GetString("type")) if err != nil { return nil, err } - props := CreatePropsFromPflags() - entry, err = types.NewProposedEntry(context.Background(), typeStr, versionStr, *props) - if err != nil { - return nil, fmt.Errorf("error: %w", err) + for _, sv := range supportedVersions { + log.CliLogger.Infof("Trying to upload entry of type %s at version %s", typeStr, sv) + entry, err := types.NewProposedEntry(context.Background(), typeStr, sv, *props) + if err != nil { + return nil, fmt.Errorf("error: %w", err) + } + params.SetProposedEntry(entry) + r, err := rekorClient.Entries.CreateLogEntry(params) + if err == nil { + resp = r + break + } + switch e := err.(type) { + case *entries.CreateLogEntryConflict: + return &uploadCmdOutput{ + Location: e.Location.String(), + AlreadyExists: true, + }, nil + default: + log.CliLogger.Warnf("Failed to upload entry, will try with another supported version if one exists: %v", err) + } } } - params.SetProposedEntry(entry) - resp, err := rekorClient.Entries.CreateLogEntry(params) - if err != nil { - switch e := err.(type) { - case *entries.CreateLogEntryConflict: - return &uploadCmdOutput{ - Location: e.Location.String(), - AlreadyExists: true, - }, nil - default: - return nil, err - } + if resp == nil { + return nil, fmt.Errorf("no valid entry was created") } var newIndex int64 diff --git a/pkg/types/intoto/intoto.go b/pkg/types/intoto/intoto.go index 81d2ceeaa..0c79019c5 100644 --- a/pkg/types/intoto/intoto.go +++ b/pkg/types/intoto/intoto.go @@ -78,7 +78,7 @@ func (it BaseIntotoType) DefaultVersion() string { // it deliberately omits 0.0.1 from the list of supported versions as that // version did not persist signatures inside the log entry func (it BaseIntotoType) SupportedVersions() []string { - return []string{"0.0.2"} + return []string{"0.0.2", "0.0.1"} } // IsSupportedVersion returns true if the version can be inserted into the log, and false if not diff --git a/tests/rekor-harness.sh b/tests/rekor-harness.sh index 51c05eb1b..8d1952dfd 100755 --- a/tests/rekor-harness.sh +++ b/tests/rekor-harness.sh @@ -87,10 +87,17 @@ function run_tests () { fi } -# Get last 3 server versions +# Get last 2 server versions git fetch origin -NUM_VERSIONS_TO_TEST=3 +NUM_VERSIONS_TO_TEST=2 VERSIONS=$(git tag --sort=-version:refname | head -n $NUM_VERSIONS_TO_TEST | tac) + +# Also add the commit @ HEAD +HEAD=$(git log --pretty="%H" -n 1 ) +echo "Also testing at HEAD at commit $HEAD" + +VERSIONS="$VERSIONS $HEAD" + echo $VERSIONS export REKOR_HARNESS_TMPDIR="$(mktemp -d -t rekor_test_harness.XXXXXX)" From c132da250c101f3a8ea5c25b95180ade99b341f3 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Tue, 6 Sep 2022 18:00:59 -0700 Subject: [PATCH 2/6] Only collect stdout Signed-off-by: Priya Wadhwa --- tests/harness_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/harness_test.go b/tests/harness_test.go index 88441c41f..4379c0fba 100644 --- a/tests/harness_test.go +++ b/tests/harness_test.go @@ -150,7 +150,7 @@ func TestHarnessAddIntoto(t *testing.T) { write(t, ecdsaPub, pubKeyPath) // If we do it twice, it should already exist - out := runCli(t, "upload", "--artifact", attestationPath, "--type", "intoto", "--public-key", pubKeyPath) + out := runCliStdout(t, "upload", "--artifact", attestationPath, "--type", "intoto", "--public-key", pubKeyPath) outputContains(t, out, "Created entry at") uuid := getUUIDFromUploadOutput(t, out) logIndex := getLogIndexFromUploadOutput(t, out) From c911f941e96c2886908f7688378e10d95d956726 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Tue, 6 Sep 2022 18:18:22 -0700 Subject: [PATCH 3/6] Update e2e tests Signed-off-by: Priya Wadhwa --- tests/e2e_test.go | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/tests/e2e_test.go b/tests/e2e_test.go index 0cd9ec732..fda0f5ce1 100644 --- a/tests/e2e_test.go +++ b/tests/e2e_test.go @@ -524,11 +524,6 @@ func TestIntoto(t *testing.T) { write(t, string(eb), attestationPath) write(t, ecdsaPub, pubKeyPath) - // ensure that we can't upload a intoto v0.0.1 entry - v001out := runCliErr(t, "upload", "--artifact", attestationPath, "--type", "intoto:0.0.1", "--public-key", pubKeyPath) - outputContains(t, v001out, "type intoto does not support version 0.0.1") - - // If we do it twice, it should already exist out := runCli(t, "upload", "--artifact", attestationPath, "--type", "intoto", "--public-key", pubKeyPath) outputContains(t, out, "Created entry at") uuid := getUUIDFromUploadOutput(t, out) @@ -658,11 +653,6 @@ func TestIntotoMultiSig(t *testing.T) { write(t, ecdsaPub, ecdsapubKeyPath) write(t, pubKey, rsapubKeyPath) - // ensure that we can't upload a intoto v0.0.1 entry - v001out := runCliErr(t, "upload", "--artifact", attestationPath, "--type", "intoto:0.0.1", "--public-key", ecdsapubKeyPath, "--public-key", rsapubKeyPath) - outputContains(t, v001out, "type intoto does not support version 0.0.1") - - // If we do it twice, it should already exist out := runCli(t, "upload", "--artifact", attestationPath, "--type", "intoto", "--public-key", ecdsapubKeyPath, "--public-key", rsapubKeyPath) outputContains(t, out, "Created entry at") uuid := getUUIDFromUploadOutput(t, out) @@ -795,11 +785,8 @@ func TestIntotoBlockV001(t *testing.T) { params.SetProposedEntry(entry) _, err = rekorClient.Entries.CreateLogEntry(params) - if err == nil { - t.Fatal("insertion of v0.0.1 entry should fail") - } - if !strings.Contains(err.Error(), "entry kind 'intoto' does not support inserting entries of version '0.0.1'") { - t.Errorf("Expected error as intoto v0.0.1 should not be allowed to be entered into rekor") + if err != nil { + t.Fatalf("failed inserting v0.0.1 entry: %v", err) } } From 2e11e4b39d88cc1d757f02b8a887744a8d5f6ffa Mon Sep 17 00:00:00 2001 From: Bob Callaway Date: Wed, 7 Sep 2022 09:13:30 -0400 Subject: [PATCH 4/6] iterate through versions of intoto type if default is specified Signed-off-by: Bob Callaway --- cmd/rekor-cli/app/pflags_test.go | 2 +- cmd/rekor-cli/app/upload.go | 30 ++++++++++++++--- pkg/types/entries.go | 8 +++++ pkg/types/intoto/intoto.go | 56 +++++++++++++++++++++++++++++--- tests/e2e_test.go | 13 ++------ 5 files changed, 88 insertions(+), 21 deletions(-) diff --git a/cmd/rekor-cli/app/pflags_test.go b/cmd/rekor-cli/app/pflags_test.go index 2e3501774..726138ac1 100644 --- a/cmd/rekor-cli/app/pflags_test.go +++ b/cmd/rekor-cli/app/pflags_test.go @@ -762,7 +762,7 @@ func TestParseTypeFlag(t *testing.T) { { caseDesc: "explicit intoto v0.0.1", typeStr: "intoto:0.0.1", - expectSuccess: false, + expectSuccess: true, }, { caseDesc: "explicit intoto v0.0.2", diff --git a/cmd/rekor-cli/app/upload.go b/cmd/rekor-cli/app/upload.go index a5ec22340..b3b3c71c5 100644 --- a/cmd/rekor-cli/app/upload.go +++ b/cmd/rekor-cli/app/upload.go @@ -31,6 +31,7 @@ import ( "github.com/sigstore/rekor/cmd/rekor-cli/app/format" "github.com/sigstore/rekor/pkg/client" + gen_client "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/rekor/pkg/log" @@ -73,8 +74,6 @@ var uploadCmd = &cobra.Command{ return nil, err } var entry models.ProposedEntry - params := entries.NewCreateLogEntryParams() - params.SetTimeout(viper.GetDuration("timeout")) entryStr := viper.GetString("entry") if entryStr != "" { @@ -111,9 +110,7 @@ var uploadCmd = &cobra.Command{ return nil, fmt.Errorf("error: %w", err) } } - params.SetProposedEntry(entry) - - resp, err := rekorClient.Entries.CreateLogEntry(params) + resp, err := tryUpload(rekorClient, entry) if err != nil { switch e := err.(type) { case *entries.CreateLogEntryConflict: @@ -160,6 +157,29 @@ var uploadCmd = &cobra.Command{ }), } +func tryUpload(rekorClient *gen_client.Rekor, entry models.ProposedEntry) (*entries.CreateLogEntryCreated, error) { + params := entries.NewCreateLogEntryParams() + params.SetTimeout(viper.GetDuration("timeout")) + if pei, ok := entry.(types.ProposedEntryIterator); ok { + params.SetProposedEntry(pei.Get()) + } else { + params.SetProposedEntry(entry) + } + resp, err := rekorClient.Entries.CreateLogEntry(params) + if err != nil { + if e, ok := err.(*entries.CreateLogEntryBadRequest); ok { + if pei, ok := entry.(types.ProposedEntryIterator); ok { + if pei.HasNext() { + log.CliLogger.Errorf("failed to upload entry: %v", e) + return tryUpload(rekorClient, pei.GetNext()) + } + } + } + return nil, err + } + return resp, nil +} + func init() { initializePFlagMap() if err := addArtifactPFlags(uploadCmd); err != nil { diff --git a/pkg/types/entries.go b/pkg/types/entries.go index 55559752d..4b0ee5b98 100644 --- a/pkg/types/entries.go +++ b/pkg/types/entries.go @@ -45,6 +45,14 @@ type EntryWithAttestationImpl interface { AttestationKeyValue() (string, []byte) // returns the key to be used when storing the attestation as well as the attestation itself } +// ProposedEntryIterator is an iterator over a list of proposed entries +type ProposedEntryIterator interface { + models.ProposedEntry + HasNext() bool + Get() models.ProposedEntry + GetNext() models.ProposedEntry +} + // EntryFactory describes a factory function that can generate structs for a specific versioned type type EntryFactory func() EntryImpl diff --git a/pkg/types/intoto/intoto.go b/pkg/types/intoto/intoto.go index 81d2ceeaa..3905ecec4 100644 --- a/pkg/types/intoto/intoto.go +++ b/pkg/types/intoto/intoto.go @@ -21,6 +21,7 @@ import ( "fmt" "github.com/sigstore/rekor/pkg/generated/models" + "github.com/sigstore/rekor/pkg/log" "github.com/sigstore/rekor/pkg/types" "golang.org/x/exp/slices" ) @@ -60,9 +61,41 @@ func (it BaseIntotoType) UnmarshalEntry(pe models.ProposedEntry) (types.EntryImp } func (it *BaseIntotoType) CreateProposedEntry(ctx context.Context, version string, props types.ArtifactProperties) (models.ProposedEntry, error) { + var head ProposedIntotoEntryIterator + var next *ProposedIntotoEntryIterator if version == "" { + // get default version as head of list version = it.DefaultVersion() + ei, err := it.VersionedUnmarshal(nil, version) + if err != nil { + return nil, fmt.Errorf("fetching default Intoto version implementation: %w", err) + } + pe, err := ei.CreateFromArtifactProperties(ctx, props) + if err != nil { + return nil, fmt.Errorf("creating default Intoto entry: %w", err) + } + head.ProposedEntry = pe + next = &head + for _, v := range it.SupportedVersions() { + if v == it.DefaultVersion() { + continue + } + ei, err := it.VersionedUnmarshal(nil, v) + if err != nil { + log.Logger.Errorf("fetching Intoto version (%v) implementation: %w", v, err) + continue + } + versionedPE, err := ei.CreateFromArtifactProperties(ctx, props) + if err != nil { + log.Logger.Errorf("error creating Intoto entry of version (%v): %w", v, err) + continue + } + next.next = &ProposedIntotoEntryIterator{versionedPE, nil} + next = next.next.(*ProposedIntotoEntryIterator) + } + return head, nil } + ei, err := it.VersionedUnmarshal(nil, version) if err != nil { return nil, fmt.Errorf("fetching Intoto version implementation: %w", err) @@ -74,14 +107,29 @@ func (it BaseIntotoType) DefaultVersion() string { return "0.0.2" } -// SupportedVersions returns the supported versions for this type; -// it deliberately omits 0.0.1 from the list of supported versions as that -// version did not persist signatures inside the log entry +// SupportedVersions returns the supported versions for this type in the order of preference func (it BaseIntotoType) SupportedVersions() []string { - return []string{"0.0.2"} + return []string{"0.0.2", "0.0.1"} } // IsSupportedVersion returns true if the version can be inserted into the log, and false if not func (it *BaseIntotoType) IsSupportedVersion(proposedVersion string) bool { return slices.Contains(it.SupportedVersions(), proposedVersion) } + +type ProposedIntotoEntryIterator struct { + models.ProposedEntry + next models.ProposedEntry +} + +func (p ProposedIntotoEntryIterator) HasNext() bool { + return p.next != nil +} + +func (p ProposedIntotoEntryIterator) GetNext() models.ProposedEntry { + return p.next +} + +func (p ProposedIntotoEntryIterator) Get() models.ProposedEntry { + return p.ProposedEntry +} diff --git a/tests/e2e_test.go b/tests/e2e_test.go index 0cd9ec732..c9c6d9a55 100644 --- a/tests/e2e_test.go +++ b/tests/e2e_test.go @@ -33,19 +33,16 @@ import ( "fmt" "io/ioutil" "net/http" - "net/url" "os" "os/exec" "path/filepath" "reflect" - "runtime" "strconv" "strings" "testing" "time" "golang.org/x/sync/errgroup" - "sigs.k8s.io/release-utils/version" "github.com/cyberphone/json-canonicalization/go/src/webpki.org/jsoncanonicalizer" "github.com/go-openapi/strfmt" @@ -524,10 +521,6 @@ func TestIntoto(t *testing.T) { write(t, string(eb), attestationPath) write(t, ecdsaPub, pubKeyPath) - // ensure that we can't upload a intoto v0.0.1 entry - v001out := runCliErr(t, "upload", "--artifact", attestationPath, "--type", "intoto:0.0.1", "--public-key", pubKeyPath) - outputContains(t, v001out, "type intoto does not support version 0.0.1") - // If we do it twice, it should already exist out := runCli(t, "upload", "--artifact", attestationPath, "--type", "intoto", "--public-key", pubKeyPath) outputContains(t, out, "Created entry at") @@ -658,10 +651,6 @@ func TestIntotoMultiSig(t *testing.T) { write(t, ecdsaPub, ecdsapubKeyPath) write(t, pubKey, rsapubKeyPath) - // ensure that we can't upload a intoto v0.0.1 entry - v001out := runCliErr(t, "upload", "--artifact", attestationPath, "--type", "intoto:0.0.1", "--public-key", ecdsapubKeyPath, "--public-key", rsapubKeyPath) - outputContains(t, v001out, "type intoto does not support version 0.0.1") - // If we do it twice, it should already exist out := runCli(t, "upload", "--artifact", attestationPath, "--type", "intoto", "--public-key", ecdsapubKeyPath, "--public-key", rsapubKeyPath) outputContains(t, out, "Created entry at") @@ -706,6 +695,7 @@ func TestIntotoMultiSig(t *testing.T) { } +/* func TestIntotoBlockV001(t *testing.T) { td := t.TempDir() attestationPath := filepath.Join(td, "attestation.json") @@ -802,6 +792,7 @@ func TestIntotoBlockV001(t *testing.T) { t.Errorf("Expected error as intoto v0.0.1 should not be allowed to be entered into rekor") } } +*/ func TestTimestampArtifact(t *testing.T) { var out string From cc3c51a14ed5b2c381f11ec0c51f4e635bd5bbec Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Wed, 7 Sep 2022 11:48:01 -0700 Subject: [PATCH 5/6] Skip harness tests if rekor-cli is incompatible with rekor-server version Signed-off-by: Priya Wadhwa --- tests/harness_test.go | 30 ++++++++++++++++++++++++++---- tests/rekor-harness.sh | 8 ++++---- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/tests/harness_test.go b/tests/harness_test.go index 4379c0fba..a6ac1a7b2 100644 --- a/tests/harness_test.go +++ b/tests/harness_test.go @@ -77,9 +77,12 @@ func TestHarnessAddEntry(t *testing.T) { uuid := getUUIDFromUploadOutput(t, out) logIndex := getLogIndexFromUploadOutput(t, out) - // Now we should be able to verify it. - out = runCli(t, "verify", "--type=hashedrekord", "--pki-format=x509", "--artifact-hash", dataSHA, "--signature", sigPath, "--public-key", pubPath) - outputContains(t, out, "Inclusion Proof:") + if !rekorCLIIncompatible() { + // Now we should be able to verify it. + out = runCli(t, "verify", "--type=hashedrekord", "--pki-format=x509", "--artifact-hash", dataSHA, "--signature", sigPath, "--public-key", pubPath) + outputContains(t, out, "Inclusion Proof:") + } + saveEntry(t, logIndex, StoredEntry{UUID: uuid}) } @@ -155,7 +158,7 @@ func TestHarnessAddIntoto(t *testing.T) { uuid := getUUIDFromUploadOutput(t, out) logIndex := getLogIndexFromUploadOutput(t, out) - out = runCli(t, "get", "--uuid", uuid, "--format=json") + out = runCli(t, "get", "--log-index", fmt.Sprintf("%d", logIndex), "--format=json") g := getOut{} if err := json.Unmarshal([]byte(out), &g); err != nil { t.Fatal(err) @@ -265,11 +268,16 @@ func TestHarnessGetAllEntriesLogIndex(t *testing.T) { } func TestHarnessGetAllEntriesUUID(t *testing.T) { + if rekorCLIIncompatible() { + t.Skipf("Skipping getting entries by UUID, old rekor-cli version %s is incompatible with server version %s", os.Getenv("CLI_VERSION"), os.Getenv("SERVER_VERSION")) + } + treeSize := activeTreeSize(t) if treeSize == 0 { t.Fatal("There are 0 entries in the log, there should be at least 2") } _, entries := getEntries(t) + for _, e := range entries { outUUID := runCli(t, "get", "--uuid", e.UUID, "--format", "json") outEntryID := runCli(t, "get", "--uuid", entryID(t, e.UUID), "--format", "json") @@ -294,6 +302,9 @@ func TestHarnessGetAllEntriesUUID(t *testing.T) { } func entryID(t *testing.T, uuid string) string { + if sharding.ValidateEntryID(uuid) == nil { + return uuid + } treeID, err := strconv.Atoi(os.Getenv("TREE_ID")) if err != nil { t.Fatal(err) @@ -317,3 +328,14 @@ func activeTreeSize(t *testing.T) int { } return s.ActiveTreeSize } + +// Check if we have a new server version and an old CLI version +// since the new server returns an EntryID but the old CLI version expects a UUID +func rekorCLIIncompatible() bool { + if sv := os.Getenv("SERVER_VERSION"); sv != "v0.10.0" && sv != "v0.11.0" { + if cv := os.Getenv("CLI_VERSION"); cv == "v0.10.0" || cv == "v0.11.0" { + return true + } + } + return false +} diff --git a/tests/rekor-harness.sh b/tests/rekor-harness.sh index 8d1952dfd..ba1f5662d 100755 --- a/tests/rekor-harness.sh +++ b/tests/rekor-harness.sh @@ -75,7 +75,7 @@ function run_tests () { trap "rm -rf $REKORTMPDIR" EXIT go clean -testcache - if ! REKORTMPDIR=$REKORTMPDIR go test -run TestHarness -v -tags=e2e ./tests/ ; then + if ! REKORTMPDIR=$REKORTMPDIR SERVER_VERSION=$1 CLI_VERSION=$2 go test -run TestHarness -v -tags=e2e ./tests/ ; then docker-compose logs --no-color > /tmp/docker-compose.log exit 1 fi @@ -112,17 +112,17 @@ do echo "Running tests with server version $server_version and CLI version $cli_version" build_cli $cli_version - run_tests + run_tests $server_version $cli_version echo "Tests passed successfully." echo "=======================================================" done done -# Since we add two entries to the log for every test, once all tests are run we should have 2*($NUM_VERSIONS_TO_TEST^2) entries +# Since we add two entries to the log for every test, once all tests are run we should have 2*(($NUM_VERSIONS_TO_TEST+1)^2) entries make rekor-cli actual=$(./rekor-cli loginfo --rekor_server http://localhost:3000 --format json --store_tree_state=false | jq -r .ActiveTreeSize) -expected=$((2*$NUM_VERSIONS_TO_TEST*$NUM_VERSIONS_TO_TEST)) +expected=$((2*(1+$NUM_VERSIONS_TO_TEST)*(1+$NUM_VERSIONS_TO_TEST))) if [[ ! "$expected" == "$actual" ]]; then echo "ERROR: Log had $actual entries instead of expected $expected" exit 1 From a8bff9985acdd9c58f44e6da477754e15295dc20 Mon Sep 17 00:00:00 2001 From: Priya Wadhwa Date: Thu, 8 Sep 2022 07:40:11 -0700 Subject: [PATCH 6/6] Code review comments Signed-off-by: Priya Wadhwa --- pkg/types/intoto/intoto.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/types/intoto/intoto.go b/pkg/types/intoto/intoto.go index 3905ecec4..0f1f0f338 100644 --- a/pkg/types/intoto/intoto.go +++ b/pkg/types/intoto/intoto.go @@ -82,12 +82,12 @@ func (it *BaseIntotoType) CreateProposedEntry(ctx context.Context, version strin } ei, err := it.VersionedUnmarshal(nil, v) if err != nil { - log.Logger.Errorf("fetching Intoto version (%v) implementation: %w", v, err) + log.ContextLogger(ctx).Errorf("fetching Intoto version (%v) implementation: %w", v, err) continue } versionedPE, err := ei.CreateFromArtifactProperties(ctx, props) if err != nil { - log.Logger.Errorf("error creating Intoto entry of version (%v): %w", v, err) + log.ContextLogger(ctx).Errorf("error creating Intoto entry of version (%v): %w", v, err) continue } next.next = &ProposedIntotoEntryIterator{versionedPE, nil}