From 5a6bc9f614545f15bf385b93a8c4a2aea5f46ed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D1=82=D0=B0=D0=BB=D0=B8=D0=B9=20=D0=9B=D0=B8?= =?UTF-8?q?=D1=82=D0=B2=D0=B8=D0=BD=D0=BE=D0=B2?= Date: Sat, 25 Apr 2026 16:45:57 +0300 Subject: [PATCH] v2.5.0: read quoted main proxy secret --- lib/telemt_config.sh | 21 ++++++++++++++++----- tests/test_admin_features.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/lib/telemt_config.sh b/lib/telemt_config.sh index 6aaa55d..d5738fb 100755 --- a/lib/telemt_config.sh +++ b/lib/telemt_config.sh @@ -132,13 +132,24 @@ get_config_value() { awk ' /^\[access\.users\]/ { in_users=1; next } /^\[/ && in_users { exit } - in_users && $1 == "main" { - sub(/^[^=]*=[[:space:]]*"/, "") - sub(/".*$/, "") - print + in_users && /^[[:space:]]*[^#[:space:]][^=]*=/ { + user_key=$1 + gsub(/"/, "", user_key) + if (user_key != "main") next + + value=$0 + sub(/^[^=]*=[[:space:]]*/, "", value) + sub(/^"/, "", value) + sub(/".*$/, "", value) + gsub(/[[:space:]]/, "", value) + if (value != "") { + print value + found=1 + } exit } - ' "$config" | tr -d ' ' + END { exit found ? 0 : 1 } + ' "$config" ;; port) # [server] port = 443 diff --git a/tests/test_admin_features.py b/tests/test_admin_features.py index 91b45d6..f5bd4d5 100644 --- a/tests/test_admin_features.py +++ b/tests/test_admin_features.py @@ -2,6 +2,8 @@ import importlib.util import json import os import re +import shlex +import subprocess import sys import tempfile import unittest @@ -212,6 +214,35 @@ class AdminFeatureTests(unittest.TestCase): self.assertIn("clearInterval", app_js) self.assertIn(".auto-refresh-toggle", styles) + def test_get_config_value_secret_accepts_quoted_main_user(self): + with tempfile.TemporaryDirectory() as raw: + config = Path(raw) / "config.toml" + config.write_text( + "\n".join([ + "[access.users]", + '"main" = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"', + '"client" = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"', + "", + ]), + encoding="utf-8", + ) + script = "\n".join([ + "set -e", + f"source {shlex.quote(str(ROOT / 'lib' / 'telemt_config.sh'))}", + f"get_config_value secret {shlex.quote(str(config))}", + ]) + + result = subprocess.run( + ["bash", "-lc", script], + cwd=ROOT, + text=True, + capture_output=True, + check=False, + ) + + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(result.stdout.strip(), "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") + if __name__ == "__main__": unittest.main()