summaryrefslogtreecommitdiffhomepage
path: root/test/unit/applications
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit/applications')
-rw-r--r--test/unit/applications/lang/go.py32
-rw-r--r--test/unit/applications/lang/java.py26
-rw-r--r--test/unit/applications/lang/node.py12
-rw-r--r--test/unit/applications/tls.py22
-rw-r--r--test/unit/applications/websockets.py46
5 files changed, 100 insertions, 38 deletions
diff --git a/test/unit/applications/lang/go.py b/test/unit/applications/lang/go.py
index e4ab8ffa..15ac1cd9 100644
--- a/test/unit/applications/lang/go.py
+++ b/test/unit/applications/lang/go.py
@@ -4,12 +4,22 @@ from unit.applications.proto import TestApplicationProto
class TestApplicationGo(TestApplicationProto):
- def load(self, script, name='app'):
+ @classmethod
+ def setUpClass(cls, complete_check=True):
+ unit = super().setUpClass(complete_check=False)
- if not os.path.isdir(self.testdir + '/go'):
- os.mkdir(self.testdir + '/go')
+ # check go module
+
+ go_app = TestApplicationGo()
+ go_app.testdir = unit.testdir
+ if go_app.prepare_env('empty', 'app').returncode == 0:
+ cls.available['modules']['go'] = []
- go_app_path = self.current_dir + '/go/'
+ return unit if not complete_check else unit.complete()
+
+ def prepare_env(self, script, name):
+ if not os.path.exists(self.testdir + '/go'):
+ os.mkdir(self.testdir + '/go')
env = os.environ.copy()
env['GOPATH'] = self.pardir + '/go'
@@ -19,12 +29,18 @@ class TestApplicationGo(TestApplicationProto):
'build',
'-o',
self.testdir + '/go/' + name,
- go_app_path + script + '/' + name + '.go',
+ self.current_dir + '/go/' + script + '/' + name + '.go',
],
env=env,
)
+
process.communicate()
+ return process
+
+ def load(self, script, name='app'):
+ self.prepare_env(script, name)
+
self._load_conf(
{
"listeners": {"*:7080": {"pass": "applications/" + script}},
@@ -32,8 +48,10 @@ class TestApplicationGo(TestApplicationProto):
script: {
"type": "external",
"processes": {"spare": 0},
- "working_directory": go_app_path + script,
- "executable": self.testdir + '/go/' + name,
+ "working_directory": self.current_dir
+ + "/go/"
+ + script,
+ "executable": self.testdir + "/go/" + name,
}
},
}
diff --git a/test/unit/applications/lang/java.py b/test/unit/applications/lang/java.py
index ec1c95d9..40bf3662 100644
--- a/test/unit/applications/lang/java.py
+++ b/test/unit/applications/lang/java.py
@@ -1,4 +1,5 @@
import os
+import glob
import shutil
from subprocess import Popen
from unit.applications.proto import TestApplicationProto
@@ -6,11 +7,9 @@ from unit.applications.proto import TestApplicationProto
class TestApplicationJava(TestApplicationProto):
def load(self, script, name='app'):
-
app_path = self.testdir + '/java'
web_inf_path = app_path + '/WEB-INF/'
classes_path = web_inf_path + 'classes/'
-
script_path = self.current_dir + '/java/' + script + '/'
if not os.path.isdir(app_path):
@@ -19,39 +18,48 @@ class TestApplicationJava(TestApplicationProto):
src = []
for f in os.listdir(script_path):
+ file_path = script_path + f
+
if f.endswith('.java'):
- src.append(script_path + f)
+ src.append(file_path)
continue
if f.startswith('.') or f == 'Makefile':
continue
- if os.path.isdir(script_path + f):
+ if os.path.isdir(file_path):
if f == 'WEB-INF':
continue
- shutil.copytree(script_path + f, app_path + '/' + f)
+ shutil.copytree(file_path, app_path + '/' + f)
continue
if f == 'web.xml':
if not os.path.isdir(web_inf_path):
os.makedirs(web_inf_path)
- shutil.copy2(script_path + f, web_inf_path)
+ shutil.copy2(file_path, web_inf_path)
else:
- shutil.copy2(script_path + f, app_path)
+ shutil.copy2(file_path, app_path)
if src:
if not os.path.isdir(classes_path):
os.makedirs(classes_path)
- tomcat_jar = self.pardir + '/build/tomcat-servlet-api-9.0.13.jar'
+ classpath = self.pardir + '/build/tomcat-servlet-api-9.0.13.jar'
+
+ ws_jars = glob.glob(
+ self.pardir + '/build/websocket-api-java-*.jar'
+ )
+
+ if not ws_jars:
+ self.fail('websocket api jar not found.')
javac = [
'javac',
'-encoding', 'utf-8',
'-d', classes_path,
- '-classpath', tomcat_jar,
+ '-classpath', classpath + ':' + ws_jars[0],
]
javac.extend(src)
diff --git a/test/unit/applications/lang/node.py b/test/unit/applications/lang/node.py
index 931c6596..3cc72669 100644
--- a/test/unit/applications/lang/node.py
+++ b/test/unit/applications/lang/node.py
@@ -4,8 +4,18 @@ from unit.applications.proto import TestApplicationProto
class TestApplicationNode(TestApplicationProto):
- def load(self, script, name='app.js'):
+ @classmethod
+ def setUpClass(cls, complete_check=True):
+ unit = super().setUpClass(complete_check=False)
+
+ # check node module
+
+ if os.path.exists(unit.pardir + '/node/node_modules'):
+ cls.available['modules']['node'] = []
+ return unit if not complete_check else unit.complete()
+
+ def load(self, script, name='app.js'):
# copy application
shutil.copytree(
diff --git a/test/unit/applications/tls.py b/test/unit/applications/tls.py
index 6e8deefb..1290279d 100644
--- a/test/unit/applications/tls.py
+++ b/test/unit/applications/tls.py
@@ -1,4 +1,5 @@
import os
+import re
import ssl
import subprocess
from unit.applications.proto import TestApplicationProto
@@ -12,6 +13,27 @@ class TestApplicationTLS(TestApplicationProto):
self.context.check_hostname = False
self.context.verify_mode = ssl.CERT_NONE
+ @classmethod
+ def setUpClass(cls, complete_check=True):
+ unit = super().setUpClass(complete_check=False)
+
+ # check tls module
+
+ try:
+ subprocess.check_output(['which', 'openssl'])
+
+ output = subprocess.check_output(
+ [unit.unitd, '--version'], stderr=subprocess.STDOUT
+ )
+
+ if re.search('--openssl', output.decode()):
+ cls.available['modules']['openssl'] = []
+
+ except:
+ pass
+
+ return unit if not complete_check else unit.complete()
+
def certificate(self, name='default', load=True):
self.openssl_conf()
diff --git a/test/unit/applications/websockets.py b/test/unit/applications/websockets.py
index 417e9504..50ff2797 100644
--- a/test/unit/applications/websockets.py
+++ b/test/unit/applications/websockets.py
@@ -54,24 +54,16 @@ class TestApplicationWebsocket(TestApplicationProto):
def apply_mask(self, data, mask):
return bytes(b ^ m for b, m in zip(data, itertools.cycle(mask)))
- def serialize_close(self, code = 1000, reason = ''):
+ def serialize_close(self, code=1000, reason=''):
return struct.pack('!H', code) + reason.encode('utf-8')
- def frame_read(self, sock, read_timeout=10):
+ def frame_read(self, sock, read_timeout=30):
def recv_bytes(sock, bytes):
data = b''
while select.select([sock], [], [], read_timeout)[0]:
- try:
- if bytes < 65536:
- data = sock.recv(bytes)
- else:
- data = self.recvall(
- sock,
- read_timeout=read_timeout,
- buff_size=bytes,
- )
- break
- except:
+ data += sock.recv(bytes - len(data))
+
+ if len(data) == bytes:
break
return data
@@ -99,7 +91,11 @@ class TestApplicationWebsocket(TestApplicationProto):
if frame['mask']:
mask_bits = recv_bytes(sock, 4)
- data = recv_bytes(sock, length)
+ data = b''
+
+ if length != 0:
+ data = recv_bytes(sock, length)
+
if frame['mask']:
data = self.apply_mask(data, mask_bits)
@@ -175,14 +171,20 @@ class TestApplicationWebsocket(TestApplicationProto):
frame = self.frame_to_send(*args, **kwargs)
if chopsize is None:
- sock.sendall(frame)
+ try:
+ sock.sendall(frame)
+ except BrokenPipeError:
+ pass
else:
pos = 0
frame_len = len(frame)
- while (pos < frame_len):
+ while pos < frame_len:
end = min(pos + chopsize, frame_len)
- sock.sendall(frame[pos:end])
+ try:
+ sock.sendall(frame[pos:end])
+ except BrokenPipeError:
+ end = frame_len
pos = end
def message(self, sock, type, message, fragmention_size=None, **kwargs):
@@ -197,17 +199,19 @@ class TestApplicationWebsocket(TestApplicationProto):
pos = 0
op_code = type
- while(pos < message_len):
+ while pos < message_len:
end = min(pos + fragmention_size, message_len)
- fin = (end == message_len)
- self.frame_write(sock, op_code, message[pos:end], fin=fin, **kwargs)
+ fin = end == message_len
+ self.frame_write(
+ sock, op_code, message[pos:end], fin=fin, **kwargs
+ )
op_code = self.OP_CONT
pos = end
def message_read(self, sock, read_timeout=10):
frame = self.frame_read(sock, read_timeout=read_timeout)
- while(not frame['fin']):
+ while not frame['fin']:
temp = self.frame_read(sock, read_timeout=read_timeout)
frame['data'] += temp['data']
frame['fin'] = temp['fin']