forked from x04/cclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_test.go
64 lines (52 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
package cclient
import (
"encoding/json"
"io"
"io/ioutil"
"testing"
tls "github.com/refraction-networking/utls"
)
type JA3Response struct {
JA3Hash string `json:"ja3_hash"`
JA3 string `json:"ja3"`
UserAgent string `json:"User-Agent"`
}
func readAndClose(r io.ReadCloser) ([]byte, error) {
readBytes, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
return readBytes, r.Close()
}
const Chrome83Hash = "b32309a26951912be7dba376398abc3b"
var client, _ = NewClient(tls.HelloChrome_83) // cannot throw an error because there is no proxy
func TestCClient_JA3(t *testing.T) {
resp, err := client.Get("https://ja3er.com/json")
if err != nil {
t.Fatal(err)
}
respBody, err := readAndClose(resp.Body)
if err != nil {
t.Fatal(err)
}
var ja3Response JA3Response
if err := json.Unmarshal(respBody, &ja3Response); err != nil {
t.Fatal(err)
}
if ja3Response.JA3Hash != Chrome83Hash {
t.Error("unexpected JA3 hash; expected:", Chrome83Hash, "| got:", ja3Response.JA3Hash)
}
}
func TestCClient_HTTP2(t *testing.T) {
resp, err := client.Get("https://www.google.com")
if err != nil {
t.Fatal(err)
}
_, err = readAndClose(resp.Body)
if err != nil {
t.Fatal(err)
}
if resp.ProtoMajor != 2 || resp.ProtoMinor != 0 {
t.Error("unexpected response proto; expected: HTTP/2.0 | got: ", resp.Proto)
}
}