lockbox

password manager
Log | Files | Refs | README | LICENSE

commit f9c91bb1561e6b9becc6e391867e360fdd570ccd
parent e071ba30f6128511b86ee2a99ba66ad6ae0a06db
Author: Sean Enck <sean@ttypty.com>
Date:   Mon,  9 Jun 2025 15:02:58 -0400

remove some overkill enable keys for config that don't really need to exist

Diffstat:
Minternal/app/completions/core.go | 13++-----------
Minternal/app/completions/core_test.go | 2+-
Minternal/app/list_test.go | 1-
Minternal/app/totp.go | 12++----------
Minternal/app/totp_test.go | 9+--------
Minternal/config/core.go | 10+++-------
Minternal/config/core_test.go | 11+++++------
Minternal/config/toml_test.go | 20++++++++++----------
Minternal/config/vars.go | 24------------------------
Minternal/config/vars_test.go | 12------------
Minternal/kdbx/actions_test.go | 3---
Minternal/platform/clip/core.go | 3---
Minternal/platform/clip/core_test.go | 13-------------
13 files changed, 24 insertions(+), 109 deletions(-)

diff --git a/internal/app/completions/core.go b/internal/app/completions/core.go @@ -43,8 +43,6 @@ type ( Conditionals struct { Not struct { ReadOnly string - CanClip string - CanTOTP string Ever string } Exported []string @@ -86,8 +84,6 @@ func NewConditionals() Conditionals { return fmt.Sprintf(shellIsNotText, fmt.Sprintf("$%s", k), right) } c.Not.ReadOnly = registerIsNotEqual(config.EnvReadOnly, config.YesValue) - c.Not.CanClip = registerIsNotEqual(config.EnvClipEnabled, config.NoValue) - c.Not.CanTOTP = registerIsNotEqual(config.EnvTOTPEnabled, config.NoValue) c.Not.Ever = fmt.Sprintf(shellIsNotText, "1", "0") return c } @@ -118,19 +114,14 @@ func Generate(completionType, exe string) ([]string, error) { } c.Conditionals = NewConditionals() - c.Options = c.newGenOptions([]string{commands.Help, commands.List, commands.Show, commands.Version, commands.JSON, commands.Groups}, + c.Options = c.newGenOptions([]string{commands.Help, commands.List, commands.Show, commands.Version, commands.JSON, commands.Groups, commands.Clip, commands.TOTP}, map[string]string{ - commands.Clip: c.Conditionals.Not.CanClip, - commands.TOTP: c.Conditionals.Not.CanTOTP, commands.Move: c.Conditionals.Not.ReadOnly, commands.Remove: c.Conditionals.Not.ReadOnly, commands.Insert: c.Conditionals.Not.ReadOnly, commands.Unset: c.Conditionals.Not.ReadOnly, }) - c.TOTPSubCommands = c.newGenOptions([]string{commands.TOTPMinimal, commands.TOTPOnce, commands.TOTPShow, commands.TOTPURL, commands.TOTPSeed}, - map[string]string{ - commands.TOTPClip: c.Conditionals.Not.CanClip, - }) + c.TOTPSubCommands = c.newGenOptions([]string{commands.TOTPMinimal, commands.TOTPOnce, commands.TOTPShow, commands.TOTPURL, commands.TOTPSeed, commands.TOTPClip}, nil) using, err := shell.ReadFile(filepath.Join("shell", fmt.Sprintf("%s.sh", completionType))) if err != nil { diff --git a/internal/app/completions/core_test.go b/internal/app/completions/core_test.go @@ -23,7 +23,7 @@ func TestCompletions(t *testing.T) { func TestConditionals(t *testing.T) { c := completions.NewConditionals() sort.Strings(c.Exported) - need := []string{"LOCKBOX_CLIP_ENABLED", "LOCKBOX_READONLY", "LOCKBOX_TOTP_ENABLED"} + need := []string{"LOCKBOX_READONLY"} if len(c.Exported) != len(need) || fmt.Sprintf("%v", c.Exported) != fmt.Sprintf("%v", need) { t.Errorf("invalid exports: %v", c.Exported) } diff --git a/internal/app/list_test.go b/internal/app/list_test.go @@ -29,7 +29,6 @@ func fullSetup(t *testing.T, keep bool) *kdbx.Transaction { store.SetString("LOCKBOX_STORE", file) store.SetArray("LOCKBOX_CREDENTIALS_PASSWORD", []string{"test"}) store.SetString("LOCKBOX_CREDENTIALS_PASSWORD_MODE", "plaintext") - store.SetString("LOCKBOX_TOTP_ENTRY", "totp") tr, err := kdbx.NewTransaction() if err != nil { t.Errorf("failed: %v", err) diff --git a/internal/app/totp.go b/internal/app/totp.go @@ -39,7 +39,6 @@ type ( TOTPOptions struct { app CommandOptions Clear func() - CanTOTP func() bool IsInteractive func() bool } ) @@ -50,7 +49,6 @@ func NewDefaultTOTPOptions(app CommandOptions) TOTPOptions { app: app, Clear: clearFunc, IsInteractive: config.EnvInteractive.Get, - CanTOTP: config.EnvTOTPEnabled.Get, } } @@ -141,10 +139,7 @@ func (args *TOTPArguments) display(opts TOTPOptions) error { if err != nil { return err } - allowColor, err := config.CanColor() - if err != nil { - return err - } + allowColor := config.CanColor() for { if !first { time.Sleep(500 * time.Millisecond) @@ -207,12 +202,9 @@ func (args *TOTPArguments) Do(opts TOTPOptions) error { if args.Mode == "" { return ErrUnknownTOTPMode } - if opts.Clear == nil || opts.CanTOTP == nil || opts.IsInteractive == nil { + if opts.Clear == nil || opts.IsInteractive == nil { return errors.New("invalid option functions") } - if !opts.CanTOTP() { - return ErrNoTOTP - } if args.Mode == commands.TOTPList { return doList(kdbx.OTPField, args.Entry, opts.app, false) } diff --git a/internal/app/totp_test.go b/internal/app/totp_test.go @@ -29,9 +29,6 @@ func newMock(t *testing.T) (*mockOptions, app.TOTPOptions) { opts := app.NewDefaultTOTPOptions(m) opts.Clear = func() { } - opts.CanTOTP = func() bool { - return true - } opts.IsInteractive = func() bool { return true } @@ -47,7 +44,6 @@ func fullTOTPSetup(t *testing.T, keep bool) *kdbx.Transaction { store.SetString("LOCKBOX_STORE", file) store.SetArray("LOCKBOX_CREDENTIALS_PASSWORD", []string{"test"}) store.SetString("LOCKBOX_CREDENTIALS_PASSWORD_MODE", "plaintext") - store.SetString("LOCKBOX_TOTP_ENTRY", "totp") store.SetInt64("LOCKBOX_TOTP_TIMEOUT", 1) tr, err := kdbx.NewTransaction() if err != nil { @@ -141,16 +137,13 @@ func TestDoErrors(t *testing.T) { if err := args.Do(opts); err == nil || err.Error() != "invalid option functions" { t.Errorf("invalid error: %v", err) } - opts.CanTOTP = func() bool { - return false - } if err := args.Do(opts); err == nil || err.Error() != "invalid option functions" { t.Errorf("invalid error: %v", err) } opts.IsInteractive = func() bool { return false } - if err := args.Do(opts); err == nil || err.Error() != "totp is disabled" { + if err := args.Do(opts); err == nil || err.Error() != "'' is not a TOTP entry" { t.Errorf("invalid error: %v", err) } } diff --git a/internal/config/core.go b/internal/config/core.go @@ -149,15 +149,11 @@ func formatterTOTP(key, value string) string { } // CanColor indicates if colorized output is allowed (or disabled) -func CanColor() (bool, error) { +func CanColor() bool { if _, noColor := os.LookupEnv("NO_COLOR"); noColor { - return false, nil + return false } - colors := EnvInteractive.Get() - if colors { - colors = EnvColorEnabled.Get() - } - return colors, nil + return EnvInteractive.Get() } func readNested(v reflect.Type, root string) []string { diff --git a/internal/config/core_test.go b/internal/config/core_test.go @@ -38,27 +38,26 @@ func TestNewEnvFiles(t *testing.T) { func TestCanColor(t *testing.T) { store.Clear() - if can, _ := config.CanColor(); !can { + if can := config.CanColor(); !can { t.Error("should be able to color") } for raw, expect := range map[string]bool{ - "INTERACTIVE": true, - "COLOR_ENABLED": true, + "INTERACTIVE": true, } { store.Clear() key := fmt.Sprintf("LOCKBOX_%s", raw) store.SetBool(key, true) - if can, _ := config.CanColor(); can != expect { + if can := config.CanColor(); can != expect { t.Errorf("expect != actual: %s", key) } store.SetBool(key, false) - if can, _ := config.CanColor(); can == expect { + if can := config.CanColor(); can == expect { t.Errorf("expect == actual: %s", key) } } store.Clear() t.Setenv("NO_COLOR", "1") - if can, _ := config.CanColor(); can { + if can := config.CanColor(); can { t.Error("should NOT be able to color") } } diff --git a/internal/config/toml_test.go b/internal/config/toml_test.go @@ -179,16 +179,16 @@ timeout = -1 func TestReadBool(t *testing.T) { store.Clear() data := ` -[totp] -enabled = 1 +[clip] +osc52 = 1 ` r := strings.NewReader(data) if err := config.LoadConfig(r, emptyRead); err == nil || err.Error() != "non-bool found where expected: 1" { t.Errorf("invalid error: %v", err) } data = `include = [] -[totp] -enabled = true +[clip] +osc52 = true ` r = strings.NewReader(data) if err := config.LoadConfig(r, emptyRead); err != nil { @@ -197,13 +197,13 @@ enabled = true if len(store.List()) != 1 { t.Errorf("invalid store") } - val, ok := store.GetBool("LOCKBOX_TOTP_ENABLED") + val, ok := store.GetBool("LOCKBOX_CLIP_OSC52") if !val || !ok { t.Errorf("invalid object: %v", val) } data = `include = [] -[totp] -enabled = false +[clip] +osc52 = false ` r = strings.NewReader(data) if err := config.LoadConfig(r, emptyRead); err != nil { @@ -212,7 +212,7 @@ enabled = false if len(store.List()) != 1 { t.Errorf("invalid store") } - val, ok = store.GetBool("LOCKBOX_TOTP_ENABLED") + val, ok = store.GetBool("LOCKBOX_CLIP_OSC52") if val || !ok { t.Errorf("invalid object: %v", val) } @@ -251,8 +251,8 @@ func TestDefaultTOMLToLoadFile(t *testing.T) { if err := config.LoadConfigFile(file); err != nil { t.Errorf("invalid error: %v", err) } - if len(store.List()) != 20 { - t.Errorf("invalid environment after load") + if len(store.List()) != 17 { + t.Errorf("invalid environment after load: %d", len(store.List())) } } diff --git a/internal/config/vars.go b/internal/config/vars.go @@ -37,14 +37,6 @@ var ( description: "Enable OSC52 clipboard mode.", }), }) - // EnvTOTPEnabled indicates if TOTP is allowed - EnvTOTPEnabled = environmentRegister(EnvironmentBool{ - environmentDefault: newDefaultedEnvironment(true, - environmentBase{ - key: totpCategory + "ENABLED", - description: "Enable TOTP integrations.", - }), - }) // EnvReadOnly indicates if in read-only mode EnvReadOnly = environmentRegister(EnvironmentBool{ environmentDefault: newDefaultedEnvironment(false, @@ -53,22 +45,6 @@ var ( description: "Operate in readonly mode.", }), }) - // EnvClipEnabled indicates if clipboard is enabled - EnvClipEnabled = environmentRegister(EnvironmentBool{ - environmentDefault: newDefaultedEnvironment(true, - environmentBase{ - key: clipCategory + "ENABLED", - description: "Enable clipboard operations.", - }), - }) - // EnvColorEnabled indicates if colors are enabled - EnvColorEnabled = environmentRegister(EnvironmentBool{ - environmentDefault: newDefaultedEnvironment(true, - environmentBase{ - key: "COLOR_ENABLED", - description: "Enable terminal colors.", - }), - }) // EnvInteractive indicates if operating in interactive mode EnvInteractive = environmentRegister(EnvironmentBool{ environmentDefault: newDefaultedEnvironment(true, diff --git a/internal/config/vars_test.go b/internal/config/vars_test.go @@ -24,10 +24,6 @@ func checkYesNo(key string, t *testing.T, obj config.EnvironmentBool, onEmpty bo } } -func TestColorSetting(t *testing.T) { - checkYesNo("LOCKBOX_COLOR_ENABLED", t, config.EnvColorEnabled, true) -} - func TestInteractiveSetting(t *testing.T) { checkYesNo("LOCKBOX_INTERACTIVE", t, config.EnvInteractive, true) } @@ -40,14 +36,6 @@ func TestIsOSC52(t *testing.T) { checkYesNo("LOCKBOX_CLIP_OSC52", t, config.EnvClipOSC52, false) } -func TestIsNoTOTP(t *testing.T) { - checkYesNo("LOCKBOX_TOTP_ENABLED", t, config.EnvTOTPEnabled, true) -} - -func TestIsNoClip(t *testing.T) { - checkYesNo("LOCKBOX_CLIP_ENABLED", t, config.EnvClipEnabled, true) -} - func TestFormatTOTP(t *testing.T) { store.Clear() otp := config.EnvTOTPFormat.Get("otpauth://abc") diff --git a/internal/kdbx/actions_test.go b/internal/kdbx/actions_test.go @@ -32,7 +32,6 @@ func fullSetup(t *testing.T, keep bool) *kdbx.Transaction { store.SetString("LOCKBOX_STORE", file) store.SetArray("LOCKBOX_CREDENTIALS_PASSWORD", []string{"test"}) store.SetString("LOCKBOX_CREDENTIALS_PASSWORD_MODE", "plaintext") - store.SetString("LOCKBOX_TOTP_ENTRY", "totp") tr, err := kdbx.NewTransaction() if err != nil { t.Errorf("failed: %v", err) @@ -50,7 +49,6 @@ func TestKeyFile(t *testing.T) { store.SetArray("LOCKBOX_CREDENTIALS_PASSWORD", []string{"test"}) store.SetString("LOCKBOX_CREDENTIALS_KEY_FILE", keyFile) store.SetString("LOCKBOX_CREDENTIALS_PASSWORD_MODE", "plaintext") - store.SetString("LOCKBOX_TOTP_ENTRY", "totp") os.WriteFile(keyFile, []byte("test"), 0o644) tr, err := kdbx.NewTransaction() if err != nil { @@ -329,7 +327,6 @@ func TestReKey(t *testing.T) { store.SetString("LOCKBOX_STORE", file) store.SetArray("LOCKBOX_CREDENTIALS_PASSWORD", []string{"test"}) store.SetString("LOCKBOX_CREDENTIALS_PASSWORD_MODE", "plaintext") - store.SetString("LOCKBOX_TOTP_ENTRY", "totp") tr, err := kdbx.NewTransaction() if err != nil { t.Errorf("failed: %v", err) diff --git a/internal/platform/clip/core.go b/internal/platform/clip/core.go @@ -32,9 +32,6 @@ func newBoard(copying, pasting []string) (Board, error) { // New will retrieve the commands to use for clipboard operations. func New() (Board, error) { - if !config.EnvClipEnabled.Get() { - return Board{}, errors.New("clipboard is off") - } overridePaste := config.EnvClipPaste.Get() overrideCopy := config.EnvClipCopy.Get() setPaste := len(overridePaste) > 0 diff --git a/internal/platform/clip/core_test.go b/internal/platform/clip/core_test.go @@ -8,22 +8,10 @@ import ( "git.sr.ht/~enckse/lockbox/internal/platform/clip" ) -func TestNoClipboard(t *testing.T) { - store.Clear() - defer store.Clear() - store.SetBool("LOCKBOX_CLIP_OSC52", false) - store.SetBool("LOCKBOX_CLIP_ENABLED", false) - _, err := clip.New() - if err == nil || err.Error() != "clipboard is off" { - t.Errorf("invalid error: %v", err) - } -} - func TestMaxTime(t *testing.T) { store.Clear() defer store.Clear() store.SetBool("LOCKBOX_CLIP_OSC52", false) - store.SetBool("LOCKBOX_CLIP_ENABLED", true) store.SetString("LOCKBOX_PLATFORM", string(platform.Systems.LinuxWaylandSystem)) c, err := clip.New() if err != nil { @@ -51,7 +39,6 @@ func TestClipboardInstances(t *testing.T) { store.Clear() defer store.Clear() store.SetBool("LOCKBOX_CLIP_OSC52", false) - store.SetBool("LOCKBOX_CLIP_ENABLED", true) for _, item := range platform.Systems.List() { store.SetString("LOCKBOX_PLATFORM", item) _, err := clip.New()