Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: handle workflow input flag parsing #379

Merged
merged 2 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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