Skip to content

Commit c325d1c

Browse files
committed
chore: update package/git urls and add missing test cases
1 parent 95ad8a6 commit c325d1c

File tree

17 files changed

+303
-26
lines changed

17 files changed

+303
-26
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ help:
1111
@printf " make fmt Format Go files\n"
1212
@printf " make tidy Tidy Go modules\n"
1313
@printf " make install Install to GOBIN/GOPATH/bin, or ~/.local/bin fallback\n"
14-
@printf " make clean Remove the built binary\n"
14+
@printf " make clean Remove build artifacts and Go caches\n"
1515

1616
build:
1717
go build -o $(APP) .
@@ -44,3 +44,6 @@ install:
4444

4545
clean:
4646
rm -f $(APP)
47+
rm -f *.test *.out coverage.out
48+
rm -rf dist bin
49+
go clean -cache -testcache -fuzzcache -modcache

cmd/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cmd
22

33
import (
4-
"github.com/managedssh/managedssh/internal/tui"
4+
"github.com/mylovelytools/managedssh/internal/tui"
55
"github.com/spf13/cobra"
66
)
77

@@ -25,7 +25,7 @@ Interface Controls:
2525
enter connect to selected host
2626
x export backup
2727
i import backup`,
28-
Args: cobra.NoArgs,
28+
Args: cobra.NoArgs,
2929
RunE: func(cmd *cobra.Command, args []string) error {
3030
return tui.Start()
3131
},

cmd/root_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package cmd
2+
3+
import (
4+
"bytes"
5+
"strings"
6+
"testing"
7+
)
8+
9+
func TestRootCmdRejectsPositionalArgs(t *testing.T) {
10+
err := rootCmd.Args(rootCmd, []string{"extra"})
11+
if err == nil {
12+
t.Fatal("expected positional args to be rejected")
13+
}
14+
}
15+
16+
func TestRootCmdHelpIncludesInterfaceControls(t *testing.T) {
17+
var out bytes.Buffer
18+
rootCmd.SetOut(&out)
19+
rootCmd.SetErr(&out)
20+
rootCmd.SetArgs([]string{"--help"})
21+
22+
if err := rootCmd.Execute(); err != nil {
23+
t.Fatalf("expected help to render without error: %v", err)
24+
}
25+
26+
help := out.String()
27+
if !strings.Contains(help, "Interface Controls:") {
28+
t.Fatal("expected help output to include interface controls header")
29+
}
30+
if !strings.Contains(help, "change master key") {
31+
t.Fatal("expected help output to include at least one dashboard control")
32+
}
33+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/managedssh/managedssh
1+
module github.com/mylovelytools/managedssh
22

33
go 1.26.1
44

internal/backup/transfer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"path/filepath"
99
"time"
1010

11-
"github.com/managedssh/managedssh/internal/vault"
11+
"github.com/mylovelytools/managedssh/internal/vault"
1212
)
1313

1414
const (

internal/backup/transfer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"reflect"
88
"testing"
99

10-
"github.com/managedssh/managedssh/internal/vault"
10+
"github.com/mylovelytools/managedssh/internal/vault"
1111
)
1212

1313
func TestExportImportRoundTrip(t *testing.T) {

internal/host/store.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,15 @@ func (h *Host) Normalize() {
230230
}
231231
}
232232
for i := range accounts {
233-
if accounts[i].UseDefault || accounts[i].AuthType == "" {
234-
accounts[i].UseDefault = false
233+
if accounts[i].UseDefault {
234+
accounts[i].AuthType = ""
235+
accounts[i].EncPassword = nil
236+
accounts[i].KeyPath = ""
237+
accounts[i].EncKey = nil
238+
accounts[i].EncKeyPass = nil
239+
continue
240+
}
241+
if accounts[i].AuthType == "" {
235242
accounts[i].AuthType = h.DefaultAuthType
236243
if accounts[i].AuthType == "" {
237244
accounts[i].AuthType = "key"

internal/sshclient/client_test.go

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package sshclient
2+
3+
import (
4+
"bytes"
5+
"os"
6+
"path/filepath"
7+
"testing"
8+
)
9+
10+
func TestUnknownHostErrorString(t *testing.T) {
11+
err := &UnknownHostError{Host: "example.com", Fingerprint: "SHA256:abc"}
12+
got := err.Error()
13+
want := "unknown host key for example.com (SHA256:abc)"
14+
if got != want {
15+
t.Fatalf("unexpected error string: got %q want %q", got, want)
16+
}
17+
}
18+
19+
func TestStripKnownHostPort(t *testing.T) {
20+
cases := []struct {
21+
in string
22+
want string
23+
}{
24+
{in: "example.com:22", want: "example.com"},
25+
{in: "[2001:db8::1]:22", want: "2001:db8::1"},
26+
{in: "example.com", want: "example.com"},
27+
}
28+
29+
for _, tc := range cases {
30+
if got := stripKnownHostPort(tc.in); got != tc.want {
31+
t.Fatalf("stripKnownHostPort(%q) = %q, want %q", tc.in, got, tc.want)
32+
}
33+
}
34+
}
35+
36+
func TestExpandUserPath(t *testing.T) {
37+
home, err := os.UserHomeDir()
38+
if err != nil {
39+
t.Fatalf("os.UserHomeDir() failed: %v", err)
40+
}
41+
42+
if got := expandUserPath("~"); got != home {
43+
t.Fatalf("expandUserPath(~) = %q, want %q", got, home)
44+
}
45+
46+
want := filepath.Join(home, ".ssh", "id_ed25519")
47+
if got := expandUserPath("~/.ssh/id_ed25519"); got != want {
48+
t.Fatalf("expandUserPath(~/...) = %q, want %q", got, want)
49+
}
50+
}
51+
52+
func TestNeedsPassphraseWithMissingPath(t *testing.T) {
53+
missing := filepath.Join(t.TempDir(), "does-not-exist")
54+
if NeedsPassphrase(missing, nil) {
55+
t.Fatal("expected false when key path does not exist")
56+
}
57+
}
58+
59+
func TestSessionZeroMethods(t *testing.T) {
60+
s := &Session{
61+
Password: []byte("pw"),
62+
KeyData: []byte("key"),
63+
KeyPassphrase: []byte("pass"),
64+
}
65+
66+
s.zeroPassword()
67+
if s.Password != nil {
68+
t.Fatal("expected Password to be nil after zeroPassword")
69+
}
70+
71+
s.zeroKeyData()
72+
if s.KeyData != nil {
73+
t.Fatal("expected KeyData to be nil after zeroKeyData")
74+
}
75+
76+
s.zeroKeyPassphrase()
77+
if s.KeyPassphrase != nil {
78+
t.Fatal("expected KeyPassphrase to be nil after zeroKeyPassphrase")
79+
}
80+
}
81+
82+
func TestTrustHostKeyNilInput(t *testing.T) {
83+
if err := TrustHostKey(nil); err == nil {
84+
t.Fatal("expected error for nil UnknownHostError")
85+
}
86+
}
87+
88+
func TestFlattenAuthMethodsEmpty(t *testing.T) {
89+
if got := flattenAuthMethods(nil); !bytes.Equal([]byte{}, []byte{}) && len(got) != 0 {
90+
t.Fatal("expected empty auth method list")
91+
}
92+
}

internal/tui/app.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import (
1212
"github.com/charmbracelet/lipgloss"
1313
"golang.org/x/crypto/ssh"
1414

15-
"github.com/managedssh/managedssh/internal/backup"
16-
"github.com/managedssh/managedssh/internal/host"
17-
"github.com/managedssh/managedssh/internal/sshclient"
18-
"github.com/managedssh/managedssh/internal/vault"
15+
"github.com/mylovelytools/managedssh/internal/backup"
16+
"github.com/mylovelytools/managedssh/internal/host"
17+
"github.com/mylovelytools/managedssh/internal/sshclient"
18+
"github.com/mylovelytools/managedssh/internal/vault"
1919
)
2020

2121
type phase int

internal/tui/app_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package tui
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestZeroBytes(t *testing.T) {
8+
data := []byte{1, 2, 3}
9+
zeroBytes(data)
10+
for i, b := range data {
11+
if b != 0 {
12+
t.Fatalf("expected data[%d] to be zero, got %d", i, b)
13+
}
14+
}
15+
}
16+
17+
func TestNewPasswordInputDefaults(t *testing.T) {
18+
in := newPasswordInput("Enter password")
19+
if in.Placeholder != "Enter password" {
20+
t.Fatalf("unexpected placeholder: %q", in.Placeholder)
21+
}
22+
if in.CharLimit != 128 {
23+
t.Fatalf("unexpected char limit: got %d want %d", in.CharLimit, 128)
24+
}
25+
}
26+
27+
func TestNewSearchInputDefaults(t *testing.T) {
28+
in := newSearchInput()
29+
if in.CharLimit != 64 {
30+
t.Fatalf("unexpected char limit: got %d want %d", in.CharLimit, 64)
31+
}
32+
if in.Placeholder == "" {
33+
t.Fatal("expected search placeholder to be set")
34+
}
35+
}
36+
37+
func TestModelViewWhenQuitting(t *testing.T) {
38+
m := model{quitting: true}
39+
if got := m.View(); got != "" {
40+
t.Fatalf("expected empty view while quitting, got %q", got)
41+
}
42+
}

0 commit comments

Comments
 (0)