add udp source port test
This commit is contained in:
parent
a2edd6a46d
commit
1a62694a3b
4 changed files with 58 additions and 2 deletions
|
@ -13,7 +13,7 @@ before_install:
|
||||||
- sudo dd if=/dev/urandom of=/usr/share/nginx/www/file bs=1M count=10
|
- 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 sh -c "echo '127.0.0.1 localhost' > /etc/hosts"
|
||||||
- sudo service nginx restart
|
- sudo service nginx restart
|
||||||
- pip install pep8 pyflakes nose coverage
|
- pip install pep8 pyflakes nose coverage PySocks
|
||||||
- sudo tests/socksify/install.sh
|
- sudo tests/socksify/install.sh
|
||||||
- sudo tests/libsodium/install.sh
|
- sudo tests/libsodium/install.sh
|
||||||
- sudo tests/setup_tc.sh
|
- sudo tests/setup_tc.sh
|
||||||
|
|
|
@ -24,6 +24,8 @@ function run_test {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pip install PySocks
|
||||||
|
|
||||||
python --version
|
python --version
|
||||||
coverage erase
|
coverage erase
|
||||||
mkdir tmp
|
mkdir tmp
|
||||||
|
@ -69,7 +71,7 @@ if [ -f /proc/sys/net/ipv4/tcp_fastopen ] ; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
run_test tests/test_large_file.sh
|
run_test tests/test_large_file.sh
|
||||||
|
run_test tests/test_udp_src.sh
|
||||||
run_test tests/test_command.sh
|
run_test tests/test_command.sh
|
||||||
|
|
||||||
coverage combine && coverage report --include=shadowsocks/*
|
coverage combine && coverage report --include=shadowsocks/*
|
||||||
|
|
31
tests/test_udp_src.py
Normal file
31
tests/test_udp_src.py
Normal file
|
@ -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
tests/test_udp_src.sh
Executable file
23
tests/test_udp_src.sh
Executable file
|
@ -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
|
Loading…
Reference in a new issue