Skip to content

Commit f538657

Browse files
committed
Improve distributable tests: update start params & clarify log output
Previously the start params used the old Mockttp form, not the plugin-aware version, and didn't start the WebRTC plugin at all, so when it broke recently (1.10.2) the tests didn't detect it. We now include the WebRTC plugin, using near-identical params to the UI, and also expand the logging so that you can more clearly see what's going on and spot issues like this in the distributable test output in future.
1 parent 46230ba commit f538657

File tree

2 files changed

+54
-26
lines changed

2 files changed

+54
-26
lines changed

test/distributables-test/unix.sh

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,41 @@ ls -la *
66

77
tar -xvzf ./distributables/v*/httptoolkit-server-*-$1-x64.tar.gz
88

9-
echo "Starting server..."
9+
echo "\nStarting server..."
1010

1111
./httptoolkit-server/bin/httptoolkit-server start &
1212
SERVER_PID=$!
1313

1414
sleep 5
1515

16-
echo "Testing server..."
16+
echo "\nTesting server..."
1717

1818
# CSRF protection fully blocks unrecognized/missing origin requests:
19+
CURL_OPTIONS="--silent --fail -i"
1920
WITH_ORIGIN="-HOrigin: https://app.httptoolkit.tech"
2021
AS_JSON="-HContent-Type: application/json"
2122

22-
# Can start a Mockttp server:
23-
curl "$WITH_ORIGIN" "$AS_JSON" -v --fail 'http://127.0.0.1:45456/start?port=\{"startPort":8000,"endPort":65535\}' -d '{}'
23+
echo "\nCan start a Mockttp server"?
24+
# Uses the default config from the UI:
25+
curl $CURL_OPTIONS "$WITH_ORIGIN" "$AS_JSON" 'http://127.0.0.1:45456/start' \
26+
--data '{"plugins":{"http":{"options":{"cors":false,"suggestChanges":false,"http2":"fallback","https":{"tlsPassthrough":[]}}},"webrtc":{}}}'
2427

25-
# Can query the API server version:
26-
curl "$WITH_ORIGIN" "$AS_JSON" -v --fail http://127.0.0.1:45457/ -d '{"query": "query getVersion { version }"}'
28+
echo "\nCan query the API server version?"
29+
curl $CURL_OPTIONS "$WITH_ORIGIN" "$AS_JSON" http://127.0.0.1:45457/ \
30+
--data '{"query": "query getVersion { version }"}'
2731

28-
# Can get config
29-
curl "$WITH_ORIGIN" "$AS_JSON" -v --fail http://127.0.0.1:45457/ -d '{"query": "query getConfig { config { certificateContent certificatePath certificateFingerprint } }"}'
32+
echo "\nCan get config?"
33+
curl $CURL_OPTIONS "$WITH_ORIGIN" "$AS_JSON" http://127.0.0.1:45457/ \
34+
--data '{"query": "query getConfig { config { certificateContent certificatePath certificateFingerprint } }"}'
3035

31-
# Can query interceptors
32-
curl "$WITH_ORIGIN" "$AS_JSON" -v --fail http://127.0.0.1:45457/ -d '{"query": "query getInterceptors { interceptors { id version, metadata isActivable isActive(proxyPort: 8000) } }"}'
36+
echo "\nCan query interceptors?"
37+
curl $CURL_OPTIONS "$WITH_ORIGIN" "$AS_JSON" http://127.0.0.1:45457/ \
38+
--data '{"query": "query getInterceptors { interceptors { id version, metadata isActivable isActive(proxyPort: 8000) } }"}'
3339

34-
# Can trigger update (can't test that it actually updates, unfortunately)
35-
curl "$WITH_ORIGIN" "$AS_JSON" -v --fail http://127.0.0.1:45457/ -d '{"query": "mutation TriggerUpdate { triggerUpdate }"}'
40+
echo "\nCan trigger update?"
41+
# (can't test that it actually updates, unfortunately)
42+
curl $CURL_OPTIONS "$WITH_ORIGIN" "$AS_JSON" http://127.0.0.1:45457/ \
43+
--data '{"query": "mutation TriggerUpdate { triggerUpdate }"}'
3644

3745
# ^ This will fail if they receive anything but a 200 result.
3846
# This ensures that the server is startable, and has minimal functionality for launch.

