Default Enter to opening the selected vault
This commit is contained in:
@@ -1733,6 +1733,7 @@ func TestUINoteRecentVaultDeduplicatesAndOrdersMostRecentFirst(t *testing.T) {
|
|||||||
|
|
||||||
u := newUIWithSession("desktop", &session.Manager{})
|
u := newUIWithSession("desktop", &session.Manager{})
|
||||||
u.recentVaultsPath = filepath.Join(t.TempDir(), "recent-vaults.json")
|
u.recentVaultsPath = filepath.Join(t.TempDir(), "recent-vaults.json")
|
||||||
|
u.recentVaults = nil
|
||||||
u.noteRecentVault("/tmp/one.kdbx")
|
u.noteRecentVault("/tmp/one.kdbx")
|
||||||
u.noteRecentVault("/tmp/two.kdbx")
|
u.noteRecentVault("/tmp/two.kdbx")
|
||||||
u.noteRecentVault("/tmp/one.kdbx")
|
u.noteRecentVault("/tmp/one.kdbx")
|
||||||
@@ -1748,11 +1749,13 @@ func TestUILoadsRecentVaultsFromPersistedConfig(t *testing.T) {
|
|||||||
configPath := filepath.Join(t.TempDir(), "recent-vaults.json")
|
configPath := filepath.Join(t.TempDir(), "recent-vaults.json")
|
||||||
first := newUIWithSession("desktop", &session.Manager{})
|
first := newUIWithSession("desktop", &session.Manager{})
|
||||||
first.recentVaultsPath = configPath
|
first.recentVaultsPath = configPath
|
||||||
|
first.recentVaults = nil
|
||||||
first.noteRecentVault("/tmp/one.kdbx")
|
first.noteRecentVault("/tmp/one.kdbx")
|
||||||
first.noteRecentVault("/tmp/two.kdbx")
|
first.noteRecentVault("/tmp/two.kdbx")
|
||||||
|
|
||||||
second := newUIWithSession("desktop", &session.Manager{})
|
second := newUIWithSession("desktop", &session.Manager{})
|
||||||
second.recentVaultsPath = configPath
|
second.recentVaultsPath = configPath
|
||||||
|
second.recentVaults = nil
|
||||||
second.loadRecentVaults()
|
second.loadRecentVaults()
|
||||||
|
|
||||||
if got := second.recentVaults; !slices.Equal(got, []string{"/tmp/two.kdbx", "/tmp/one.kdbx"}) {
|
if got := second.recentVaults; !slices.Equal(got, []string{"/tmp/two.kdbx", "/tmp/one.kdbx"}) {
|
||||||
@@ -1760,6 +1763,63 @@ func TestUILoadsRecentVaultsFromPersistedConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEnterOnLocalLifecycleScreenDefaultsToOpenVault(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
path := filepath.Join(t.TempDir(), "vault.kdbx")
|
||||||
|
var encoded bytes.Buffer
|
||||||
|
if err := vault.SaveKDBX(&encoded, vault.Model{}, "correct horse battery staple"); err != nil {
|
||||||
|
t.Fatalf("SaveKDBX() error = %v", err)
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(path, encoded.Bytes(), 0o600); err != nil {
|
||||||
|
t.Fatalf("WriteFile(vault.kdbx) error = %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
u := newUIWithSession("desktop", &session.Manager{})
|
||||||
|
u.masterPassword.SetText("correct horse battery staple")
|
||||||
|
u.vaultPath.SetText(path)
|
||||||
|
|
||||||
|
handled := u.handleKeyPress(key.NameReturn, 0)
|
||||||
|
if !handled {
|
||||||
|
t.Fatal("handleKeyPress(Return) = false, want true")
|
||||||
|
}
|
||||||
|
if got := u.state.StatusMessage; got != "open vault complete" {
|
||||||
|
t.Fatalf("StatusMessage = %q, want %q", got, "open vault complete")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEnterOnRemoteLifecycleScreenDefaultsToOpenRemoteVault(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
masterKey := vault.MasterKey{Password: "correct horse battery staple"}
|
||||||
|
var encoded bytes.Buffer
|
||||||
|
if err := vault.SaveKDBXWithKey(&encoded, vault.Model{}, masterKey); err != nil {
|
||||||
|
t.Fatalf("SaveKDBXWithKey() error = %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Method != http.MethodGet {
|
||||||
|
t.Fatalf("unexpected method = %s, want GET", r.Method)
|
||||||
|
}
|
||||||
|
_, _ = w.Write(encoded.Bytes())
|
||||||
|
}))
|
||||||
|
defer server.Close()
|
||||||
|
|
||||||
|
u := newUIWithSession("desktop", &session.Manager{})
|
||||||
|
u.lifecycleMode = "remote"
|
||||||
|
u.masterPassword.SetText("correct horse battery staple")
|
||||||
|
u.remoteBaseURL.SetText(server.URL)
|
||||||
|
u.remotePath.SetText("vault.kdbx")
|
||||||
|
|
||||||
|
handled := u.handleKeyPress(key.NameReturn, 0)
|
||||||
|
if !handled {
|
||||||
|
t.Fatal("handleKeyPress(Return) = false, want true")
|
||||||
|
}
|
||||||
|
if got := u.state.StatusMessage; got != "open remote vault complete" {
|
||||||
|
t.Fatalf("StatusMessage = %q, want %q", got, "open remote vault complete")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestUICopyActionsWriteExpectedClipboardContentsAndSanitizedFeedback(t *testing.T) {
|
func TestUICopyActionsWriteExpectedClipboardContentsAndSanitizedFeedback(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,14 @@ func (u *ui) handleKeyPress(name key.Name, modifiers key.Modifiers) bool {
|
|||||||
if u.handleShortcutKey(name, modifiers) {
|
if u.handleShortcutKey(name, modifiers) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
if u.shouldShowLifecycleSetup() && name == key.NameReturn {
|
||||||
|
if u.lifecycleMode == "remote" {
|
||||||
|
u.runAction("open remote vault", u.openRemoteAction)
|
||||||
|
} else {
|
||||||
|
u.runAction("open vault", u.openVaultAction)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
switch name {
|
switch name {
|
||||||
case key.NameTab:
|
case key.NameTab:
|
||||||
|
|||||||
Reference in New Issue
Block a user