Skip to content

Commit 1a62694

Browse files
committed
add udp source port test
1 parent a2edd6a commit 1a62694

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ before_install:
1313
- sudo dd if=/dev/urandom of=/usr/share/nginx/www/file bs=1M count=10
1414
- sudo sh -c "echo '127.0.0.1 localhost' > /etc/hosts"
1515
- sudo service nginx restart
16-
- pip install pep8 pyflakes nose coverage
16+
- pip install pep8 pyflakes nose coverage PySocks
1717
- sudo tests/socksify/install.sh
1818
- sudo tests/libsodium/install.sh
1919
- sudo tests/setup_tc.sh

tests/jenkins.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ function run_test {
2424
return 0
2525
}
2626

27+
pip install PySocks
28+
2729
python --version
2830
coverage erase
2931
mkdir tmp
@@ -69,7 +71,7 @@ if [ -f /proc/sys/net/ipv4/tcp_fastopen ] ; then
6971
fi
7072

7173
run_test tests/test_large_file.sh
72-
74+
run_test tests/test_udp_src.sh
7375
run_test tests/test_command.sh
7476

7577
coverage combine && coverage report --include=shadowsocks/*

tests/test_udp_src.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/python
2+
3+
import socket
4+
import socks
5+
6+
if __name__ == '__main__':
7+
sock_out = socks.socksocket(socket.AF_INET, socket.SOCK_DGRAM,
8+
socket.SOL_UDP)
9+
sock_out.set_proxy(socks.SOCKS5, '127.0.0.1', 1081)
10+
sock_out.bind(('127.0.0.1', 9000))
11+
12+
sock_in1 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
13+
socket.SOL_UDP)
14+
sock_in2 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,
15+
socket.SOL_UDP)
16+
17+
sock_in1.bind(('127.0.0.1', 9001))
18+
sock_in2.bind(('127.0.0.1', 9002))
19+
20+
sock_out.sendto('data', ('127.0.0.1', 9001))
21+
result1 = sock_in1.recvfrom(8)
22+
23+
sock_out.sendto('data', ('127.0.0.1', 9002))
24+
result2 = sock_in2.recvfrom(8)
25+
26+
sock_out.close()
27+
sock_in1.close()
28+
sock_in2.close()
29+
30+
# make sure they're from the same source port
31+
assert result1 == result2

tests/test_udp_src.sh

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
PYTHON="coverage run -p -a"
4+
5+
mkdir -p tmp
6+
7+
$PYTHON shadowsocks/local.py -c tests/aes.json &
8+
LOCAL=$!
9+
10+
$PYTHON shadowsocks/server.py -c tests/aes.json --forbidden-ip "" &
11+
SERVER=$!
12+
13+
sleep 3
14+
15+
python tests/test_udp_src.py
16+
r=$?
17+
18+
kill -s SIGINT $LOCAL
19+
kill -s SIGINT $SERVER
20+
21+
sleep 2
22+
23+
exit $r

0 commit comments

Comments
 (0)