Skip to content

Commit

Permalink
Add test for compatibility with shadowsocks-nodejs.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyfdecyf committed May 26, 2013
1 parent 23e5771 commit 5407a8d
Showing 1 changed file with 45 additions and 25 deletions.
70 changes: 45 additions & 25 deletions script/test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

OPTION="-p 8389 -k foobar -d"
OPTION="-p 8389 -k foobar"
LOCAL_PORT="1090"
SOCKS="127.0.0.1:$LOCAL_PORT"

Expand All @@ -14,25 +14,21 @@ test_get() {
code="200"
fi

# get 5 times
for i in {1..2}; do
# -s silent to disable progress meter, but enable --show-error
# -i to include http header
# -L to follow redirect so we should always get HTTP 200
cont=`curl --socks5 $SOCKS -s --show-error -i -L $url 2>&1`
ok=`echo $cont | grep -E -o "HTTP/1\.1 +$code"`
html=`echo $cont | grep -E -o -i "$target"`
if [[ -z $ok || -z $html ]] ; then
echo "=============================="
echo "GET $url FAILED!!!"
echo "$ok"
echo "$html"
echo $cont
echo "=============================="
return 1
fi
sleep 0.3
done
# -s silent to disable progress meter, but enable --show-error
# -i to include http header
# -L to follow redirect so we should always get HTTP 200
cont=`curl --socks5 $SOCKS -s --show-error -i -L $url 2>&1`
ok=`echo $cont | grep -E -o "HTTP/1\.1 +$code"`
html=`echo $cont | grep -E -o -i "$target"`
if [[ -z $ok || -z $html ]] ; then
echo "=============================="
echo "GET $url FAILED!!!"
echo "$ok"
echo "$html"
echo $cont
echo "=============================="
return 1
fi
return 0
}

Expand All @@ -44,21 +40,22 @@ test_shadowsocks() {
url=$1
method=$2

shadowsocks-server $OPTION -m "$method" &
$SERVER $OPTION -m "$method" &
server_pid=$!
shadowsocks-local $OPTION -s 127.0.0.1 -l $LOCAL_PORT -m "$method" &
$LOCAL $OPTION -s 127.0.0.1 -l $LOCAL_PORT -m "$method" &
local_pid=$!

# wait server and client finish startup
sleep 1

# get 5 times
for i in {1..5}; do
for i in {1..2}; do
if ! test_get $url "<html"; then
kill -SIGTERM $server_pid
kill -SIGTERM $local_pid
return 1
fi
sleep 0.3
done
echo "=============================="
echo "GET $url $method passed"
Expand All @@ -68,6 +65,29 @@ test_shadowsocks() {
sleep 1
}

test_shadowsocks baidu.com
test_shadowsocks baidu.com rc4
test_server_local_pair() {
echo "============================================================"
echo "server: $SERVER, local: $LOCAL"
echo "============================================================"
test_shadowsocks baidu.com table
test_shadowsocks baidu.com rc4
}

SERVER="shadowsocks-server"
LOCAL="shadowsocks-local"
test_server_local_pair

if [ -n $SS_NODEJS ]; then
pushd $SS_NODEJS

SERVER="node server.js"
LOCAL="shadowsocks-local"
test_server_local_pair

SERVER="shadowsocks-server"
LOCAL="node local.js"
test_server_local_pair

popd $SS_NODEJS
fi

0 comments on commit 5407a8d

Please sign in to comment.