Skip to content

Commit

Permalink
fix: handle workflow input flag parsing (#379)
Browse files Browse the repository at this point in the history
* fix: handle workflow input flag parsing

Signed-off-by: Asra Ali <asraa@google.com>

* add smoke tests

Signed-off-by: Asra Ali <asraa@google.com>

Signed-off-by: Asra Ali <asraa@google.com>
  • Loading branch information
asraa authored Dec 2, 2022
1 parent c9993a5 commit d50e89b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
34 changes: 33 additions & 1 deletion cli/slsa-verifier/main_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bytes"
"context"
"errors"
"fmt"
Expand Down Expand Up @@ -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{""}
}
Expand Down Expand Up @@ -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()))
}
}
}
})
Expand Down
3 changes: 3 additions & 0 deletions cli/slsa-verifier/verify/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit d50e89b

Please sign in to comment.