Skip to content

Commit

Permalink
tests: cache http responses
Browse files Browse the repository at this point in the history
  • Loading branch information
lilydjwg committed Feb 10, 2025
1 parent fa9ca38 commit d67d765
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
31 changes: 30 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,34 @@ jobs:
env:
KEY: ${{ secrets.KEY }}
run: if [[ -n $KEY ]]; then openssl enc -d -aes-256-ctr -pbkdf2 -k $KEY -in keyfile.toml.enc -out keyfile.toml; fi

- name: Setup mitmproxy cache
uses: actions/cache@v4
env:
cache-name: cache-mitm
with:
path: ~/.mitmproxy
key: ${{ env.cache-name }}
restore-keys: |
${{ env.cache-name }}
- name: Install mitmproxy
run: |
sudo apt update
/usr/bin/pip install -U mitmproxy
# https://github.com/DevToys-app/DevToys/issues/1373#issuecomment-2599820594
sudo sysctl -w kernel.apparmor_restrict_unprivileged_unconfined=0
sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
# - name: Setup upterm session
# uses: lhotari/action-upterm@v1
- name: Run pytest
run: if [[ -f keyfile.toml ]]; then KEYFILE=keyfile.toml pytest; else pytest; fi
run: scripts/run_cached_tests

- name: save mitmproxy cache
if: always()
uses: actions/cache/save@v4
env:
cache-name: cache-mitm
with:
path: ~/.mitmproxy
key: ${{ env.cache-name }}
32 changes: 32 additions & 0 deletions scripts/run_cached_tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash -e

if [[ -f ~/.mitmproxy/nvdump ]]; then
mitmdump -S ~/.mitmproxy/nvdump -p 7890 --ignore-hosts '127\.0\.0\.1' --server-replay-reuse --server-replay-extra=forward -w newdump >/dev/null &
else
mitmdump -w ~/.mitmproxy/nvdump -p 7890 --ignore-hosts '127\.0\.0\.1' >/dev/null &
fi

mitm_pid=$!

if [[ -f keyfile.toml ]]; then
export KEYFILE=keyfile.toml
fi

for _ in {1..10}; do
if [[ -s ~/.mitmproxy/mitmproxy-ca-cert.pem ]]; then
break
fi
sleep 1
done

export SSL_CERT_FILE=$HOME/.mitmproxy/mitmproxy-ca-cert.pem
export GIT_SSL_CAINFO=$SSL_CERT_FILE
export http_proxy=http://localhost:7890 https_proxy=http://localhost:7890

pytest

kill -INT $mitm_pid

if [[ -s newdump ]]; then
cat newdump >> ~/.mitmproxy/nvdump
fi

0 comments on commit d67d765

Please sign in to comment.