MCPcopy Create free account
hub / github.com/dropbox/dbxcli / TestJSONHelpAuthBypassRequiresInstalledHelpCommand

Function TestJSONHelpAuthBypassRequiresInstalledHelpCommand

cmd/help_json_test.go:594–620  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

592}
593
594func TestJSONHelpAuthBypassRequiresInstalledHelpCommand(t *testing.T) {
595 root := &cobra.Command{Use: "dbxcli"}
596 root.PersistentFlags().String(outputFlag, "text", "")
597 if err := root.PersistentFlags().Set(outputFlag, "json"); err != nil {
598 t.Fatal(err)
599 }
600
601 fakeHelp := &cobra.Command{
602 Use: "help",
603 RunE: func(cmd *cobra.Command, args []string) error { return nil },
604 }
605 root.AddCommand(fakeHelp)
606 if commandIsJSONHelp(fakeHelp) {
607 t.Fatal("non-annotated command named help should not bypass auth")
608 }
609
610 jsonRoot := &cobra.Command{Use: "dbxcli"}
611 jsonRoot.PersistentFlags().String(outputFlag, "text", "")
612 if err := jsonRoot.PersistentFlags().Set(outputFlag, "json"); err != nil {
613 t.Fatal(err)
614 }
615 jsonHelp := newJSONAwareHelpCommand(jsonRoot)
616 jsonRoot.AddCommand(jsonHelp)
617 if !commandIsJSONHelp(jsonHelp) {
618 t.Fatal("installed JSON-aware help command should bypass auth for JSON help")
619 }
620}
621
622func TestJSONHelpRawArgsDetection(t *testing.T) {
623 tests := []struct {

Callers

nothing calls this directly

Calls 2

commandIsJSONHelpFunction · 0.85
newJSONAwareHelpCommandFunction · 0.85

Tested by

no test coverage detected