Expose vault-backed remote choices in UI

This commit is contained in:
Joe Julian
2026-04-06 12:20:19 -07:00
parent ef01e33990
commit 4da9c07b32
2 changed files with 75 additions and 0 deletions
+16
View File
@@ -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() {
+59
View File
@@ -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()