diff --git a/main.go b/main.go index 6d4b89c..6bddb39 100644 --- a/main.go +++ b/main.go @@ -1888,6 +1888,22 @@ func (u *ui) remotePreferencesRetentionSummary() string { return "KeePassGO keeps up to six recent connections. Store remote credentials in the vault if this connection should persist across devices or reinstalls." } +func (u *ui) availableRemoteProfiles() []vault.RemoteProfile { + profiles, err := u.state.RemoteProfiles() + if err != nil { + return nil + } + return profiles +} + +func (u *ui) availableRemoteCredentialEntries() []vault.Entry { + entries, err := u.state.RemoteCredentialEntries() + if err != nil { + return nil + } + return entries +} + func (u *ui) noteCurrentRemotePath() { status, ok := u.state.Session.(sessionStatus) if !ok || !status.IsRemote() || status.IsLocked() { diff --git a/main_test.go b/main_test.go index eaf9c7b..fbf96cb 100644 --- a/main_test.go +++ b/main_test.go @@ -4499,6 +4499,65 @@ func TestApplyingRecentRemoteRecordMarksSelectedRemoteConnection(t *testing.T) { } } +func TestUIAvailableRemoteProfilesUsesVaultProfiles(t *testing.T) { + t.Parallel() + + u := newUIWithModel("desktop", vault.Model{ + RemoteProfiles: []vault.RemoteProfile{ + { + ID: "family-webdav", + Name: "Family Vault", + Backend: vault.RemoteBackendWebDAV, + BaseURL: "https://dav.example.invalid/remote.php/dav", + Path: "files/family/keepass.kdbx", + }, + { + ID: "archive-webdav", + Name: "Archive Vault", + Backend: vault.RemoteBackendWebDAV, + BaseURL: "https://dav.example.invalid/remote.php/dav", + Path: "files/family/archive.kdbx", + }, + }, + }) + + got := u.availableRemoteProfiles() + if len(got) != 2 { + t.Fatalf("len(availableRemoteProfiles()) = %d, want 2", len(got)) + } + if got[0].ID != "archive-webdav" || got[1].ID != "family-webdav" { + t.Fatalf("availableRemoteProfiles() = %#v, want profiles sorted by name/id", got) + } +} + +func TestUIAvailableRemoteCredentialEntriesUsesVaultEntries(t *testing.T) { + t.Parallel() + + u := newUIWithModel("desktop", vault.Model{ + Entries: []vault.Entry{ + {ID: "cred-2", Title: "Zulu Sign-In", Username: "zuser", Path: []string{"Crew", "Internet"}}, + {ID: "cred-1", Title: "Alpha Sign-In", Username: "auser", Path: []string{"Crew", "Internet"}}, + }, + }) + + got := u.availableRemoteCredentialEntries() + if len(got) != 2 { + t.Fatalf("len(availableRemoteCredentialEntries()) = %d, want 2", len(got)) + } + if got[0].ID != "cred-1" || got[1].ID != "cred-2" { + t.Fatalf("availableRemoteCredentialEntries() = %#v, want entries sorted by title", got) + } +} + +func TestUIAvailableRemoteProfilesReturnsEmptyWhenLocked(t *testing.T) { + t.Parallel() + + u := newUIWithSession("desktop", summarySession{locked: true}) + if got := u.availableRemoteProfiles(); len(got) != 0 { + t.Fatalf("availableRemoteProfiles() = %#v, want empty when locked", got) + } +} + func TestSwitchToLifecycleSelectionResetsLockedLocalSession(t *testing.T) { t.Parallel()