Tests: minor improvements.
Added "go" availability check before trying to build an application. update_action() method used were possible and fixed bug with the relative path determination in test_static_chroot.py. Templates optimization and style fixes.
This commit is contained in:
@@ -14,8 +14,7 @@ class TestStaticChroot(TestApplicationProto):
|
|||||||
Path(temp_dir + '/assets/index.html').write_text('0123456789')
|
Path(temp_dir + '/assets/index.html').write_text('0123456789')
|
||||||
Path(temp_dir + '/assets/dir/file').write_text('blah')
|
Path(temp_dir + '/assets/dir/file').write_text('blah')
|
||||||
|
|
||||||
test = Path(__file__)
|
self.test_path = '/' + os.path.relpath(Path(__file__))
|
||||||
self.test_path = '/' + test.parent.name + '/' + test.name
|
|
||||||
|
|
||||||
self._load_conf(
|
self._load_conf(
|
||||||
{
|
{
|
||||||
@@ -39,26 +38,18 @@ class TestStaticChroot(TestApplicationProto):
|
|||||||
assert self.get(url='/dir/file')['status'] == 200, 'default chroot'
|
assert self.get(url='/dir/file')['status'] == 200, 'default chroot'
|
||||||
assert self.get(url='/index.html')['status'] == 200, 'default chroot 2'
|
assert self.get(url='/index.html')['status'] == 200, 'default chroot 2'
|
||||||
|
|
||||||
assert 'success' in self.conf(
|
assert 'success' in self.update_action(
|
||||||
{
|
temp_dir + "/assets$uri", temp_dir + "/assets/dir"
|
||||||
"share": temp_dir + "/assets$uri",
|
)
|
||||||
"chroot": temp_dir + "/assets/dir",
|
|
||||||
},
|
|
||||||
'routes/0/action',
|
|
||||||
), 'configure chroot'
|
|
||||||
|
|
||||||
assert self.get(url='/dir/file')['status'] == 200, 'chroot'
|
assert self.get(url='/dir/file')['status'] == 200, 'chroot'
|
||||||
assert self.get(url='/index.html')['status'] == 403, 'chroot 403 2'
|
assert self.get(url='/index.html')['status'] == 403, 'chroot 403 2'
|
||||||
assert self.get(url='/file')['status'] == 403, 'chroot 403'
|
assert self.get(url='/file')['status'] == 403, 'chroot 403'
|
||||||
|
|
||||||
def test_share_chroot_array(self, temp_dir):
|
def test_share_chroot_array(self, temp_dir):
|
||||||
assert 'success' in self.conf(
|
assert 'success' in self.update_action(
|
||||||
{
|
["/blah", temp_dir + "/assets$uri"], temp_dir + "/assets/dir"
|
||||||
"share": ["/blah", temp_dir + "/assets$uri"],
|
)
|
||||||
"chroot": temp_dir + "/assets/dir",
|
|
||||||
},
|
|
||||||
'routes/0/action',
|
|
||||||
), 'configure share array'
|
|
||||||
assert self.get(url='/dir/file')['status'] == 200, 'share array'
|
assert self.get(url='/dir/file')['status'] == 200, 'share array'
|
||||||
|
|
||||||
assert 'success' in self.update_action(
|
assert 'success' in self.update_action(
|
||||||
@@ -66,13 +57,9 @@ class TestStaticChroot(TestApplicationProto):
|
|||||||
)
|
)
|
||||||
assert self.get_custom('/dir/file', 'dir') == 200, 'array variable'
|
assert self.get_custom('/dir/file', 'dir') == 200, 'array variable'
|
||||||
|
|
||||||
assert 'success' in self.conf(
|
assert 'success' in self.update_action(
|
||||||
{
|
["/blah", "/blah2"], temp_dir + "/assets/dir"
|
||||||
"share": ["/blah", "/blah2"],
|
)
|
||||||
"chroot": temp_dir + "/assets/dir",
|
|
||||||
},
|
|
||||||
'routes/0/action',
|
|
||||||
), 'configure share array bad'
|
|
||||||
assert self.get()['status'] != 200, 'share array bad'
|
assert self.get()['status'] != 200, 'share array bad'
|
||||||
|
|
||||||
def test_static_chroot_permission(self, is_su, temp_dir):
|
def test_static_chroot_permission(self, is_su, temp_dir):
|
||||||
@@ -81,58 +68,30 @@ class TestStaticChroot(TestApplicationProto):
|
|||||||
|
|
||||||
os.chmod(temp_dir + '/assets/dir', 0o100)
|
os.chmod(temp_dir + '/assets/dir', 0o100)
|
||||||
|
|
||||||
assert 'success' in self.conf(
|
assert 'success' in self.update_action(
|
||||||
{
|
temp_dir + "/assets$uri", temp_dir + "/assets/dir"
|
||||||
"share": temp_dir + "/assets$uri",
|
|
||||||
"chroot": temp_dir + "/assets/dir",
|
|
||||||
},
|
|
||||||
'routes/0/action',
|
|
||||||
), 'configure chroot'
|
), 'configure chroot'
|
||||||
|
|
||||||
assert self.get(url='/dir/file')['status'] == 200, 'chroot'
|
assert self.get(url='/dir/file')['status'] == 200, 'chroot'
|
||||||
|
|
||||||
def test_static_chroot_empty(self, temp_dir):
|
def test_static_chroot_empty(self, temp_dir):
|
||||||
assert 'success' in self.conf(
|
assert 'success' in self.update_action(temp_dir + "/assets$uri", "")
|
||||||
{"share": temp_dir + "/assets$uri", "chroot": ""},
|
assert self.get(url='/dir/file')['status'] == 200, 'empty absolute'
|
||||||
'routes/0/action',
|
|
||||||
), 'configure chroot empty absolute'
|
|
||||||
|
|
||||||
assert (
|
assert 'success' in self.update_action(".$uri", "")
|
||||||
self.get(url='/dir/file')['status'] == 200
|
assert self.get(url=self.test_path)['status'] == 200, 'empty relative'
|
||||||
), 'chroot empty absolute'
|
|
||||||
|
|
||||||
assert 'success' in self.conf(
|
|
||||||
{"share": ".$uri", "chroot": ""},
|
|
||||||
'routes/0/action',
|
|
||||||
), 'configure chroot empty relative'
|
|
||||||
|
|
||||||
assert (
|
|
||||||
self.get(url=self.test_path)['status'] == 200
|
|
||||||
), 'chroot empty relative'
|
|
||||||
|
|
||||||
def test_static_chroot_relative(self, is_su, temp_dir):
|
def test_static_chroot_relative(self, is_su, temp_dir):
|
||||||
if is_su:
|
if is_su:
|
||||||
pytest.skip('does\'t work under root')
|
pytest.skip('does\'t work under root')
|
||||||
|
|
||||||
assert 'success' in self.conf(
|
assert 'success' in self.update_action(temp_dir + "/assets$uri", ".")
|
||||||
{"share": temp_dir + "/assets$uri", "chroot": "."},
|
|
||||||
'routes/0/action',
|
|
||||||
), 'configure relative chroot'
|
|
||||||
|
|
||||||
assert self.get(url='/dir/file')['status'] == 403, 'relative chroot'
|
assert self.get(url='/dir/file')['status'] == 403, 'relative chroot'
|
||||||
|
|
||||||
assert 'success' in self.conf(
|
assert 'success' in self.conf({"share": ".$uri"}, 'routes/0/action')
|
||||||
{"share": ".$uri"},
|
|
||||||
'routes/0/action',
|
|
||||||
), 'configure relative share'
|
|
||||||
|
|
||||||
assert self.get(url=self.test_path)['status'] == 200, 'relative share'
|
assert self.get(url=self.test_path)['status'] == 200, 'relative share'
|
||||||
|
|
||||||
assert 'success' in self.conf(
|
assert 'success' in self.update_action(".$uri", ".")
|
||||||
{"share": ".$uri", "chroot": "."},
|
|
||||||
'routes/0/action',
|
|
||||||
), 'configure relative'
|
|
||||||
|
|
||||||
assert self.get(url=self.test_path)['status'] == 200, 'relative'
|
assert self.get(url=self.test_path)['status'] == 200, 'relative'
|
||||||
|
|
||||||
def test_static_chroot_variables(self, temp_dir):
|
def test_static_chroot_variables(self, temp_dir):
|
||||||
@@ -150,64 +109,41 @@ class TestStaticChroot(TestApplicationProto):
|
|||||||
assert 'success' in self.update_action(
|
assert 'success' in self.update_action(
|
||||||
temp_dir + '/assets/dir/$host', '$uri/assets/dir'
|
temp_dir + '/assets/dir/$host', '$uri/assets/dir'
|
||||||
)
|
)
|
||||||
|
|
||||||
assert self.get_custom(temp_dir, 'file') == 200
|
assert self.get_custom(temp_dir, 'file') == 200
|
||||||
|
|
||||||
def test_static_chroot_variables_buildin_mid(self, temp_dir):
|
def test_static_chroot_variables_buildin_mid(self, temp_dir):
|
||||||
assert 'success' in self.update_action(
|
assert 'success' in self.update_action(
|
||||||
temp_dir + '/assets$uri', temp_dir + '/$host/dir'
|
temp_dir + '/assets$uri', temp_dir + '/$host/dir'
|
||||||
)
|
)
|
||||||
|
|
||||||
assert self.get_custom('/dir/file', 'assets') == 200
|
assert self.get_custom('/dir/file', 'assets') == 200
|
||||||
|
|
||||||
def test_static_chroot_variables_buildin_end(self, temp_dir):
|
def test_static_chroot_variables_buildin_end(self, temp_dir):
|
||||||
assert 'success' in self.update_action(
|
assert 'success' in self.update_action(
|
||||||
temp_dir + '/assets$uri', temp_dir + '/assets/$host'
|
temp_dir + '/assets$uri', temp_dir + '/assets/$host'
|
||||||
)
|
)
|
||||||
|
|
||||||
assert self.get_custom('/dir/file', 'dir') == 200
|
assert self.get_custom('/dir/file', 'dir') == 200
|
||||||
|
|
||||||
def test_static_chroot_slash(self, temp_dir):
|
def test_static_chroot_slash(self, temp_dir):
|
||||||
assert 'success' in self.conf(
|
assert 'success' in self.update_action(
|
||||||
{
|
temp_dir + "/assets$uri", temp_dir + "/assets/dir/"
|
||||||
"share": temp_dir + "/assets$uri",
|
)
|
||||||
"chroot": temp_dir + "/assets/dir/",
|
|
||||||
},
|
|
||||||
'routes/0/action',
|
|
||||||
), 'configure chroot slash end'
|
|
||||||
|
|
||||||
assert self.get(url='/dir/file')['status'] == 200, 'slash end'
|
assert self.get(url='/dir/file')['status'] == 200, 'slash end'
|
||||||
assert self.get(url='/dirxfile')['status'] == 403, 'slash end bad'
|
assert self.get(url='/dirxfile')['status'] == 403, 'slash end bad'
|
||||||
|
|
||||||
assert 'success' in self.conf(
|
assert 'success' in self.update_action(
|
||||||
{
|
temp_dir + "/assets$uri", temp_dir + "/assets/dir"
|
||||||
"share": temp_dir + "/assets$uri",
|
)
|
||||||
"chroot": temp_dir + "/assets/dir",
|
|
||||||
},
|
|
||||||
'routes/0/action',
|
|
||||||
), 'configure chroot no slash end'
|
|
||||||
|
|
||||||
assert self.get(url='/dir/file')['status'] == 200, 'no slash end'
|
assert self.get(url='/dir/file')['status'] == 200, 'no slash end'
|
||||||
|
|
||||||
assert 'success' in self.conf(
|
assert 'success' in self.update_action(
|
||||||
{
|
temp_dir + "/assets$uri", temp_dir + "/assets/dir/"
|
||||||
"share": temp_dir + "/assets$uri",
|
)
|
||||||
"chroot": temp_dir + "/assets/dir/",
|
|
||||||
},
|
|
||||||
'routes/0/action',
|
|
||||||
), 'configure chroot slash end 2'
|
|
||||||
|
|
||||||
assert self.get(url='/dir/file')['status'] == 200, 'slash end 2'
|
assert self.get(url='/dir/file')['status'] == 200, 'slash end 2'
|
||||||
assert self.get(url='/dirxfile')['status'] == 403, 'slash end 2 bad'
|
assert self.get(url='/dirxfile')['status'] == 403, 'slash end 2 bad'
|
||||||
|
|
||||||
assert 'success' in self.conf(
|
assert 'success' in self.update_action(
|
||||||
{
|
temp_dir + "///assets/////$uri", temp_dir + "//assets////dir///"
|
||||||
"share": temp_dir + "///assets/////$uri",
|
)
|
||||||
"chroot": temp_dir + "//assets////dir///",
|
|
||||||
},
|
|
||||||
'routes/0/action',
|
|
||||||
), 'configure chroot multiple slashes'
|
|
||||||
|
|
||||||
assert self.get(url='/dir/file')['status'] == 200, 'multiple slashes'
|
assert self.get(url='/dir/file')['status'] == 200, 'multiple slashes'
|
||||||
|
|
||||||
def test_static_chroot_invalid(self, temp_dir):
|
def test_static_chroot_invalid(self, temp_dir):
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class TestTLS(TestApplicationTLS):
|
|||||||
prerequisites = {'modules': {'python': 'any', 'openssl': 'any'}}
|
prerequisites = {'modules': {'python': 'any', 'openssl': 'any'}}
|
||||||
|
|
||||||
def openssl_date_to_sec_epoch(self, date):
|
def openssl_date_to_sec_epoch(self, date):
|
||||||
return self.date_to_sec_epoch(date, '%b %d %H:%M:%S %Y %Z')
|
return self.date_to_sec_epoch(date, '%b %d %X %Y %Z')
|
||||||
|
|
||||||
def add_tls(self, application='empty', cert='default', port=7080):
|
def add_tls(self, application='empty', cert='default', port=7080):
|
||||||
assert 'success' in self.conf(
|
assert 'success' in self.conf(
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class TestTLSSNI(TestApplicationTLS):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def openssl_date_to_sec_epoch(self, date):
|
def openssl_date_to_sec_epoch(self, date):
|
||||||
return self.date_to_sec_epoch(date, '%b %d %H:%M:%S %Y %Z')
|
return self.date_to_sec_epoch(date, '%b %d %X %Y %Z')
|
||||||
|
|
||||||
def add_tls(self, cert='default'):
|
def add_tls(self, cert='default'):
|
||||||
assert 'success' in self.conf(
|
assert 'success' in self.conf(
|
||||||
|
|||||||
@@ -9,6 +9,11 @@ from unit.option import option
|
|||||||
class TestApplicationGo(TestApplicationProto):
|
class TestApplicationGo(TestApplicationProto):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def prepare_env(script, name='app', static=False):
|
def prepare_env(script, name='app', static=False):
|
||||||
|
try:
|
||||||
|
subprocess.check_output(['which', 'go'])
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
return None
|
||||||
|
|
||||||
temp_dir = option.temp_dir + '/go/'
|
temp_dir = option.temp_dir + '/go/'
|
||||||
|
|
||||||
if not os.path.exists(temp_dir):
|
if not os.path.exists(temp_dir):
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class TestApplicationProto(TestControl):
|
|||||||
def sec_epoch(self):
|
def sec_epoch(self):
|
||||||
return time.mktime(time.gmtime())
|
return time.mktime(time.gmtime())
|
||||||
|
|
||||||
def date_to_sec_epoch(self, date, template='%a, %d %b %Y %H:%M:%S %Z'):
|
def date_to_sec_epoch(self, date, template='%a, %d %b %Y %X %Z'):
|
||||||
return time.mktime(time.strptime(date, template))
|
return time.mktime(time.strptime(date, template))
|
||||||
|
|
||||||
def findall(self, pattern, name='unit.log'):
|
def findall(self, pattern, name='unit.log'):
|
||||||
|
|||||||
Reference in New Issue
Block a user