mirror of
https://github.com/db9979/sshtermy.git
synced 2026-12-06 12:44:08 +01:00
- Pfade unter dem Home werden als ~/… gespeichert (passen auf jedem Rechner) - auf einem anderen Rechner gewählter Pfad gilt nur lokal (Data.LocalKeys) - fehlt der Key: gleicher Pfad unter eigenem Home, ~/.ssh/<Name> probieren - sonst Abfrage: Key aus ~/.ssh wählen oder Pfad eingeben, optional einbetten Claude-Session: https://claude.ai/code/session_018i4GUk7sFy6cJyktEcKXcm Co-authored-by: Claude <noreply@anthropic.com>
49 lines
1.6 KiB
Go
49 lines
1.6 KiB
Go
package domain
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestPortableKeyPath(t *testing.T) {
|
|
home := filepath.Join(string(filepath.Separator)+"home", "dom")
|
|
in := filepath.Join(home, ".ssh", "id_ed25519")
|
|
if got := PortableKeyPath(in, home); got != "~/.ssh/id_ed25519" {
|
|
t.Fatalf("PortableKeyPath = %q", got)
|
|
}
|
|
other := filepath.Join(string(filepath.Separator)+"opt", "keys", "k")
|
|
if got := PortableKeyPath(other, home); got != other {
|
|
t.Fatalf("fremder Pfad geändert: %q", got)
|
|
}
|
|
if got := PortableKeyPath(home+"x/k", home); got != home+"x/k" {
|
|
t.Fatalf("Präfix ohne Trenner: %q", got)
|
|
}
|
|
if got := ExpandKeyPath("~/.ssh/id", home); got != filepath.Join(home, ".ssh", "id") {
|
|
t.Fatalf("ExpandKeyPath = %q", got)
|
|
}
|
|
}
|
|
|
|
func TestKeyPathCandidatesForeignHome(t *testing.T) {
|
|
home := filepath.Join(string(filepath.Separator)+"Users", "dom")
|
|
cases := map[string][]string{
|
|
`C:\Users\db9\.ssh\id_ed25519`: {`C:\Users\db9\.ssh\id_ed25519`, filepath.Join(home, ".ssh", "id_ed25519")},
|
|
`C:\Users\db9\AppData\Local\NVIDIA Corporation\Sync\config\nvsync.key`: {
|
|
`C:\Users\db9\AppData\Local\NVIDIA Corporation\Sync\config\nvsync.key`,
|
|
filepath.Join(home, "AppData", "Local", "NVIDIA Corporation", "Sync", "config", "nvsync.key"),
|
|
filepath.Join(home, ".ssh", "nvsync.key"),
|
|
},
|
|
"/home/x/keys/k": {"/home/x/keys/k", filepath.Join(home, "keys", "k"), filepath.Join(home, ".ssh", "k")},
|
|
}
|
|
for in, want := range cases {
|
|
got := KeyPathCandidates(in, home)
|
|
if len(got) != len(want) {
|
|
t.Fatalf("%s: %q", in, got)
|
|
}
|
|
for i := range want {
|
|
if got[i] != want[i] {
|
|
t.Fatalf("%s: %q, erwartet %q", in, got, want)
|
|
}
|
|
}
|
|
}
|
|
}
|