@@ -11,24 +11,31 @@ import (
1111)
1212
1313func TestNeedsFileBackendSetup (t * testing.T ) {
14- // Save and restore the original resolveBackendInfo .
14+ // Save and restore the original stubs .
1515 origResolve := resolveBackendInfo
16+ origProbe := isSecretServiceAvailable
1617
17- t .Cleanup (func () { resolveBackendInfo = origResolve })
18+ t .Cleanup (func () {
19+ resolveBackendInfo = origResolve
20+ isSecretServiceAvailable = origProbe
21+ })
1822
1923 // Mock: return "auto" backend with "default" source (typical fresh install).
2024 resolveBackendInfo = func () (secrets.KeyringBackendInfo , error ) {
2125 return secrets.KeyringBackendInfo {Value : "auto" , Source : "default" }, nil
2226 }
2327
28+ // Mock: SecretService is available (for dbus-present cases).
29+ isSecretServiceAvailable = func () bool { return true }
30+
2431 tests := []struct {
2532 name string
2633 goos string
2734 dbusAddr string
2835 want bool
2936 }{
3037 {"linux headless" , "linux" , "" , true },
31- {"linux with dbus" , "linux" , "/run/user/1000/bus" , false },
38+ {"linux with dbus and secret service " , "linux" , "/run/user/1000/bus" , false },
3239 {"darwin" , "darwin" , "" , false },
3340 {"darwin with dbus" , "darwin" , "/tmp/bus" , false },
3441 {"windows" , "windows" , "" , false },
@@ -46,6 +53,20 @@ func TestNeedsFileBackendSetup(t *testing.T) {
4653 }
4754 })
4855 }
56+
57+ // D-Bus present but SecretService NOT running → needs file backend.
58+ t .Run ("linux with dbus but no secret service" , func (t * testing.T ) {
59+ isSecretServiceAvailable = func () bool { return false }
60+
61+ got , err := NeedsFileBackendSetup ("linux" , "/run/user/1000/bus" )
62+ if err != nil {
63+ t .Fatalf ("unexpected error: %v" , err )
64+ }
65+
66+ if ! got {
67+ t .Error ("expected true when D-Bus present but SecretService unavailable" )
68+ }
69+ })
4970}
5071
5172func TestNeedsFileBackendSetup_ExplicitBackend (t * testing.T ) {
@@ -371,11 +392,13 @@ func TestSetupKeyringIfNeeded_NoOp_LinuxWithDBus(t *testing.T) {
371392 origGOOS := runtimeGOOS
372393 origResolve := resolveBackendInfo
373394 origGetenv := getenv
395+ origProbe := isSecretServiceAvailable
374396
375397 t .Cleanup (func () {
376398 runtimeGOOS = origGOOS
377399 resolveBackendInfo = origResolve
378400 getenv = origGetenv
401+ isSecretServiceAvailable = origProbe
379402 })
380403
381404 runtimeGOOS = "linux"
@@ -389,6 +412,8 @@ func TestSetupKeyringIfNeeded_NoOp_LinuxWithDBus(t *testing.T) {
389412
390413 return ""
391414 }
415+ // Mock SecretService as available so setup is a no-op.
416+ isSecretServiceAvailable = func () bool { return true }
392417
393418 var buf bytes.Buffer
394419 if err := SetupKeyringIfNeeded (& buf ); err != nil {
0 commit comments