2022-08-14 18:36:49 +08:00
|
|
|
from textwrap import dedent
|
|
|
|
|
|
|
|
|
|
|
|
class Test:
|
|
|
|
def test_success(
|
|
|
|
self,
|
|
|
|
processes,
|
|
|
|
echo_server_port,
|
2022-09-02 20:00:08 +08:00
|
|
|
timeout,
|
2022-08-14 18:36:49 +08:00
|
|
|
):
|
|
|
|
proc, _ = processes.start_wg(
|
|
|
|
config=dedent(
|
|
|
|
f'''\
|
|
|
|
users: []
|
|
|
|
targets:
|
|
|
|
- name: target
|
|
|
|
allow_roles: [role]
|
|
|
|
http:
|
|
|
|
url: http://localhost:{echo_server_port}
|
|
|
|
'''
|
|
|
|
),
|
|
|
|
args=['test-target', 'target'],
|
|
|
|
)
|
2022-09-02 20:00:08 +08:00
|
|
|
proc.wait(timeout=timeout)
|
2022-08-14 18:36:49 +08:00
|
|
|
assert proc.returncode == 0
|
|
|
|
|
2022-09-02 20:00:08 +08:00
|
|
|
def test_fail_no_connection(self, processes, timeout):
|
2022-08-14 18:36:49 +08:00
|
|
|
proc, _ = processes.start_wg(
|
|
|
|
config=dedent(
|
|
|
|
'''\
|
|
|
|
users: []
|
|
|
|
targets:
|
|
|
|
- name: target
|
|
|
|
allow_roles: [role]
|
|
|
|
http:
|
|
|
|
url: http://localhostbaddomain
|
|
|
|
'''
|
|
|
|
),
|
|
|
|
args=['test-target', 'target'],
|
|
|
|
)
|
2022-09-02 20:00:08 +08:00
|
|
|
proc.wait(timeout=timeout)
|
2022-08-14 18:36:49 +08:00
|
|
|
assert proc.returncode != 0
|