Browse Source

add udp source port test

master
clowwindy 5 years ago
parent
commit
1a62694a3b
4 changed files with 58 additions and 2 deletions
  1. 1
    1
      .travis.yml
  2. 3
    1
      tests/jenkins.sh
  3. 31
    0
      tests/test_udp_src.py
  4. 23
    0
      tests/test_udp_src.sh

+ 1
- 1
.travis.yml View File

@@ -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

+ 3
- 1
tests/jenkins.sh View File

@@ -24,6 +24,8 @@ function run_test {
return 0
}

pip install PySocks

python --version
coverage erase
mkdir tmp
@@ -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/*

+ 31
- 0
tests/test_udp_src.py View 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
- 0
tests/test_udp_src.sh View 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…
Cancel
Save