Add Android shared vault import flow
This commit is contained in:
@@ -5653,6 +5653,74 @@ func TestDefaultStatePathsUsesProvidedStateDir(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestImportedVaultDestinationUsesIncomingFilenameInsideDefaultDirectory(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
u := newUIWithSession("desktop", &session.Manager{}, statePaths{
|
||||
DefaultSaveAsPath: filepath.Join(t.TempDir(), "vault.kdbx"),
|
||||
})
|
||||
|
||||
got := u.importedVaultDestination("shared-home.kdbx")
|
||||
want := filepath.Join(filepath.Dir(u.defaultSaveAsPath), "shared-home.kdbx")
|
||||
if got != want {
|
||||
t.Fatalf("importedVaultDestination() = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUIImportSharedVaultBytesActionCopiesVaultAndSelectsIt(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
dir := t.TempDir()
|
||||
paths := statePaths{
|
||||
DefaultSaveAsPath: filepath.Join(dir, "vault.kdbx"),
|
||||
RecentVaultsPath: filepath.Join(dir, "recent-vaults.json"),
|
||||
RecentRemotesPath: filepath.Join(dir, "recent-remotes.json"),
|
||||
UIPreferencesPath: filepath.Join(dir, "ui-prefs.json"),
|
||||
}
|
||||
key := vault.MasterKey{Password: "correct horse battery staple"}
|
||||
var encoded bytes.Buffer
|
||||
if err := vault.SaveKDBXWithKey(&encoded, vault.Model{
|
||||
Entries: []vault.Entry{
|
||||
{ID: "entry-1", Title: "Vault Console", Path: []string{"Root", "Internet"}},
|
||||
},
|
||||
}, key); err != nil {
|
||||
t.Fatalf("SaveKDBXWithKey() error = %v", err)
|
||||
}
|
||||
|
||||
u := newUIWithState("phone", &session.Manager{}, paths)
|
||||
u.lifecycleMode = "remote"
|
||||
|
||||
if err := u.importSharedVaultBytesAction("shared-home.kdbx", encoded.Bytes()); err != nil {
|
||||
t.Fatalf("importSharedVaultBytesAction() error = %v", err)
|
||||
}
|
||||
|
||||
wantPath := filepath.Join(dir, "shared-home.kdbx")
|
||||
if got := u.vaultPath.Text(); got != wantPath {
|
||||
t.Fatalf("vaultPath = %q, want %q", got, wantPath)
|
||||
}
|
||||
if got := u.lifecycleMode; got != "local" {
|
||||
t.Fatalf("lifecycleMode = %q, want local", got)
|
||||
}
|
||||
if !u.hasSelectedLifecycleTarget() {
|
||||
t.Fatal("hasSelectedLifecycleTarget() = false, want true after import")
|
||||
}
|
||||
if _, err := os.Stat(wantPath); err != nil {
|
||||
t.Fatalf("Stat(imported vault) error = %v", err)
|
||||
}
|
||||
|
||||
reopened := newUIWithState("phone", &session.Manager{}, paths)
|
||||
reopened.vaultPath.SetText(wantPath)
|
||||
reopened.masterPassword.SetText(key.Password)
|
||||
if err := reopened.openVaultAction(); err != nil {
|
||||
t.Fatalf("openVaultAction(imported) error = %v", err)
|
||||
}
|
||||
reopened.state.NavigateToPath([]string{"Root", "Internet"})
|
||||
reopened.filter()
|
||||
if got := reopened.filteredTitles(); !slices.Equal(got, []string{"Vault Console"}) {
|
||||
t.Fatalf("filteredTitles() = %v, want [Vault Console]", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefaultStatePathsUsesEnvironmentStateDirWhenFlagUnset(t *testing.T) {
|
||||
base := filepath.Join(t.TempDir(), "keepassgo-state-env")
|
||||
t.Setenv("KEEPASSGO_STATE_DIR", base)
|
||||
@@ -5765,6 +5833,17 @@ func TestSupportsDesktopFilePicker(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSupportsSharedVaultImport(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if got := supportsSharedVaultImport("android"); !got {
|
||||
t.Fatal("supportsSharedVaultImport(android) = false, want true")
|
||||
}
|
||||
if got := supportsSharedVaultImport("linux"); got {
|
||||
t.Fatal("supportsSharedVaultImport(linux) = true, want false")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnterOnLocalLifecycleScreenDefaultsToOpenVault(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user