-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathMakefile
335 lines (254 loc) · 8.84 KB
/
Makefile
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
default: run
force:
build:
go build
clean: force
rm -rf out
test:
go run ./testing/run-tests --exclude '*ipv6*' '*sudo*'
run: clean
httptap bash
install:
go install
webui-sleep-forever: install
httptap --webui :5000 -- sleep infinity
webui-curl-loop: install
httptap --webui :5000 -- bash -c "while true; do echo "curling..."; curl -s https://www.example.com > out; sleep 1; done"
tcpdump-port-11223:
sudo tcpdump -i lo 'tcp port 11223'
# Setup tests
setup:
go install
# Test cases that run in CI
test-echo:
httptap -- echo "hello"
# Output:
# hello
# Test that the user and group doesn't change inside httptap
test-uid:
id -u > expected
httptap -- bash -c "id -u > actual"
diff actual expected
test-gid:
id -g > expected
httptap -- bash -c "id -g > actual"
diff actual expected
test-root:
httptap --user root -- id -u
# Output:
# 0
test-curl:
httptap -- bash -c "curl -s https://example.com > out"
# Output:
# ---> GET https://example.com/
# <--- 200 https://example.com/ (1256 bytes)
test-curl-http:
httptap -- bash -c "curl -s http://example.com > out"
# Output:
# ---> GET http://example.com/
# <--- 200 http://example.com/ (1256 bytes)
test-curl-monasticacademy-http:
httptap -- curl -Lso /dev/null http://monasticacademy.org
# Output:
# ---> GET http://monasticacademy.org/
# <--- 308 http://monasticacademy.org/ (14 bytes)
# ---> GET https://monasticacademy.org/
# <--- 308 https://monasticacademy.org/ (15 bytes)
# ---> GET https://www.monasticacademy.org/
# <--- 200 https://www.monasticacademy.org/ (31955 bytes)
test-curl-pre-resolved-https:
httptap -- bash -c "curl -s --resolve example.com:443:$(shell dig +short example.com | head -n 1) https://example.com > out"
# Output:
# ---> GET https://example.com/
# <--- 200 https://example.com/ (1256 bytes)
test-curl-pre-resolved-http:
httptap -- bash -c "curl -s --resolve example.com:80:$(shell dig +short example.com | head -n 1) http://example.com > out"
# Output:
# ---> GET http://example.com/
# <--- 200 http://example.com/ (1256 bytes)
# try curling ipv6.google.com, which has an ipv6 address only
manual-test-curl-ipv6:
./testing/httptap_test curl -sL https://ipv6.google.com
# ---> GET https://ipv6.google.com/
# <--- 200 https://ipv6.google.com/ (18791 bytes)
test-netcat:
httptap -- \
bash -c "printf 'GET / HTTP/1.1\r\nHOST: example.com\r\nUser-Agent: nc\r\n\r\n' \
| nc example.com 80 \
> out"
grep -A 1000000 "<!doctype html>" out | diff - testing/expected/example.com
# Output:
# ---> GET http://example.com/
# <--- 200 http://example.com/ (1256 bytes)
test-netcat-pre-resolved:
httptap -- \
bash -c "printf 'GET / HTTP/1.1\r\nHOST: example.com\r\nUser-Agent: nc\r\n\r\n' \
| nc $(shell dig +short example.com | head -n 1) 80 \
> out"
grep -A 1000000 "<!doctype html>" out | diff - testing/expected/example.com
# Output:
# ---> GET http://example.com/
# <--- 200 http://example.com/ (1256 bytes)
test-wget:
./testing/httptap_test wget -qO - https://example.com
# Output:
# ---> GET https://example.com/
# <--- 200 https://example.com/ (1256 bytes)
test-udp-11223:
httptap -- bash -c "echo 'hello udp' | socat udp4:1.2.3.4:11223 - "
test-udp-11223-two-udp-packets:
httptap -- bash -c "echo 'hello udp' | socat udp4:1.2.3.4:11223 - ; echo 'hello again udp' | socat udp4:1.2.3.4:11223 - "
flaky-test-socat-dns:
httptap -- bash -c "echo cfc9 0100 0001 0000 0000 0000 0a64 7563 6b64 7563 6b67 6f03 636f 6d00 0001 0001 | xxd -p -r | socat udp4:1.1.1.1:53 - | xxd"
# Output:
# 00000000: cfc9 8100 0001 0001 0000 0000 0a64 7563 .............duc
# 00000010: 6b64 7563 6b67 6f03 636f 6d00 0001 0001 kduckgo.com.....
# 00000020: 0a64 7563 6b64 7563 6b67 6f03 636f 6d00 .duckduckgo.com.
# 00000030: 0001 0001 0000 0e10 0004 3495 f627 ..........4.*.'
test-dig:
./testing/httptap_test dig +short -t a monasticacademy.org
test-dig-cloudflare:
./testing/httptap_test dig +short -t a monasticacademy.org @1.1.1.1
disabled-test-http3:
./testing/httptap_test go run ./testing/http3get https://www.google.com
test-nslookup:
nslookup google.com | grep -A 10000 answer | grep Address | sort > expected
httptap -- bash -c "nslookup google.com | grep -A 10000 answer | grep Address | sort > actual"
diff actual expected
# should not generate extraneous error messages
test-nonexistent-domain:
./testing/httptap_test curl -qs https://nonexistent.monasticacademy.org
# Output:
# httptap exited with code 6
test-python:
httptap -- python -c 'import requests; requests.get("https://monasticacademy.org")'
# Output:
# ---> GET https://monasticacademy.org/
# <--- 308 https://monasticacademy.org/ (15 bytes)
# ---> GET https://www.monasticacademy.org/
# <--- 200 https://www.monasticacademy.org/ (31955 bytes)
test-java:
javac testing/java/Example.java
httptap -- java -cp testing/java Example 2>&1 | grep -v JAVA_OPTIONS
# Output:
# ---> GET https://example.com/
# <--- 200 https://example.com/ (1256 bytes)
test-go:
./testing/httptap_test go run ./testing/httpget
# Output:
# ---> GET https://monasticacademy.com/
# <--- 308 https://monasticacademy.com/ (15 bytes)
# ---> GET https://www.monasticacademy.org/
# <--- 200 https://www.monasticacademy.org/ (31955 bytes)
test-doh:
./testing/httptap_test curl -s --doh-url https://cloudflare-dns.com/dns-query https://www.example.com
# Output:
# ---> POST https://cloudflare-dns.com/dns-query
# <--- 200 https://cloudflare-dns.com/dns-query (143 bytes)
# ---> POST https://cloudflare-dns.com/dns-query
# <--- 200 https://cloudflare-dns.com/dns-query (167 bytes)
# ---> GET https://www.example.com/
# <--- 200 https://www.example.com/ (1256 bytes)
test-node:
./testing/httptap_test node testing/js/get.js
# Output:
# ---> GET https://www.example.com/
# <--- 200 https://www.example.com/ (1256 bytes)
test-deno:
./testing/httptap_test deno --allow-net testing/ts/get.ts
# Output:
# ---> GET https://example.com/
# <--- 200 https://example.com/ (1256 bytes)
not-working-test-bun:
./testing/httptap_test bun testing/ts/get.ts
# Output:
# ---> GET https://example.com/
# <--- 200 https://example.com/ (1256 bytes)
# Test running httptap inside itself
not-working-test-self:
httptap -- httptap curl https://www.example.com
# Test HAR output
test-har:
httptap --dump-har out.har -- curl -Lso /dev/null https://monasticacademy.org
jq '.log.entries[] | del(.response.content.text, .request.headers, .response.headers, .timings, .time, .startedDateTime)' out.har > filtered.har
diff filtered.har testing/expected/monasticacademy.org.har
# Output:
# ---> GET https://monasticacademy.org/
# <--- 308 https://monasticacademy.org/ (15 bytes)
# ---> GET https://www.monasticacademy.org/
# <--- 200 https://www.monasticacademy.org/ (31955 bytes)
# These tests require things that I do not want to install into github actions
manual-test-gcloud:
./testing/httptap_test gcloud compute instances list
manual-test-wine-battle-net:
go run . -- wine ~/Downloads/Battle.net-Setup.exe
# Test running inside sudo
test-sudo:
go build -o /tmp/httptap
sudo /tmp/httptap echo "hello"
# Output:
# hello
test-sudo-no-new-user-namespace:
go build -o /tmp/httptap
sudo /tmp/httptap --no-new-user-namespace -- curl -so out https://www.example.com
# Output:
# ---> GET https://www.example.com/
# <--- 200 https://www.example.com/ (1256 bytes)
manual-test-sudo-udp:
go build -o /tmp/httptap
go build -o /tmp/udpsend ./testing/udpsend
sudo /tmp/httptap /tmp/udpsend httptap 1.2.3.4:11223
test-sudo-setcap-echo:
go build -o /tmp/httptap
sudo setcap 'cap_net_admin=ep cap_sys_admin=ep cap_dac_override=ep' /tmp/httptap
/tmp/httptap --no-new-user-namespace -- echo "hello"
# Output:
# hello
test-sudo-setcap-curl:
go build -o /tmp/httptap
sudo setcap 'cap_net_admin=ep cap_sys_admin=ep cap_dac_override=ep' /tmp/httptap
/tmp/httptap --no-new-user-namespace -- curl -so out https://www.example.com
# Output:
# ---> GET https://www.example.com/
# <--- 200 https://www.example.com/ (1256 bytes)
# Docker-based tests
manual-test-dockerized-ubuntu:
mkdir -p .build
go build -o .build/httptap
docker run \
--interactive \
--tty \
--rm \
--volume .:/src \
--workdir /src \
--cap-add SYS_ADMIN \
--device /dev/net/tun:/dev/net/tun \
ubuntu \
.build/httptap --no-overlay -- curl -so out https://www.example.com
manual-test-dockerized-alpine:
mkdir -p .build
CGO_ENABLED=0 go build -o .build/httptap
docker run \
--interactive \
--tty \
--rm \
--volume .:/src \
--workdir /src \
--cap-add SYS_ADMIN \
--device /dev/net/tun:/dev/net/tun \
alpine/curl \
.build/httptap --no-overlay -- curl -so out https://www.example.com
manual-test-dockerized-distroless:
mkdir -p .build
CGO_ENABLED=0 go build -o .build/httptap
CGO_ENABLED=0 go build -o .build/hi ./testing/hello
docker run \
--interactive \
--tty \
--rm \
--volume .:/src \
--workdir /src \
--cap-add SYS_ADMIN \
--device /dev/net/tun:/dev/net/tun \
gcr.io/distroless/static-debian12 \
.build/httptap --no-overlay -- .build/hi