From cc36d32a212a2b8b6611fb73549fe6d04fb6ec38 Mon Sep 17 00:00:00 2001 From: Andy Feller Date: Mon, 29 Apr 2024 12:02:41 -0400 Subject: [PATCH] Test `gh at verify -b` does not require auth Thanks to @williammartin, this completes the PR by ensuring the actual feature this new logic was added for actually works as expected :D --- pkg/cmd/attestation/verify/verify_test.go | 31 +++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pkg/cmd/attestation/verify/verify_test.go b/pkg/cmd/attestation/verify/verify_test.go index 203f203b3..ef778f454 100644 --- a/pkg/cmd/attestation/verify/verify_test.go +++ b/pkg/cmd/attestation/verify/verify_test.go @@ -14,6 +14,7 @@ import ( "github.com/cli/cli/v2/pkg/cmd/attestation/test" "github.com/cli/cli/v2/pkg/cmd/attestation/verification" "github.com/cli/cli/v2/pkg/cmdutil" + "github.com/spf13/cobra" "github.com/cli/cli/v2/pkg/httpmock" "github.com/cli/cli/v2/pkg/iostreams" @@ -237,6 +238,36 @@ func TestNewVerifyCmd(t *testing.T) { } } +func TestVerifyCmdAuthChecks(t *testing.T) { + f := &cmdutil.Factory{} + + t.Run("by default auth check is required", func(t *testing.T) { + cmd := NewVerifyCmd(f, func(o *Options) error { + return nil + }) + + // IsAuthCheckEnabled assumes commands under test are subcommands + parent := &cobra.Command{Use: "root"} + parent.AddCommand(cmd) + + require.NoError(t, cmd.ParseFlags([]string{})) + require.True(t, cmdutil.IsAuthCheckEnabled(cmd), "expected auth check to be required") + }) + + t.Run("when --bundle flag is provided, auth check is not required", func(t *testing.T) { + cmd := NewVerifyCmd(f, func(o *Options) error { + return nil + }) + + // IsAuthCheckEnabled assumes commands under test are subcommands + parent := &cobra.Command{Use: "root"} + parent.AddCommand(cmd) + + require.NoError(t, cmd.ParseFlags([]string{"--bundle", "not-important"})) + require.False(t, cmdutil.IsAuthCheckEnabled(cmd), "expected auth check not to be required due to --bundle flag") + }) +} + func TestJSONOutput(t *testing.T) { testIO, _, out, _ := iostreams.Test() opts := Options{