feat: test mCaptcha installation for firewall, services and health endpoint

This commit is contained in:
Aravinth Manivannan 2023-12-09 02:57:32 +05:30
parent 3002808f92
commit f7206d721c
Signed by: realaravinth
GPG Key ID: F8F50389936984FF
2 changed files with 41 additions and 0 deletions

2
.gitignore vendored
View File

@ -159,3 +159,5 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
ansible/credentials/
terraform/mcaptcha/mcaptcha

39
tests/mcaptcha/base.py Normal file
View File

@ -0,0 +1,39 @@
# SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
import os
import requests
def test_mcaptcha_nginx_is_listening(host):
socket = host.socket(f"tcp://127.0.0.1:80")
assert socket.is_listening
def test_mcaptcha_config_exists(host):
config = host.file("/etc/mcaptcha/config.toml")
assert config.exists
assert config.is_file
def test_mcaptcha_health(host):
url = f"http://{host.interface.default().addresses[0]}/api/v1/meta/health"
resp = requests.get(url, headers={"Host": "mcaptcha.local"})
assert resp.status_code == 200
data = resp.json()
if "redis" in data:
assert data["redis"] is True
assert data["db"] is True
def test_nginx_service_running_and_enabled(host):
service = host.service("nginx")
assert service.is_running
assert service.is_enabled
def test_mcaptcha_service_running_and_enabled(host):
service = host.service("mcaptcha")
assert service.is_running
assert service.is_enabled