forked from charmbracelet/wishlist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_auth_test.go
53 lines (45 loc) · 1.25 KB
/
client_auth_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package wishlist
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/charmbracelet/keygen"
"github.com/stretchr/testify/require"
)
func TestUserKeys(t *testing.T) {
fn := func(home string) func(string) (string, error) {
return func(s string) (string, error) {
return filepath.Join(home, strings.TrimPrefix(s, "~"+string(os.PathSeparator))), nil
}
}
sshKeygen := func(tb testing.TB, tmp string, algo keygen.KeyType) {
tb.Helper()
path := filepath.Join(tmp, ".ssh")
require.NoError(tb, os.MkdirAll(path, 0765))
_, err := keygen.NewWithWrite(path, "id", nil, keygen.RSA)
require.NoError(tb, err)
}
t.Run("rsa", func(t *testing.T) {
tmp := t.TempDir()
sshKeygen(t, tmp, keygen.RSA)
methods, err := tryUserKeysInternal(fn(tmp))
require.NoError(t, err)
require.Len(t, methods, 1)
})
t.Run("ecdsa", func(t *testing.T) {
tmp := t.TempDir()
sshKeygen(t, tmp, keygen.ECDSA)
methods, err := tryUserKeysInternal(fn(tmp))
require.NoError(t, err)
require.Len(t, methods, 1)
})
t.Run("ed25519", func(t *testing.T) {
tmp := t.TempDir()
sshKeygen(t, tmp, keygen.Ed25519)
methods, err := tryUserKeysInternal(fn(tmp))
require.NoError(t, err)
require.Len(t, methods, 1)
})
// TODO: how to test ecdsa-sk and ed25519-sk?
}