Browse Source

add test

1.4
clowwindy 12 years ago
parent
commit
ae711d2b2c
  1. 12
      .travis.yml
  2. 56
      test.py

12
.travis.yml

@ -0,0 +1,12 @@
language: python
python:
- "2.6"
- "2.7"
before_install:
- pip install gevent
script:
- python test.py
branches:
only:
- master
- dev

56
test_encrypt.py → test.py

@ -1,4 +1,12 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import select
import struct
import hashlib
import string
from subprocess import Popen, PIPE
target1 = [ target1 = [
[60, 53, 84, 138, 217, 94, 88, 23, 39, 242, 219, 35, 12, 157, 165, 181, 255, 143, 83, 247, 162, 16, 31, 209, 190, [60, 53, 84, 138, 217, 94, 88, 23, 39, 242, 219, 35, 12, 157, 165, 181, 255, 143, 83, 247, 162, 16, 31, 209, 190,
@ -48,9 +56,6 @@ target2 = [
230, 133, 215, 41, 184, 22, 104, 254, 234, 253, 187, 226, 247, 188, 156, 151, 40, 108, 51, 83, 178, 52, 3, 31, 255, 230, 133, 215, 41, 184, 22, 104, 254, 234, 253, 187, 226, 247, 188, 156, 151, 40, 108, 51, 83, 178, 52, 3, 31, 255,
195, 53, 235, 126, 167, 120]] 195, 53, 235, 126, 167, 120]]
import struct
import hashlib
import string
def get_table(key): def get_table(key):
m = hashlib.md5() m = hashlib.md5()
@ -75,4 +80,47 @@ decrypt_table = string.maketrans(encrypt_table, string.maketrans('', ''))
for i in range(0, 256): for i in range(0, 256):
assert(target2[0][i] == ord(encrypt_table[i])) assert(target2[0][i] == ord(encrypt_table[i]))
assert(target2[1][i] == ord(decrypt_table[i])) assert(target2[1][i] == ord(decrypt_table[i]))
print 'test passed' p1 = Popen(['python', 'server.py'], shell=False, bufsize=0, stdin=PIPE,
stdout=PIPE, stderr=PIPE, close_fds=True)
p2 = Popen(['python', 'local.py'], shell=False, bufsize=0, stdin=PIPE,
stdout=PIPE, stderr=PIPE, close_fds=True)
p3 = None
print 'encryption test passed'
try:
ready_count = 0
fdset = [p1.stdout, p2.stdout, p1.stderr, p2.stderr]
while True:
r, w, e = select.select(fdset, [], fdset)
if e:
break
for fd in r:
line = fd.readline()
sys.stdout.write(line)
if line.find('starting server at port') >= 0:
ready_count += 1
if ready_count == 2 and p3 is None:
p3 = Popen(['curl', 'http://www.google.com/', '-v', '-L',
'--socks5-hostname', '127.0.0.1:1080'], shell=False,
bufsize=0, stdin=PIPE, stdout=PIPE, stderr=PIPE,
close_fds=True)
fdset.append(p3.stdout)
fdset.append(p3.stderr)
finally:
for p in [p1, p2]:
try:
p.kill()
except OSError:
pass
if p3 is not None:
r = p3.wait()
if r == 0:
print 'test passed'
sys.exit(r)
sys.exit(-1)
Loading…
Cancel
Save