-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration_test.go
More file actions
197 lines (167 loc) · 4.56 KB
/
integration_test.go
File metadata and controls
197 lines (167 loc) · 4.56 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
//go:build integration
package http_test
import (
"encoding/json"
"io"
"strings"
"testing"
http "github.com/aarock1234/fphttp"
)
type peetResponse struct {
TLS struct {
JA3Hash string `json:"ja3_hash"`
JA4 string `json:"ja4"`
PeetPrintHash string `json:"peetprint_hash"`
} `json:"tls"`
HTTP2 struct {
AkamaiHash string `json:"akamai_fingerprint_hash"`
SentFrames []struct {
FrameType string `json:"frame_type"`
} `json:"sent_frames"`
} `json:"http2"`
}
func TestIntegration_ChromeFingerprint(t *testing.T) {
client := &http.Client{
Transport: &http.Transport{
Fingerprint: http.Chrome(),
},
}
req, err := http.NewRequest("GET", "https://tls.peet.ws/api/all", nil)
if err != nil {
t.Fatalf("NewRequest() error: %v", err)
}
resp, err := client.Do(req)
if err != nil {
t.Fatalf("Do() error: %v", err)
}
defer func() { _ = resp.Body.Close() }()
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("ReadAll() error: %v", err)
}
var pr peetResponse
if err := json.Unmarshal(body, &pr); err != nil {
t.Fatalf("Unmarshal() error: %v", err)
}
t.Logf("ja3_hash: %s", pr.TLS.JA3Hash)
t.Logf("ja4: %s", pr.TLS.JA4)
t.Logf("peetprint_hash: %s", pr.TLS.PeetPrintHash)
t.Logf("akamai_fingerprint_hash: %s", pr.HTTP2.AkamaiHash)
if pr.TLS.JA3Hash == "" {
t.Errorf("tls.ja3_hash is empty")
}
if pr.TLS.JA4 == "" {
t.Errorf("tls.ja4 is empty")
}
if pr.HTTP2.AkamaiHash == "" {
t.Errorf("http2.akamai_fingerprint_hash is empty")
}
var hasSettings, hasWindowUpdate bool
for _, f := range pr.HTTP2.SentFrames {
switch f.FrameType {
case "SETTINGS":
hasSettings = true
case "WINDOW_UPDATE":
hasWindowUpdate = true
}
}
if !hasSettings {
t.Errorf("expected SETTINGS frame in sent_frames")
}
if !hasWindowUpdate {
t.Errorf("expected WINDOW_UPDATE frame in sent_frames")
}
}
func TestIntegration_FirefoxFingerprint(t *testing.T) {
client := &http.Client{
Transport: &http.Transport{
Fingerprint: http.Firefox(),
},
}
req, err := http.NewRequest("GET", "https://tls.peet.ws/api/all", nil)
if err != nil {
t.Fatalf("NewRequest() error: %v", err)
}
resp, err := client.Do(req)
if err != nil {
t.Fatalf("Do() error: %v", err)
}
defer func() { _ = resp.Body.Close() }()
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("ReadAll() error: %v", err)
}
var pr peetResponse
if err := json.Unmarshal(body, &pr); err != nil {
t.Fatalf("Unmarshal() error: %v", err)
}
t.Logf("ja3_hash: %s", pr.TLS.JA3Hash)
t.Logf("ja4: %s", pr.TLS.JA4)
t.Logf("peetprint_hash: %s", pr.TLS.PeetPrintHash)
t.Logf("akamai_fingerprint_hash: %s", pr.HTTP2.AkamaiHash)
if pr.TLS.JA3Hash == "" {
t.Errorf("tls.ja3_hash is empty")
}
if pr.TLS.JA4 == "" {
t.Errorf("tls.ja4 is empty")
}
if pr.HTTP2.AkamaiHash == "" {
t.Errorf("http2.akamai_fingerprint_hash is empty")
}
var hasSettings, hasWindowUpdate, hasPriority bool
for _, f := range pr.HTTP2.SentFrames {
switch f.FrameType {
case "SETTINGS":
hasSettings = true
case "WINDOW_UPDATE":
hasWindowUpdate = true
case "PRIORITY":
hasPriority = true
}
}
if !hasSettings {
t.Errorf("expected SETTINGS frame in sent_frames")
}
if !hasWindowUpdate {
t.Errorf("expected WINDOW_UPDATE frame in sent_frames")
}
if !hasPriority {
t.Errorf("expected PRIORITY frame in sent_frames (Firefox sends InitPriorityFrames)")
}
}
func TestIntegration_NilFingerprint(t *testing.T) {
client := &http.Client{
Transport: &http.Transport{},
}
req, err := http.NewRequest("GET", "https://tls.peet.ws/api/all", nil)
if err != nil {
t.Fatalf("NewRequest() error: %v", err)
}
resp, err := client.Do(req)
if err != nil {
t.Fatalf("Do() error: %v", err)
}
defer func() { _ = resp.Body.Close() }()
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("ReadAll() error: %v", err)
}
var pr peetResponse
if err := json.Unmarshal(body, &pr); err != nil {
t.Fatalf("Unmarshal() error: %v", err)
}
t.Logf("ja3_hash: %s", pr.TLS.JA3Hash)
t.Logf("ja4: %s", pr.TLS.JA4)
t.Logf("peetprint_hash: %s", pr.TLS.PeetPrintHash)
t.Logf("akamai_fingerprint_hash: %s", pr.HTTP2.AkamaiHash)
if pr.TLS.JA3Hash == "" {
t.Errorf("tls.ja3_hash is empty")
}
if pr.TLS.JA4 == "" {
t.Errorf("tls.ja4 is empty")
}
// Verify the response body was valid JSON with actual content.
if !strings.Contains(string(body), "ja3_hash") {
t.Errorf("response body does not contain expected fingerprint data")
}
}