Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kwabena Antwi-Boasiako
slapos
Commits
3c5e9e9d
Commit
3c5e9e9d
authored
Feb 08, 2019
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
caddy-frontend: fix tests for plugin promises
parent
c106130b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
140 additions
and
78 deletions
+140
-78
software/caddy-frontend/test/test.py
software/caddy-frontend/test/test.py
+112
-78
software/caddy-frontend/test/test_data/test.TestSlaveBadParameters.test_plugin_list-CADDY.txt
...ta/test.TestSlaveBadParameters.test_plugin_list-CADDY.txt
+28
-0
No files found.
software/caddy-frontend/test/test.py
View file @
3c5e9e9d
...
...
@@ -42,6 +42,7 @@ from forcediphttpsadapter.adapters import ForcedIPHTTPSAdapter
import
time
import
tempfile
import
ipaddress
import
importlib
from
utils
import
SlapOSInstanceTestCase
from
utils
import
findFreeTCPPort
...
...
@@ -223,6 +224,29 @@ def getQUIC(url, ip, port):
except
subprocess
.
CalledProcessError
as
e
:
return
False
,
e
.
output
def
getPluginParameterDict
(
software_path
,
filepath
):
bin_file
=
os
.
path
.
join
(
software_path
,
'bin'
,
'test-plugin-promise'
)
with
open
(
bin_file
,
'w'
)
as
f
:
f
.
write
(
"""#!%s/bin/pythonwitheggs
import os
import importlib
import sys
import json
filepath = sys.argv[1]
sys.path[0:0] = [os.path.dirname(filepath)]
filename = os.path.basename(filepath)
module = importlib.import_module(os.path.splitext(filename)[0])
print json.dumps(module.extra_config_dict)
"""
%
software_path
)
os
.
chmod
(
bin_file
,
0755
)
result
=
subprocess_output
([
bin_file
,
filepath
]).
strip
()
try
:
return
json
.
loads
(
result
)
except
ValueError
,
e
:
raise
ValueError
(
"%s
\
n
Result was: %s"
%
(
e
,
result
))
class
TestDataMixin
(
object
):
@
staticmethod
...
...
@@ -1030,8 +1054,6 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
self
.
assertEqual
(
set
([
'monitor-http-frontend'
,
'monitor-httpd-listening-on-tcp'
,
'promise-monitor-httpd-is-process-older-than-dependency-set'
,
]),
set
(
os
.
listdir
(
os
.
path
.
join
(
partition_path
,
'etc'
,
'promise'
))))
...
...
@@ -1040,6 +1062,8 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
set
([
'monitor-bootstrap-status.py'
,
'check-free-disk-space.py'
,
'monitor-http-frontend.py'
,
'monitor-httpd-listening-on-tcp.py'
,
'buildout-%s-0-status.py'
%
(
type
(
self
).
__name__
,),
'__init__.py'
,
]),
...
...
@@ -1056,15 +1080,23 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
partition_path
,
'etc'
,
'httpd-cors.cfg'
),
'r'
).
read
().
strip
())
def
test_promise_monitor_httpd_listening_on_tcp
(
self
):
result
=
set
([
subprocess
.
call
(
q
)
for
q
in
glob
.
glob
(
runpromise_bin
=
os
.
path
.
join
(
self
.
software_path
,
'bin'
,
'monitor.runpromise'
)
result
=
set
([
subprocess
.
call
([
runpromise_bin
,
'-c'
,
os
.
path
.
join
(
os
.
path
.
dirname
(
q
),
'../monitor.conf'
),
'--run-only'
,
'monitor-httpd-listening-on-tcp.py'
]
)
for
q
in
glob
.
glob
(
os
.
path
.
join
(
self
.
instance_path
,
'*'
,
'etc'
,
'p
romise
'
,
'monitor-httpd-listening-on-tcp'
))])
self
.
assertEqual
(
set
([
0
]),
result
)
self
.
instance_path
,
'*'
,
'etc'
,
'p
lugin
'
,
'monitor-httpd-listening-on-tcp
.py
'
))])
self
.
assertEqual
(
set
([
0
]),
result
)
def
test_slave_partition_state
(
self
):
partition_path
=
self
.
getSlavePartitionPath
()
...
...
@@ -2410,18 +2442,17 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
parameter_dict['
domain
'], parameter_dict['
public
-
ipv4
'], '
test
-
path
')
self.assertEqual(httplib.NOT_FOUND, result_http.status_code)
# rewrite SR/bin/is-icmp-packet-lost
open(
os.path.join(self.software_path, '
bin
', '
is
-
icmp
-
packet
-
lost
'), '
w
'
).write('
echo
"$@"')
# call the monitor for this partition
monitor_file = glob.glob(
os.path.join(
self.instance_path, '
*
', '
etc
', '
promise
',
'
check
-
_monitor
-
ipv6
-
test
-
ipv6
-
packet
-
list
-
test
'))[0]
self.instance_path, '
*
', '
etc
', '
plugin
',
'
check
-
_monitor
-
ipv6
-
test
-
ipv6
-
packet
-
list
-
test
.
py
'))[0]
# get promise module and check that parameters are ok
self.assertEqual(
'
-
a
monitor
-
ipv6
-
test
',
subprocess_output(monitor_file).strip()
getPluginParameterDict(self.software_path, monitor_file),
{
'
frequency
': '
720
',
'
address
': '
monitor
-
ipv6
-
test
'
}
)
def test_monitor_ipv4_test(self):
...
...
@@ -2452,18 +2483,18 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
parameter_dict['
domain
'], parameter_dict['
public
-
ipv4
'], '
test
-
path
')
self.assertEqual(httplib.NOT_FOUND, result_http.status_code)
# rewrite SR/bin/is-icmp-packet-lost
open(
os.path.join(self.software_path, '
bin
', '
is
-
icmp
-
packet
-
lost
'), '
w
'
).write('
echo
"$@"')
# call the monitor for this partition
monitor_file = glob.glob(
os.path.join(
self.instance_path, '
*
', '
etc
', '
promise
',
'
check
-
_monitor
-
ipv4
-
test
-
ipv4
-
packet
-
list
-
test
'))[0]
self.instance_path, '
*
', '
etc
', '
plugin
',
'
check
-
_monitor
-
ipv4
-
test
-
ipv4
-
packet
-
list
-
test
.
py
'))[0]
# get promise module and check that parameters are ok
self.assertEqual(
'
-
4
-
a
monitor
-
ipv4
-
test
',
subprocess_output(monitor_file).strip()
getPluginParameterDict(self.software_path, monitor_file),
{
'
frequency
': '
720
',
'
ipv4
': '
true
',
'
address
': '
monitor
-
ipv4
-
test
',
}
)
def test_re6st_optimal_test(self):
...
...
@@ -2494,19 +2525,18 @@ http://apachecustomhttpsaccepted.example.com:%%(http_port)s {
parameter_dict['
domain
'], parameter_dict['
public
-
ipv4
'], '
test
-
path
')
self.assertEqual(httplib.NOT_FOUND, result_http.status_code)
# rewrite SR/bin/is-icmp-packet-lost
open(
os.path.join(
self.software_path, '
bin
', '
check
-
re6st
-
optimal
-
status
'), '
w
'
).write('
echo
"$@"')
# call the monitor for this partition
monitor_file = glob.glob(
os.path.join(
self.instance_path, '
*
', '
etc
', '
promise
',
'
check
-
_re6st
-
optimal
-
test
-
re6st
-
optimal
-
test
'))[0]
self.instance_path, '
*
', '
etc
', '
plugin
',
'
check
-
_re6st
-
optimal
-
test
-
re6st
-
optimal
-
test
.
py
'))[0]
# get promise module and check that parameters are ok
self.assertEqual(
'
-
4
ipv4
-
6
ipv6
',
subprocess_output(monitor_file).strip()
getPluginParameterDict(self.software_path, monitor_file),
{
'
frequency
': '
720
',
'
ipv4
': '
ipv4
',
'
ipv6
': '
ipv6
'
}
)
def test_enable_cache(self):
...
...
@@ -3370,14 +3400,17 @@ class TestRe6stVerificationUrlDefaultSlave(SlaveHttpFrontendTestCase,
re6st_connectivity_promise_list = glob.glob(
os.path.join(
self.instance_path, '
*
', '
etc
', '
p
romise
',
'
re6st
-
connectivity
'))
self.instance_path, '
*
', '
etc
', '
p
lugin
',
'
re6st
-
connectivity
.
py
'))
self.assertEqual(1, len(re6st_connectivity_promise_list))
re6st_connectivity_promise_file = re6st_connectivity_promise_list[0]
self.assertTrue(
'
URL
=
"http://[2001:67c:1254:4::1]/index.html"' in
open(re6st_connectivity_promise_list[0]).read()
self.assertEqual(
getPluginParameterDict(self.software_path, re6st_connectivity_promise_file),
{
'
url
': '
http
:
//
[
2001
:
67
c
:
1254
:
4
::
1
]
/
index
.
html
',
}
)
...
...
@@ -3419,14 +3452,17 @@ class TestRe6stVerificationUrlSlave(SlaveHttpFrontendTestCase,
re6st_connectivity_promise_list = glob.glob(
os.path.join(
self.instance_path, '
*
', '
etc
', '
p
romise
',
'
re6st
-
connectivity
'))
self.instance_path, '
*
', '
etc
', '
p
lugin
',
'
re6st
-
connectivity
.
py
'))
self.assertEqual(1, len(re6st_connectivity_promise_list))
re6st_connectivity_promise_file = re6st_connectivity_promise_list[0]
self.assertTrue(
'
URL
=
"some-re6st-verification-url"' in
open(re6st_connectivity_promise_list[0]).read()
self.assertEqual(
getPluginParameterDict(self.software_path, re6st_connectivity_promise_file),
{
'
url
': '
some
-
re6st
-
verification
-
url
',
}
)
...
...
@@ -3835,23 +3871,21 @@ https://www.google.com {}""",
self.assertEqual(httplib.NOT_FOUND, result.status_code)
# rewrite SR/bin/is-icmp-packet-lost
open(
os.path.join(
self.software_path, 'bin', 'check-re6st-optimal-status'), 'w'
).write('echo "
$
@
"')
# call the monitor for this partition
monitor_file = glob.glob(
os.path.join(
self.instance_path, '*', 'etc', 'p
romise
',
'check-_re6st-optimal-test-unsafe-re6st-optimal-test'))[0]
self.instance_path, '*', 'etc', 'p
lugin
',
'check-_re6st-optimal-test-unsafe-re6st-optimal-test
.py
'))[0]
# Note: The result is a bit differnt from the request (newlines stripped),
# but good enough to prove, that ${esection:eoption} has been
# correctly passed to the script.
self.assertEqual(
'-4 newline [s${esection:eoption} -6 new line;rm -fr ~;',
subprocess_output(monitor_file).strip()
getPluginParameterDict(self.software_path, monitor_file),
{
'frequency': '720',
'ipv4': 'new
\
\
line
\
n
[s${esection:eoption}',
'ipv6': 'new
\
n
line;rm -fr ~;',
}
)
def test_re6st_optimal_test_nocomma(self):
...
...
@@ -3881,8 +3915,8 @@ https://www.google.com {}""",
# assert that there is no nocomma file
monitor_file_list = glob.glob(
os.path.join(
self.instance_path, '*', 'etc', 'p
romise
',
'check-_re6st-optimal-test-nocomma-re6st-optimal-test'))
self.instance_path, '*', 'etc', 'p
lugin
',
'check-_re6st-optimal-test-nocomma-re6st-optimal-test
.py
'))
self.assertEqual(
[],
monitor_file_list
...
...
@@ -4029,18 +4063,19 @@ https://www.google.com {}""",
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path')
self.assertEqual(httplib.NOT_FOUND, result_http.status_code)
# rewrite SR/bin/is-icmp-packet-lost
open(
os.path.join(self.software_path, 'bin', 'is-icmp-packet-lost'), 'w'
).write('echo "
$
@
"')
# call the monitor for this partition
monitor_file = glob.glob(
os.path.join(
self.instance_path, '*', 'etc', 'promise',
'check-_monitor-ipv4-test-unsafe-ipv4-packet-list-test'))[0]
self.instance_path, '*', 'etc', 'plugin',
'check-_monitor-ipv4-test-unsafe-ipv4-packet-list-test.py'))[0]
# get promise module and check that parameters are ok
self.assertEqual(
'-4 -a ${section:option} afternewline ipv4',
subprocess_output(monitor_file).strip()
getPluginParameterDict(self.software_path, monitor_file),
{
'frequency': '720',
'ipv4': 'true',
'address': '${section:option}
\
n
afternewline ipv4',
}
)
def test_monitor_ipv6_test_unsafe(self):
...
...
@@ -4071,18 +4106,17 @@ https://www.google.com {}""",
parameter_dict['domain'], parameter_dict['public-ipv4'], 'test-path')
self.assertEqual(httplib.NOT_FOUND, result_http.status_code)
# rewrite SR/bin/is-icmp-packet-lost
open(
os.path.join(self.software_path, 'bin', 'is-icmp-packet-lost'), 'w'
).write('echo "
$
@
"')
# call the monitor for this partition
monitor_file = glob.glob(
os.path.join(
self.instance_path, '*', 'etc', 'promise',
'check-_monitor-ipv6-test-unsafe-ipv6-packet-list-test'))[0]
self.instance_path, '*', 'etc', 'plugin',
'check-_monitor-ipv6-test-unsafe-ipv6-packet-list-test.py'))[0]
# get promise module and check that parameters are ok
self.assertEqual(
'-a ${section:option} afternewline ipv6',
subprocess_output(monitor_file).strip()
getPluginParameterDict(self.software_path, monitor_file),
{
'frequency': '720',
'address': '${section:option}
\
n
afternewline ipv6'
}
)
def test_ssl_key_ssl_crt_unsafe(self):
...
...
software/caddy-frontend/test/test_data/test.TestSlaveBadParameters.test_plugin_list-CADDY.txt
View file @
3c5e9e9d
...
...
@@ -7,12 +7,40 @@ TestSlaveBadParameters-0/etc/plugin/monitor-httpd-listening-on-tcp.py
TestSlaveBadParameters-1/etc/plugin/__init__.py
TestSlaveBadParameters-1/etc/plugin/buildout-TestSlaveBadParameters-1-status.py
TestSlaveBadParameters-1/etc/plugin/caddy_cached.py
TestSlaveBadParameters-1/etc/plugin/caddy_frontend_ipv4_http.py
TestSlaveBadParameters-1/etc/plugin/caddy_frontend_ipv4_https.py
TestSlaveBadParameters-1/etc/plugin/caddy_frontend_ipv6_http.py
TestSlaveBadParameters-1/etc/plugin/caddy_frontend_ipv6_https.py
TestSlaveBadParameters-1/etc/plugin/caddy_ssl_cached.py
TestSlaveBadParameters-1/etc/plugin/check-_default-path-unsafe-error-log-last-day.py
TestSlaveBadParameters-1/etc/plugin/check-_default-path-unsafe-error-log-last-hour.py
TestSlaveBadParameters-1/etc/plugin/check-_monitor-ipv4-test-unsafe-error-log-last-day.py
TestSlaveBadParameters-1/etc/plugin/check-_monitor-ipv4-test-unsafe-error-log-last-hour.py
TestSlaveBadParameters-1/etc/plugin/check-_monitor-ipv4-test-unsafe-ipv4-packet-list-test.py
TestSlaveBadParameters-1/etc/plugin/check-_monitor-ipv6-test-unsafe-error-log-last-day.py
TestSlaveBadParameters-1/etc/plugin/check-_monitor-ipv6-test-unsafe-error-log-last-hour.py
TestSlaveBadParameters-1/etc/plugin/check-_monitor-ipv6-test-unsafe-ipv6-packet-list-test.py
TestSlaveBadParameters-1/etc/plugin/check-_re6st-optimal-test-nocomma-error-log-last-day.py
TestSlaveBadParameters-1/etc/plugin/check-_re6st-optimal-test-nocomma-error-log-last-hour.py
TestSlaveBadParameters-1/etc/plugin/check-_re6st-optimal-test-unsafe-error-log-last-day.py
TestSlaveBadParameters-1/etc/plugin/check-_re6st-optimal-test-unsafe-error-log-last-hour.py
TestSlaveBadParameters-1/etc/plugin/check-_re6st-optimal-test-unsafe-re6st-optimal-test.py
TestSlaveBadParameters-1/etc/plugin/check-_server-alias-same-error-log-last-day.py
TestSlaveBadParameters-1/etc/plugin/check-_server-alias-same-error-log-last-hour.py
TestSlaveBadParameters-1/etc/plugin/check-_virtualhostroot-http-port-unsafe-error-log-last-day.py
TestSlaveBadParameters-1/etc/plugin/check-_virtualhostroot-http-port-unsafe-error-log-last-hour.py
TestSlaveBadParameters-1/etc/plugin/check-_virtualhostroot-https-port-unsafe-error-log-last-day.py
TestSlaveBadParameters-1/etc/plugin/check-_virtualhostroot-https-port-unsafe-error-log-last-hour.py
TestSlaveBadParameters-1/etc/plugin/check-free-disk-space.py
TestSlaveBadParameters-1/etc/plugin/frontend-caddy-configuration-promise.py
TestSlaveBadParameters-1/etc/plugin/monitor-bootstrap-status.py
TestSlaveBadParameters-1/etc/plugin/monitor-http-frontend.py
TestSlaveBadParameters-1/etc/plugin/monitor-httpd-listening-on-tcp.py
TestSlaveBadParameters-1/etc/plugin/nginx-configuration-promise.py
TestSlaveBadParameters-1/etc/plugin/nginx_frontend_ipv4_http.py
TestSlaveBadParameters-1/etc/plugin/nginx_frontend_ipv4_https.py
TestSlaveBadParameters-1/etc/plugin/nginx_frontend_ipv6_http.py
TestSlaveBadParameters-1/etc/plugin/nginx_frontend_ipv6_https.py
TestSlaveBadParameters-1/etc/plugin/re6st-connectivity.py
TestSlaveBadParameters-1/etc/plugin/trafficserver-cache-availability.py
TestSlaveBadParameters-1/etc/plugin/trafficserver-port-listening.py
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment