Files

36 lines
1.1 KiB
Go

package cmd
import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"os"
"path/filepath"
"testing"
)
func TestOnlyExplicitNoSSOFlagSkipsInitialSSOSetup(t *testing.T) {
for _, enabled := range []bool{false, true} {
dir := t.TempDir()
config := filepath.Join(dir, "config.json")
// A JSON setting must not enable this process-only bypass.
if err := os.WriteFile(config, []byte(`{"no-sso":true}`), 0600); err != nil {
t.Fatal(err)
}
command := &cobra.Command{Use: "filebrowser"}
command.Flags().String("config", config, "")
command.Flags().String("database", filepath.Join(dir, "test.db"), "")
command.Flags().Bool("no-sso", false, "")
if enabled {
command.Flags().Set("no-sso", "true")
}
called := false
err := withViperAndStore(func(_ *cobra.Command, _ []string, _ *viper.Viper, _ *store) error { called = true; return nil }, storeOptions{allowsNoDatabase: true})(command, nil)
if enabled && (err != nil || !called) {
t.Fatalf("explicit flag blocked: %v", err)
}
if !enabled && (err == nil || called) {
t.Fatal("configuration silently enabled no-sso")
}
}
}