-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathclient_test.go
66 lines (55 loc) · 1.32 KB
/
client_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
54
55
56
57
58
59
60
61
62
63
64
65
66
package reality_test
import (
"context"
"crypto/ecdh"
"crypto/ed25519"
"crypto/rand"
"encoding/base64"
"encoding/json"
"testing"
"github.com/howmp/reality"
)
func TestClient(t *testing.T) {
privEcdh, err := ecdh.X25519().GenerateKey(rand.Reader)
if err != nil {
t.Fatal(err)
}
pubVerify, _, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
t.Fatal(err)
}
config := &reality.ClientConfig{
SNI: "www.qq.com",
ServerAddr: "www.qq.com:443",
PublicKeyECDH: base64.StdEncoding.EncodeToString(privEcdh.Bytes()),
PublicKeyVerify: base64.StdEncoding.EncodeToString(pubVerify),
Debug: true,
}
d, err := json.Marshal(config)
if err != nil {
t.Fatal(err)
}
t.Log(string(d))
_, err = reality.NewClient(context.Background(), config)
if err == nil {
t.Fatal("should error")
}
}
func TestClientConfig(t *testing.T) {
configServer, err := reality.NewServerConfig("example.com:443", "127.0.0.1:443")
if err != nil {
t.Fatal(err)
}
config := configServer.ToClientConfig(0)
configData, err := config.Marshal()
if err != nil {
t.Fatal(err)
}
newConfig, err := reality.UnmarshalClientConfig(configData)
if err != nil {
t.Fatal(err)
}
if err := newConfig.Validate(); err != nil {
t.Fatal(err)
}
}