Skip to content

Commit

Permalink
Use direct download of proxy to fix Travis (#473)
Browse files Browse the repository at this point in the history
Co-authored-by: jrfnl <[email protected]>
  • Loading branch information
schlessera and jrfnl authored Apr 26, 2021
1 parent 5fdcc83 commit 83cd17f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ install:
- phpenv local --unset

# Setup the proxy
- pip install --user mitmproxy==0.18.2
- wget -O /tmp/mitmproxy-0.18.2-linux.tar.gz https://snapshots.mitmproxy.org/0.18.2/mitmproxy-0.18.2-linux.tar.gz
- tar -xzf /tmp/mitmproxy-0.18.2-linux.tar.gz --directory /tmp

before_script:
- PHPBIN=$TESTPHPBIN PORT=8080 vendor/bin/start.sh
- export REQUESTS_TEST_HOST_HTTP="localhost:8080"

- PROXYBIN="$HOME/.local/bin/mitmdump" PORT=9002 tests/utils/proxy/start.sh
- PROXYBIN="$HOME/.local/bin/mitmdump" PORT=9003 AUTH="test:pass" tests/utils/proxy/start.sh
- PROXYBIN="/tmp/mitmdump" PORT=9002 tests/utils/proxy/start-travis.sh
- PROXYBIN="/tmp/mitmdump" PORT=9003 AUTH="test:pass" tests/utils/proxy/start-travis.sh
- export REQUESTS_HTTP_PROXY="localhost:9002"
- export REQUESTS_HTTP_PROXY_AUTH="localhost:9003"
- export REQUESTS_HTTP_PROXY_AUTH_USER="test"
Expand All @@ -70,9 +71,9 @@ script:
- |
# PHPUnit 4.x does not yet support the `no-coverage` flag.
if [ ${TRAVIS_PHP_VERSION:0:3} == "5.2" ]; then
$PHPUNIT_BIN;
phpunit
else
$PHPUNIT_BIN --no-coverage;
phpunit --no-coverage
fi
after_script:
Expand Down
4 changes: 3 additions & 1 deletion tests/Proxy/HTTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ public function testConnectWithInvalidAuth($transport) {
'transport' => $transport,
);

if ($transport === 'Requests_Transport_fsockopen') {
if (version_compare(phpversion(), '5.5.0', '>=') === true
&& $transport === 'Requests_Transport_fsockopen'
) {
// @TODO fsockopen connection times out on invalid auth instead of returning 407.
if (method_exists($this, 'expectException')) {
$this->expectException('Requests_Exception');
Expand Down
19 changes: 19 additions & 0 deletions tests/utils/proxy/start-travis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

PROXYDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PORT=${PORT:-9000}

PROXYBIN=${PROXYBIN:-"$(which mitmdump)"}
ARGS="-s '$PROXYDIR/proxy.py' -p $PORT"
if [[ ! -z "$AUTH" ]]; then
ARGS="$ARGS --singleuser=$AUTH"
fi
PIDFILE="$PROXYDIR/proxy-$PORT.pid"

set -x

start-stop-daemon --verbose --start --background --pidfile $PIDFILE --make-pidfile --exec $PROXYBIN -- $ARGS

ps -p $(cat $PIDFILE) u
sleep 2
ps -p $(cat $PIDFILE) u
4 changes: 2 additions & 2 deletions tests/utils/proxy/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ set -x

start-stop-daemon --verbose --start --background --pidfile $PIDFILE --make-pidfile --exec $PROXYBIN -- $ARGS

ps -p $(cat $PIDFILE) -u
ps -p $(cat $PIDFILE) u
sleep 2
ps -p $(cat $PIDFILE) -u
ps -p $(cat $PIDFILE) u

0 comments on commit 83cd17f

Please sign in to comment.