Handle local-open remote sync fallback
This commit is contained in:
+81
-1
@@ -1447,7 +1447,13 @@ func TestUIChangeMasterKeyModeForExistingVault(t *testing.T) {
|
||||
t.Fatalf("WriteFile(updated.key) error = %v", err)
|
||||
}
|
||||
|
||||
u := newUIWithSession("desktop", &session.Manager{})
|
||||
stateDir := t.TempDir()
|
||||
u := newUIWithSession("desktop", &session.Manager{}, statePaths{
|
||||
DefaultSaveAsPath: filepath.Join(stateDir, "default.kdbx"),
|
||||
RecentVaultsPath: filepath.Join(stateDir, "recent-vaults.json"),
|
||||
RecentRemotesPath: filepath.Join(stateDir, "recent-remotes.json"),
|
||||
UIPreferencesPath: filepath.Join(stateDir, "ui-prefs.json"),
|
||||
})
|
||||
u.setMasterKeyMode(vault.MasterKeyModePasswordOnly)
|
||||
u.masterPassword.SetText("old-password")
|
||||
if err := u.createVaultAction(); err != nil {
|
||||
@@ -2360,6 +2366,62 @@ func TestUIOpenVaultActionAutomaticallySynchronizesFromRemoteBinding(t *testing.
|
||||
}
|
||||
}
|
||||
|
||||
func TestUIOpenVaultActionKeepsLocalVaultOpenWhenAutoSyncFails(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
key := vault.MasterKey{Password: "correct horse battery staple"}
|
||||
path := filepath.Join(t.TempDir(), "family.kdbx")
|
||||
localModel := vault.Model{
|
||||
Entries: []vault.Entry{
|
||||
{ID: "entry-1", Title: "Local Cache", Path: []string{"Root", "Internet"}},
|
||||
{ID: "remote-creds-1", Title: "WebDAV Sign-In", Username: "tjulian", Password: "token-1", Path: []string{"Crew", "Internet"}},
|
||||
},
|
||||
RemoteProfiles: []vault.RemoteProfile{{
|
||||
ID: "family-webdav",
|
||||
Name: "Family Vault",
|
||||
Backend: vault.RemoteBackendWebDAV,
|
||||
BaseURL: "https://unreachable.example.invalid/remote.php/dav",
|
||||
Path: "files/family/keepass.kdbx",
|
||||
}},
|
||||
}
|
||||
writeKDBXMainTestFile(t, path, localModel, key)
|
||||
|
||||
u := newUIWithState("desktop", &session.Manager{}, statePaths{
|
||||
DefaultSaveAsPath: filepath.Join(t.TempDir(), "default.kdbx"),
|
||||
RecentVaultsPath: filepath.Join(t.TempDir(), "recent-vaults.json"),
|
||||
RecentRemotesPath: filepath.Join(t.TempDir(), "recent-remotes.json"),
|
||||
UIPreferencesPath: filepath.Join(t.TempDir(), "ui-prefs.json"),
|
||||
})
|
||||
u.recentRemotes = []recentRemoteRecord{{
|
||||
BaseURL: "https://unreachable.example.invalid/remote.php/dav",
|
||||
Path: "files/family/keepass.kdbx",
|
||||
LocalVaultPath: path,
|
||||
RemoteProfileID: "family-webdav",
|
||||
CredentialEntryID: "remote-creds-1",
|
||||
SyncMode: string(appstate.SyncModeAutomaticOnOpenSave),
|
||||
}}
|
||||
u.vaultPath.SetText(path)
|
||||
u.masterPassword.SetText(key.Password)
|
||||
|
||||
if err := u.openVaultAction(); err != nil {
|
||||
t.Fatalf("openVaultAction() error = %v, want local open to succeed even if auto-sync fails", err)
|
||||
}
|
||||
|
||||
current, err := u.state.Session.Current()
|
||||
if err != nil {
|
||||
t.Fatalf("Session.Current() error = %v", err)
|
||||
}
|
||||
if _, err := current.EntryByID("entry-1"); err != nil {
|
||||
t.Fatalf("EntryByID(entry-1) error = %v, want local vault opened", err)
|
||||
}
|
||||
if got := u.state.StatusMessage; !strings.Contains(got, "Remote sync on open failed:") {
|
||||
t.Fatalf("StatusMessage = %q, want nonfatal remote sync failure notice", got)
|
||||
}
|
||||
if got := u.state.ErrorMessage; got != "" {
|
||||
t.Fatalf("ErrorMessage = %q, want empty for nonfatal remote sync failure", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUISaveActionAutomaticallySynchronizesToRemoteBinding(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -2456,6 +2518,24 @@ func TestUISaveActionAutomaticallySynchronizesToRemoteBinding(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPickExistingFileOutputExtractsPathFromPortalNoise(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
output := strings.Join([]string{
|
||||
"(zenity:1): Gdk-DEBUG: Ignoring portal setting",
|
||||
"/home/tester/vaults/family.kdbx",
|
||||
"",
|
||||
}, "\n")
|
||||
|
||||
got, err := parsePickedFilePath([]byte(output))
|
||||
if err != nil {
|
||||
t.Fatalf("parsePickedFilePath() error = %v", err)
|
||||
}
|
||||
if got != "/home/tester/vaults/family.kdbx" {
|
||||
t.Fatalf("parsePickedFilePath() = %q, want /home/tester/vaults/family.kdbx", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUIRemoteSaveConflictShowsVisibleErrorAndKeepsDirtyState(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user