From e04cc587cbddd125ea54b5252177f3fae273624b Mon Sep 17 00:00:00 2001 From: agessaman Date: Thu, 16 Apr 2026 18:41:27 -0700 Subject: [PATCH] test: add tests for admin config page loading and password redaction Introduced a new test class, TestAdminConfig, to verify the loading of the admin configuration page and ensure sensitive information like passwords is redacted in the response. This enhances test coverage for the admin configuration functionality. --- .../web_viewer/templates/admin_config.html | 113 ++++++++++++++++++ tests/test_web_viewer_app.py | 19 +++ 2 files changed, 132 insertions(+) create mode 100644 modules/web_viewer/templates/admin_config.html diff --git a/modules/web_viewer/templates/admin_config.html b/modules/web_viewer/templates/admin_config.html new file mode 100644 index 0000000..eae5064 --- /dev/null +++ b/modules/web_viewer/templates/admin_config.html @@ -0,0 +1,113 @@ +{% extends "base.html" %} + +{% block title %}Raw Config — MeshCore Bot{% endblock %} + +{% block extra_css %} + +{% endblock %} + +{% block content %} +
+
+
+ +

+ Raw Config +

+

+ Effective values loaded by the bot (sensitive keys are redacted). This view is read-only. +

+

+ {{ config_path }} +

+ + {% for section_name, options in sections.items() %} +
+
+

[{{ section_name }}]

+
+
+ {% if options %} +
+ + + + + + + + + {% for key, val in options.items() %} + + + + + {% endfor %} + +
KeyValue
{{ key }}{{ val }}
+
+ {% else %} +

No keys in this section.

+ {% endif %} +
+
+ {% endfor %} + + {% if not sections %} +

No configuration sections to display.

+ {% endif %} +
+
+
+{% endblock %} diff --git a/tests/test_web_viewer_app.py b/tests/test_web_viewer_app.py index eb91575..74e9a59 100644 --- a/tests/test_web_viewer_app.py +++ b/tests/test_web_viewer_app.py @@ -811,6 +811,25 @@ class TestApiExplorer: assert 'curl-btn' in body +# --------------------------------------------------------------------------- +# admin_config (resolved config.ini viewer) +# --------------------------------------------------------------------------- + + +class TestAdminConfig: + def test_page_loads(self, mock_viewer): + with mock_viewer.app.test_client() as client: + response = client.get('/admin/config') + assert response.status_code == 200 + + def test_redacts_password_like_keys(self, mock_viewer): + with mock_viewer.app.test_client() as client: + response = client.get('/admin/config') + body = response.data.decode() + assert 'web_viewer_password' in body + assert '●●●●●●' in body + + # --------------------------------------------------------------------------- # error_handler # ---------------------------------------------------------------------------