Skip to content

Commit

Permalink
add udp source port test
Browse files Browse the repository at this point in the history
  • Loading branch information
clowwindy committed Jul 10, 2015
1 parent a2edd6a commit 1a62694
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ before_install:
- sudo dd if=/dev/urandom of=/usr/share/nginx/www/file bs=1M count=10
- sudo sh -c "echo '127.0.0.1 localhost' > /etc/hosts"
- sudo service nginx restart
- pip install pep8 pyflakes nose coverage
- pip install pep8 pyflakes nose coverage PySocks
- sudo tests/socksify/install.sh
- sudo tests/libsodium/install.sh
- sudo tests/setup_tc.sh
Expand Down
4 changes: 3 additions & 1 deletion tests/jenkins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ function run_test {
return 0
}

pip install PySocks

python --version
coverage erase
mkdir tmp
Expand Down Expand Up @@ -69,7 +71,7 @@ if [ -f /proc/sys/net/ipv4/tcp_fastopen ] ; then
fi

run_test tests/test_large_file.sh

run_test tests/test_udp_src.sh
run_test tests/test_command.sh

coverage combine && coverage report --include=shadowsocks/*
Expand Down
31 changes: 31 additions & 0 deletions tests/test_udp_src.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/python

import socket
import socks

if __name__ == '__main__':
sock_out = socks.socksocket(socket.AF_INET, socket.SOCK_DGRAM,
socket.SOL_UDP)
sock_out.set_proxy(socks.SOCKS5, '127.0.0.1', 1081)
sock_out.bind(('127.0.0.1', 9000))

sock_in1 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
socket.SOL_UDP)
sock_in2 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
socket.SOL_UDP)

sock_in1.bind(('127.0.0.1', 9001))
sock_in2.bind(('127.0.0.1', 9002))

sock_out.sendto('data', ('127.0.0.1', 9001))
result1 = sock_in1.recvfrom(8)

sock_out.sendto('data', ('127.0.0.1', 9002))
result2 = sock_in2.recvfrom(8)

sock_out.close()
sock_in1.close()
sock_in2.close()

# make sure they're from the same source port
assert result1 == result2
23 changes: 23 additions & 0 deletions tests/test_udp_src.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

PYTHON="coverage run -p -a"

mkdir -p tmp

$PYTHON shadowsocks/local.py -c tests/aes.json &
LOCAL=$!

$PYTHON shadowsocks/server.py -c tests/aes.json --forbidden-ip "" &
SERVER=$!

sleep 3

python tests/test_udp_src.py
r=$?

kill -s SIGINT $LOCAL
kill -s SIGINT $SERVER

sleep 2

exit $r

0 comments on commit 1a62694

Please sign in to comment.