test/distributables-test/windows.bat

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,53 @@ FOR /F "tokens=*" %%i IN (' %GET_TAR% ') DO SET TAR_PATH=%%i
77

88
tar -xvzf %TAR_PATH%
99

10+
echo:
11+
echo:
1012
echo Starting server...
1113

1214
START "server" /b .\httptoolkit-server\bin\httptoolkit-server start
1315

1416
REM The closest we can get to a 10 second delay on Windows in CI, ick:
1517
ping -n 10 127.0.0.1 >NUL
1618

19+
echo:
20+
echo:
1721
echo Testing server...
1822

23+
REM --silent (no progress), --fail on errors, --include headers in logs
24+
set CURL_OPTIONS="-sfi"
1925
REM CSRF protection fully blocks unrecognized/missing origin requests:
2026
set WITH_ORIGIN="-HOrigin: https://app.httptoolkit.tech"
2127
set AS_JSON="-HContent-Type: application/json"
2228

23-
REM Can start a Mockttp server:
24-
curl %WITH_ORIGIN% %AS_JSON% -v --fail -X POST "http://127.0.0.1:45456/start?port=\{\"startPort\":8000,\"endPort\":65535\}" || goto :error
25-
26-
REM Can query the API server version:
27-
curl %WITH_ORIGIN% %AS_JSON% -v --fail http://127.0.0.1:45457/ -d "{\"query\": \"query getVersion { version }\"}" || goto :error
28-
29-
REM Can get config
30-
curl %WITH_ORIGIN% %AS_JSON% -v --fail http://127.0.0.1:45457/ -d "{\"query\": \"query getConfig { config { certificateContent certificatePath certificateFingerprint } }\"}" || goto :error
31-
32-
REM Can query interceptors
33-
curl %WITH_ORIGIN% %AS_JSON% -v --fail http://127.0.0.1:45457/ -d "{\"query\": \"query getInterceptors { interceptors { id version, metadata isActivable isActive(proxyPort: 8000) } }\"}" || goto :error
34-
35-
REM Can trigger update (can't test that it actually updates, unfortunately)
36-
curl %WITH_ORIGIN% %AS_JSON% -v --fail http://127.0.0.1:45457/ -d "{\"query\": \"mutation TriggerUpdate { triggerUpdate }\"}" || goto :error
29+
echo:
30+
echo:
31+
echo Can start a Mockttp server?
32+
REM Uses the default config from the UI:
33+
curl %CURL_OPTIONS% %WITH_ORIGIN% %AS_JSON% -X POST "http://127.0.0.1:45456/start" ^
34+
--data "{\"plugins\":{\"http\":{\"options\":{\"cors\":false,\"suggestChanges\":false,\"http2\":\"fallback\",\"https\":{\"tlsPassthrough\":[]}}},\"webrtc\":{}}}" ^
35+
|| goto :error`
36+
37+
echo:
38+
echo:
39+
echo Can query the API server version?
40+
curl %CURL_OPTIONS% %WITH_ORIGIN% %AS_JSON% http://127.0.0.1:45457/ -d "{\"query\": \"query getVersion { version }\"}" || goto :error
41+
42+
echo:
43+
echo:
44+
echo Can get config?
45+
curl %CURL_OPTIONS% %WITH_ORIGIN% %AS_JSON% http://127.0.0.1:45457/ -d "{\"query\": \"query getConfig { config { certificateContent certificatePath certificateFingerprint } }\"}" || goto :error
46+
47+
echo:
48+
echo:
49+
echo Can query interceptors?
50+
curl %CURL_OPTIONS% %WITH_ORIGIN% %AS_JSON% http://127.0.0.1:45457/ -d "{\"query\": \"query getInterceptors { interceptors { id version, metadata isActivable isActive(proxyPort: 8000) } }\"}" || goto :error
51+
52+
echo:
53+
echo:
54+
echo Can trigger update?
55+
REM (can't test that it actually updates, unfortunately)
56+
curl %CURL_OPTIONS% %WITH_ORIGIN% %AS_JSON% http://127.0.0.1:45457/ -d "{\"query\": \"mutation TriggerUpdate { triggerUpdate }\"}" || goto :error
3757

3858
REM ^ This will fail if they receive anything but a 200 result.
3959
REM This ensures that the server is startable, and has minimal functionality for launch.

0 commit comments

Comments
 (0)