Commit ba885de89c
Verified · cmc
Layout: unified · split
cmd/gitbay/main.go +2 −2
| @@ -357,7 +357,7 @@ func isEmptyReader(r io.Reader) bool { | ||
| 357 | 357 | // usesStdin reports whether the arguments request stdin content. |
| 358 | 358 | func usesStdin(args []string) bool { |
| 359 | 359 | for i, a := range args { |
| 360 | if (a == "--file" || a == "--key") && i+1 < len(args) && args[i+1] == "-" { | |
| 360 | if (a == "--file" || a == "--key" || a == "--secret") && i+1 < len(args) && args[i+1] == "-" { | |
| 361 | 361 | return true |
| 362 | 362 | } |
| 363 | 363 | if a == "--token-stdin" { |
| @@ -750,7 +750,7 @@ func webCmd() *cobra.Command { | ||
| 750 | 750 | |
| 751 | 751 | func webhookCmd() *cobra.Command { |
| 752 | 752 | return group("webhook", "outbound event delivery", |
| 753 | pass("add", passOpts{server: []string{"webhook", "add"}, needsRepo: true}), | |
| 753 | pass("add", passOpts{server: []string{"webhook", "add"}, needsRepo: true, stdinOK: true, stdinWhat: "the webhook secret", stdinSecret: true}), | |
| 754 | 754 | pass("list", passOpts{server: []string{"webhook", "list"}, needsRepo: true}), |
| 755 | 755 | pass("remove", passOpts{server: []string{"webhook", "remove"}, needsRepo: true}), |
| 756 | 756 | pass("deliveries", passOpts{server: []string{"webhook", "deliveries"}, needsRepo: true}), |
cmd/gitbay/stdinpayload_test.go +11
| @@ -114,3 +114,14 @@ func swapTerminal(f func(*os.File) bool) func() { | ||
| 114 | 114 | isTerminal = f |
| 115 | 115 | return func() { isTerminal = prev } |
| 116 | 116 | } |
| 117 | ||
| 118 | // webhook add --secret - reads the secret on the server, so the CLI must | |
| 119 | // forward stdin for it the way it does for --file - (#284). | |
| 120 | func TestUsesStdinForSecretDash(t *testing.T) { | |
| 121 | if !usesStdin([]string{"alice/app", "https://ci.example/hook", "--secret", "-"}) { | |
| 122 | t.Error("--secret - does not forward stdin") | |
| 123 | } | |
| 124 | if usesStdin([]string{"alice/app", "https://ci.example/hook", "--events", "push"}) { | |
| 125 | t.Error("forwarded stdin with no flag asking for it") | |
| 126 | } | |
| 127 | } | |