summaryrefslogtreecommitdiffhomepage
path: root/test/unit/applications
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--test/unit/applications/lang/go.py1
-rw-r--r--test/unit/applications/lang/node.py21
-rw-r--r--test/unit/applications/lang/python.py11
-rw-r--r--test/unit/applications/proto.py18
-rw-r--r--test/unit/applications/tls.py42
-rw-r--r--test/unit/applications/websockets.py18
6 files changed, 82 insertions, 29 deletions
diff --git a/test/unit/applications/lang/go.py b/test/unit/applications/lang/go.py
index a17b1af4..6be1667b 100644
--- a/test/unit/applications/lang/go.py
+++ b/test/unit/applications/lang/go.py
@@ -13,6 +13,7 @@ class TestApplicationGo(TestApplicationProto):
env = os.environ.copy()
env['GOPATH'] = option.current_dir + '/build/go'
env['GOCACHE'] = option.cache_dir + '/go'
+ env['GO111MODULE'] = 'auto'
if static:
args = [
diff --git a/test/unit/applications/lang/node.py b/test/unit/applications/lang/node.py
index cc6d06ef..5d05c70c 100644
--- a/test/unit/applications/lang/node.py
+++ b/test/unit/applications/lang/node.py
@@ -7,15 +7,16 @@ from unit.utils import public_dir
class TestApplicationNode(TestApplicationProto):
+ application_type = "node"
+ es_modules = False
+
def prepare_env(self, script):
# copy application
-
shutil.copytree(
option.test_dir + '/node/' + script, option.temp_dir + '/node'
)
# copy modules
-
shutil.copytree(
option.current_dir + '/node/node_modules',
option.temp_dir + '/node/node_modules',
@@ -26,6 +27,19 @@ class TestApplicationNode(TestApplicationProto):
def load(self, script, name='app.js', **kwargs):
self.prepare_env(script)
+ if self.es_modules:
+ arguments = [
+ "node",
+ "--loader",
+ "unit-http/loader.mjs",
+ "--require",
+ "unit-http/loader",
+ name,
+ ]
+
+ else:
+ arguments = ["node", "--require", "unit-http/loader", name]
+
self._load_conf(
{
"listeners": {
@@ -36,7 +50,8 @@ class TestApplicationNode(TestApplicationProto):
"type": "external",
"processes": {"spare": 0},
"working_directory": option.temp_dir + '/node',
- "executable": name,
+ "executable": '/usr/bin/env',
+ "arguments": arguments,
}
},
},
diff --git a/test/unit/applications/lang/python.py b/test/unit/applications/lang/python.py
index 287d23f0..b399dffd 100644
--- a/test/unit/applications/lang/python.py
+++ b/test/unit/applications/lang/python.py
@@ -42,8 +42,15 @@ class TestApplicationPython(TestApplicationProto):
"module": module,
}
- for attr in ('callable', 'home', 'limits', 'path', 'protocol',
- 'threads'):
+ for attr in (
+ 'callable',
+ 'home',
+ 'limits',
+ 'path',
+ 'protocol',
+ 'targets',
+ 'threads',
+ ):
if attr in kwargs:
app[attr] = kwargs.pop(attr)
diff --git a/test/unit/applications/proto.py b/test/unit/applications/proto.py
index 5c400621..92754c03 100644
--- a/test/unit/applications/proto.py
+++ b/test/unit/applications/proto.py
@@ -4,6 +4,7 @@ import time
from unit.control import TestControl
from unit.option import option
+from unit.log import Log
class TestApplicationProto(TestControl):
@@ -15,18 +16,23 @@ class TestApplicationProto(TestControl):
def date_to_sec_epoch(self, date, template='%a, %d %b %Y %H:%M:%S %Z'):
return time.mktime(time.strptime(date, template))
+ def findall(self, pattern, name='unit.log'):
+ with Log.open(name) as f:
+ return re.findall(pattern, f.read())
+
def search_in_log(self, pattern, name='unit.log'):
- with open(option.temp_dir + '/' + name, 'r', errors='ignore') as f:
+ with Log.open(name) as f:
return re.search(pattern, f.read())
def wait_for_record(self, pattern, name='unit.log', wait=150):
- for i in range(wait):
- found = self.search_in_log(pattern, name)
+ with Log.open(name) as f:
+ for i in range(wait):
+ found = re.search(pattern, f.read())
- if found is not None:
- break
+ if found is not None:
+ break
- time.sleep(0.1)
+ time.sleep(0.1)
return found
diff --git a/test/unit/applications/tls.py b/test/unit/applications/tls.py
index b0cd5abb..583b618f 100644
--- a/test/unit/applications/tls.py
+++ b/test/unit/applications/tls.py
@@ -21,10 +21,14 @@ class TestApplicationTLS(TestApplicationProto):
'req',
'-x509',
'-new',
- '-subj', '/CN=' + name + '/',
- '-config', option.temp_dir + '/openssl.conf',
- '-out', option.temp_dir + '/' + name + '.crt',
- '-keyout', option.temp_dir + '/' + name + '.key',
+ '-subj',
+ '/CN=' + name + '/',
+ '-config',
+ option.temp_dir + '/openssl.conf',
+ '-out',
+ option.temp_dir + '/' + name + '.crt',
+ '-keyout',
+ option.temp_dir + '/' + name + '.key',
],
stderr=subprocess.STDOUT,
)
@@ -63,19 +67,43 @@ class TestApplicationTLS(TestApplicationProto):
return ssl.get_server_certificate(addr, ssl_version=ssl_version)
- def openssl_conf(self):
+ def openssl_conf(self, rewrite=False, alt_names=[]):
conf_path = option.temp_dir + '/openssl.conf'
- if os.path.exists(conf_path):
+ if not rewrite and os.path.exists(conf_path):
return
+ # Generates alt_names section with dns names
+ a_names = "[alt_names]\n"
+ for i, k in enumerate(alt_names, 1):
+ k = k.split('|')
+
+ if k[0] == 'IP':
+ a_names += "IP.%d = %s\n" % (i, k[1])
+ else:
+ a_names += "DNS.%d = %s\n" % (i, k[0])
+
+ # Generates section for sign request extension
+ a_sec = """req_extensions = myca_req_extensions
+
+[ myca_req_extensions ]
+subjectAltName = @alt_names
+
+{a_names}""".format(
+ a_names=a_names
+ )
+
with open(conf_path, 'w') as f:
f.write(
"""[ req ]
default_bits = 2048
encrypt_key = no
distinguished_name = req_distinguished_name
-[ req_distinguished_name ]"""
+
+{a_sec}
+[ req_distinguished_name ]""".format(
+ a_sec=a_sec if alt_names else ""
+ )
)
def load(self, script, name=None):
diff --git a/test/unit/applications/websockets.py b/test/unit/applications/websockets.py
index cc720a98..aa83339c 100644
--- a/test/unit/applications/websockets.py
+++ b/test/unit/applications/websockets.py
@@ -43,11 +43,7 @@ class TestApplicationWebsocket(TestApplicationProto):
'Sec-WebSocket-Version': 13,
}
- _, sock = self.get(
- headers=headers,
- no_recv=True,
- start=True,
- )
+ _, sock = self.get(headers=headers, no_recv=True, start=True,)
resp = ''
while True:
@@ -57,7 +53,7 @@ class TestApplicationWebsocket(TestApplicationProto):
resp += sock.recv(4096).decode()
- if (resp.startswith('HTTP/') and '\r\n\r\n' in resp):
+ if resp.startswith('HTTP/') and '\r\n\r\n' in resp:
resp = self._resp_to_dict(resp)
break
@@ -90,8 +86,8 @@ class TestApplicationWebsocket(TestApplicationProto):
frame = {}
- head1, = struct.unpack('!B', recv_bytes(sock, 1))
- head2, = struct.unpack('!B', recv_bytes(sock, 1))
+ (head1,) = struct.unpack('!B', recv_bytes(sock, 1))
+ (head2,) = struct.unpack('!B', recv_bytes(sock, 1))
frame['fin'] = bool(head1 & 0b10000000)
frame['rsv1'] = bool(head1 & 0b01000000)
@@ -103,10 +99,10 @@ class TestApplicationWebsocket(TestApplicationProto):
length = head2 & 0b01111111
if length == 126:
data = recv_bytes(sock, 2)
- length, = struct.unpack('!H', data)
+ (length,) = struct.unpack('!H', data)
elif length == 127:
data = recv_bytes(sock, 8)
- length, = struct.unpack('!Q', data)
+ (length,) = struct.unpack('!Q', data)
if frame['mask']:
mask_bits = recv_bytes(sock, 4)
@@ -121,7 +117,7 @@ class TestApplicationWebsocket(TestApplicationProto):
if frame['opcode'] == self.OP_CLOSE:
if length >= 2:
- code, = struct.unpack('!H', data[:2])
+ (code,) = struct.unpack('!H', data[:2])
reason = data[2:].decode('utf-8')
if not (code in self.CLOSE_CODES or 3000 <= code < 5000):
pytest.fail('Invalid status code')