forked from kryptco/kr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile_test.go
49 lines (41 loc) · 869 Bytes
/
profile_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
package kr
import (
"bytes"
"testing"
"golang.org/x/crypto/ssh"
)
var rsaProfile = Profile{
SSHWirePublicKey: pubWire,
Email: "[email protected]",
}
func TestRSAProfile(t *testing.T) {
authKey, err := rsaProfile.AuthorizedKeyString()
if err != nil {
t.Fatal(err)
}
key1, email, _, _, err := ssh.ParseAuthorizedKey([]byte(authKey))
if err != nil {
t.Fatal(err)
}
if email != rsaProfile.Email {
t.Fatal("email wrong")
}
pk, err := rsaProfile.RSAPublicKey()
if err != nil {
t.Fatal(err)
}
key2, err := ssh.NewPublicKey(pk)
if err != nil {
t.Fatal(err)
}
key3, err := rsaProfile.SSHPublicKey()
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(key1.Marshal(), key2.Marshal()) {
t.Fatal("authorized key != public key")
}
if !bytes.Equal(key1.Marshal(), key3.Marshal()) {
t.Fatal("authorized key != ssh public key")
}
}