-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ECO-4787: Add interception proxy prototype
- start-interception-proxy adapted from https://github.com/ably/sdk-test-proxy at 82e93a7 Some TODOs which aren’t really important right now because this is just a prototype: - TODO fix type checking for interception proxy — `npm run build` does it properly, but tried to reproduce the way we do it for modulereport and it didn’t work - TODO fix linting for interception proxy — doesn’t seem to be catching lint errors - TODO linting / type checking etc for Python code Also: > Add test:playwright:open-browser script > > Lets you open a headed browser which is configured to use the > interception proxy. Useful for local debugging of browser tests.
- Loading branch information
1 parent
c4e9703
commit 66c568e
Showing
25 changed files
with
2,169 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Runs the server as a background service, exiting once the server is ready to receive requests. | ||
# | ||
# Intended for use in SDKs’ CI jobs. Must be run from the root of this repository. | ||
|
||
set -e | ||
|
||
# We run as the current user so that we can access the generated server certificate (in ~/.mitmproxy) without having to worry about permissions. TODO consider instead generating our own cert and telling mitmproxy to use it, then we also won’t have to have that step where we run mitmproxy once just to generate the certs | ||
start_systemd_service () { | ||
systemd_service=$(cat <<SYSTEMD_SERVICE | ||
[Unit] | ||
Description=Ably SDK Test Proxy | ||
[Service] | ||
WorkingDirectory=$(pwd) | ||
ExecStart=npm run test:proxy | ||
User=$USER | ||
[Install] | ||
WantedBy=multi-user.target | ||
SYSTEMD_SERVICE | ||
) | ||
|
||
# https://stackoverflow.com/questions/84882/sudo-echo-something-etc-privilegedfile-doesnt-work | ||
echo "${systemd_service}" | sudo tee /etc/systemd/system/ably-sdk-test-proxy.service 1>/dev/null | ||
|
||
echo "Starting ably-sdk-test-proxy systemd service..." 1>&2 | ||
sudo systemctl start ably-sdk-test-proxy.service | ||
echo "Started ably-sdk-test-proxy systemd service." 1>&2 | ||
} | ||
|
||
start_launchd_daemon () { | ||
launchd_daemon=$(cat <<LAUNCHD_DAEMON | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>Label</key> | ||
<string>com.ably.test.proxy</string> | ||
<key>WorkingDirectory</key> | ||
<string>$(pwd)</string> | ||
<key>ProgramArguments</key> | ||
<array> | ||
<string>npm</string> | ||
<string>run</string> | ||
<string>test:proxy</string> | ||
</array> | ||
<key>RunAtLoad</key> | ||
<true/> | ||
</dict> | ||
</plist> | ||
LAUNCHD_DAEMON | ||
) | ||
|
||
# https://stackoverflow.com/questions/84882/sudo-echo-something-etc-privilegedfile-doesnt-work | ||
echo "${launchd_daemon}" | sudo tee /Library/LaunchDaemons/com.ably.test.proxy.plist | ||
|
||
echo "Loading ably-sdk-test-proxy launchd daemon..." 1>&2 | ||
sudo launchctl load /Library/LaunchDaemons/com.ably.test.proxy.plist | ||
echo "Loaded ably-sdk-test-proxy launchd daemon." 1>&2 | ||
} | ||
|
||
check_daemon_still_running () { | ||
if uname | grep Linux 1>/dev/null | ||
then | ||
systemctl is-active --quiet ably-sdk-test-proxy.service | ||
elif uname | grep Darwin 1>/dev/null | ||
then | ||
launchctl print system/com.ably.test.proxy 1>/dev/null | ||
fi | ||
} | ||
|
||
if uname | grep Linux 1>/dev/null | ||
then | ||
start_systemd_service | ||
elif uname | grep Darwin 1>/dev/null | ||
then | ||
start_launchd_daemon | ||
else | ||
echo "Unsupported system $(uname); exiting" 1>&2 | ||
exit 1 | ||
fi | ||
|
||
echo "Waiting for sdk-test-proxy server to start on port 8001..." 1>&2 | ||
|
||
# https://stackoverflow.com/questions/27599839/how-to-wait-for-an-open-port-with-netcat | ||
while ! nc -z localhost 8001; do | ||
# Check that the service hasn’t failed (else we’ll be waiting forever) | ||
check_daemon_still_running | ||
sleep 0.5 | ||
done | ||
|
||
echo "sdk-test-proxy server is now listening on port 8001." 1>&2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.