From 70080c842fc448dbb24edda5dfcf15cac7c3bda0 Mon Sep 17 00:00:00 2001 From: klzgrad Date: Mon, 14 Jan 2019 23:45:52 -0500 Subject: [PATCH] Add tests Also clean up build file name. --- .appveyor.yml | 17 ++++++---- .travis.yml | 14 +++++--- tests/basic.sh | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 10 deletions(-) create mode 100755 tests/basic.sh diff --git a/.appveyor.yml b/.appveyor.yml index 3b4e2b1e62..9d8a443610 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,3 +1,6 @@ +branches: + except: + - dev version: '{build}' image: Visual Studio 2017 install: @@ -11,17 +14,19 @@ build_script: - bash -c '~/.cargo/bin/sccache -s' - bash -c 'cd src; ./build.sh' - bash -c '~/.cargo/bin/sccache -s' - - bash -c 'mkdir naive-$APPVEYOR_REPO_TAG_NAME-win64' - - bash -c 'cp src/out/Release/naive.exe src/config.json LICENSE naive-$APPVEYOR_REPO_TAG_NAME-win64/' - - bash -c '7z a naive-$APPVEYOR_REPO_TAG_NAME-win64.zip naive-$APPVEYOR_REPO_TAG_NAME-win64/' -test: off + - ps: $env:BUILD_NAME="naiveproxy-$env:APPVEYOR_REPO_TAG_NAME-win64" + - bash -c 'mkdir $BUILD_NAME' + - bash -c 'cp src/out/Release/naive.exe src/config.json LICENSE $BUILD_NAME' + - bash -c '7z a $BUILD_NAME.zip $BUILD_NAME' +test_script: + - bash -c './tests/basic.sh src/out/Release/naive' artifacts: - - path: naive-$(APPVEYOR_REPO_TAG_NAME)-win64.zip + - path: $(BUILD_NAME).zip deploy: - provider: GitHub auth_token: secure: h+qwIoof/3ET7LOldWwlb6XQLmpxYPuaZL4YcFQ8QyclfBrnywzwzDaSqdE2unPg - artifact: naive-$(APPVEYOR_REPO_TAG_NAME)-win64.zip + artifact: $(BUILD_NAME).zip prerelease: true force_update: true on: diff --git a/.travis.yml b/.travis.yml index 091fa1b9b9..cfad35ab1b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,6 @@ +branches: + except: + - dev language: cpp os: - linux @@ -21,14 +24,17 @@ script: - ( cd src; ./get-clang.sh ) - ccache -s - ( cd src; ./build.sh ) - - mkdir naiveproxy-$TRAVIS_BRANCH-$TRAVIS_OS_NAME - - cp src/out/Release/naive src/config.json LICENSE naiveproxy-$TRAVIS_BRANCH-$TRAVIS_OS_NAME/ - - tar cJf naiveproxy-$TRAVIS_BRANCH-$TRAVIS_OS_NAME.tar.xz naiveproxy-$TRAVIS_BRANCH-$TRAVIS_OS_NAME/ + - ccache -s + - ./tests/basic.sh src/out/Release/naive + - export BUILD_NAME="naiveproxy-$TRAVIS_BRANCH-$TRAVIS_OS_NAME" + - mkdir $BUILD_NAME + - cp src/out/Release/naive src/config.json LICENSE $BUILD_NAME + - tar cJf $BUILD_NAME.tar.xz $BUILD_NAME deploy: provider: releases api_key: secure: hZ+M3GvNpPPMri0u7HkeDM8qCNSzCP2kBxL/68XgF3uvMDkJRX5/gyq27EoQMHyRxni759LlwHttRn6nHSg/CwNgK4fD4WPZWU99XIWKdlI+P1AQkHThjNtABv3P7JOq1HxyuwrcaBPybnDjsQTFE6HG5zsIhXZlUTCHbndCBpYPuDnaqKJJUv4/WzoEjXAlBSkAsBGhEQv+HZhaupw5vSkDkulNgXZrXOoO6uzAtAiR5St38dV7cWXgk6UwoyrVaV8cO0cltveyEPkGYMXJh6YkopJjSVrkYlI8vWsA8CgwdhXwAkYoG1uaIDUdNdlrBXNuA0BOFcU3iEo3D9H/z1/WQUnCuAOVCkYC/QhkTCsioQ5vaNA56+3uY8KOSDNo8XxxBzRIUSwul2lwHCNl6+cf1EhO9brI3Q8q/ZPZLmNIqYDXAI29/MMC13g/ql8UUcy2TwGrx2OE73SIzVBm2hVYI6FFs2hjJzMkknV83K0kr515gXrI+p7ANqnA9vdRBx7zMdOT1etFeuD06wjbLGLmHTS4ykhDYl6wn26fJHm3/OkqNyWllghc8DZnpAHh5AAYrrTIQPlSgtyqGL2qCoCPHbb2WgWewSVhqY+p7JMPchAc6myW3H2c7yL+TDMdRcr9I7DDOpvvfMoGx527Lji54mxGdZmdEpSGxi9Rx3g= - file: naiveproxy-$TRAVIS_BRANCH-$TRAVIS_OS_NAME.tar.xz + file: $BUILD_NAME.tar.xz skip_cleanup: true name: $TRAVIS_BRANCH prerelease: true diff --git a/tests/basic.sh b/tests/basic.sh new file mode 100755 index 0000000000..950242b82d --- /dev/null +++ b/tests/basic.sh @@ -0,0 +1,90 @@ +#!/bin/sh + +[ "$1" ] || exit 1 +naive="$1" +set -ex + +test_proxy() { + curl -v --proxy "$1" https://www.google.com/humans.txt | grep '^Google is built' +} + +test_naive() { + test_name="$1" + proxy="$2" + echo "TEST '$test_name':" + shift 2 + if ( + trap 'kill $pid' EXIT + pid= + for arg in "$@"; do + $naive $arg & pid="$pid $!" + done + sleep 1 + test_proxy "$proxy" + ); then + echo "TEST '$test_name': PASS" + true + else + echo "TEST '$test_name': FAIL" + false + fi +} + +test_naive 'Default config' socks5h://127.0.0.1:1080 '--log' + +echo '{"listen":"socks://127.0.0.1:61080","log":""}' >config.json +test_naive 'Default config file' socks5h://127.0.0.1:61080 '' +rm -f config.json + +echo '{"listen":"socks://127.0.0.1:61080","log":""}' >/tmp/config.json +test_naive 'Config file' socks5h://127.0.0.1:61080 '/tmp/config.json' +rm -f /tmp/config.json + +test_naive 'Trivial - scheme only' socks5h://127.0.0.1:1080 \ + '--log --listen=socks://' + +test_naive 'Trivial - no host' socks5h://127.0.0.1:61080 \ + '--log --listen=socks://:61080' + +test_naive 'Trivial - no port' socks5h://127.0.0.1:1080 \ + '--log --listen=socks://127.0.0.1' + +test_naive 'SOCKS-SOCKS' socks5h://127.0.0.1:11080 \ + '--log --listen=socks://:11080 --proxy=socks://127.0.0.1:21080' \ + '--log --listen=socks://:21080' + +test_naive 'SOCKS-HTTP' socks5h://127.0.0.1:11080 \ + '--log --listen=socks://:11080 --proxy=http://127.0.0.1:28080' \ + '--log --listen=http://:28080' + +test_naive 'HTTP-HTTP' http://127.0.0.1:18080 \ + '--log --listen=http://:18080 --proxy=http://127.0.0.1:28080' \ + '--log --listen=http://:28080' + +test_naive 'HTTP-SOCKS' http://127.0.0.1:18080 \ + '--log --listen=http://:18080 --proxy=http://127.0.0.1:21080' \ + '--log --listen=http://:21080' + +test_naive 'SOCKS-HTTP padded' socks5h://127.0.0.1:11080 \ + '--log --listen=socks://:11080 --proxy=http://127.0.01:28080 --padding' \ + '--log --listen=http://:28080 --padding' + +test_naive 'SOCKS-SOCKS-SOCKS' socks5h://127.0.0.1:11080 \ + '--log --listen=socks://:11080 --proxy=socks://127.0.0.1:21080' \ + '--log --listen=socks://:21080 --proxy=socks://127.0.0.1:31080' \ + '--log --listen=socks://:31080' + +test_naive 'SOCKS-HTTP-SOCKS' socks5h://127.0.0.1:11080 \ + '--log --listen=socks://:11080 --proxy=socks://127.0.0.1:28080' \ + '--log --listen=socks://:28080 --proxy=socks://127.0.0.1:31080' \ + '--log --listen=socks://:31080' + +test_naive 'HTTP-SOCKS-HTTP' socks5h://127.0.0.1:18080 \ + '--log --listen=socks://:18080 --proxy=socks://127.0.0.1:21080' \ + '--log --listen=socks://:21080 --proxy=socks://127.0.0.1:38080' \ + '--log --listen=socks://:38080' + +test_naive 'HTTP-HTTP-HTTP' socks5h://127.0.0.1:18080 \ + '--log --listen=socks://:18080 --proxy=socks://127.0.0.1:28080' \ + '--log --listen=socks://:28080 --proxy=socks://127.0.0.1:38080' \ + '--log --listen=socks://:38080'