From d50e89b5595e6bb57bc830d3fdde8dee01827f1d Mon Sep 17 00:00:00 2001 From: asraa Date: Fri, 2 Dec 2022 12:01:20 -0600 Subject: [PATCH] fix: handle workflow input flag parsing (#379) * fix: handle workflow input flag parsing Signed-off-by: Asra Ali * add smoke tests Signed-off-by: Asra Ali Signed-off-by: Asra Ali --- cli/slsa-verifier/main_test.go | 34 ++++++++++++++++++++++++++++- cli/slsa-verifier/verify/options.go | 3 +++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/cli/slsa-verifier/main_test.go b/cli/slsa-verifier/main_test.go index 5e24d5e..4fd201d 100644 --- a/cli/slsa-verifier/main_test.go +++ b/cli/slsa-verifier/main_test.go @@ -1,6 +1,7 @@ package main import ( + "bytes" "context" "errors" "fmt" @@ -487,7 +488,7 @@ func Test_runVerifyGHAArtifactPath(t *testing.T) { // Avoid rate limiting by not running the tests in parallel. // t.Parallel() - checkVersions := getBuildersAndVersions(t, tt.minversion, tt.builders, GHA_ARTIFACT_PATH_BUILDERS) + checkVersions := getBuildersAndVersions(t, "v1.2.2", tt.builders, GHA_ARTIFACT_PATH_BUILDERS) if tt.noversion { checkVersions = []string{""} } @@ -576,6 +577,37 @@ func Test_runVerifyGHAArtifactPath(t *testing.T) { if err := outBuilderID.Matches(*bid, false); err != nil { t.Errorf(fmt.Sprintf("matches failed (2): %v", err)) } + + // Smoke test against the CLI command + cliCmd := verifyArtifactCmd() + args := []string{ + artifactPath, + "--source-uri", tt.source, + "--provenance-path", provenancePath} + if bid != nil { + args = append(args, "--builder-id", *bid) + } + if tt.pbranch != nil { + args = append(args, "--source-branch", *tt.pbranch) + } + if tt.ptag != nil { + args = append(args, "--source-tag", *tt.ptag) + } + if tt.pversiontag != nil { + args = append(args, "--source-versioned-tag", *tt.pversiontag) + } + if tt.inputs != nil { + for k, v := range tt.inputs { + args = append(args, "--build-workflow-input", fmt.Sprintf("%s=%s", k, v)) + } + } + b := bytes.NewBufferString("") + cliCmd.SetOut(b) + cliCmd.SetArgs(args) + cliErr := cliCmd.Execute() + if !errCmp(cliErr, tt.err) { + t.Errorf("%v: %v", v, cmp.Diff(cliErr, tt.err, cmpopts.EquateErrors())) + } } } }) diff --git a/cli/slsa-verifier/verify/options.go b/cli/slsa-verifier/verify/options.go index 9af23e5..021bf8e 100644 --- a/cli/slsa-verifier/verify/options.go +++ b/cli/slsa-verifier/verify/options.go @@ -91,6 +91,9 @@ func (i *workflowInputs) Set(value string) error { if len(l) != 2 { return fmt.Errorf("%w: expected 'key=value' format, got '%s'", serrors.ErrorInvalidFormat, value) } + if i.kv == nil { + i.kv = make(map[string]string) + } i.kv[l[0]] = l[1] return nil }