mirror of
https://github.com/anten-ka/gotelegram_pro.git
synced 2026-05-19 15:46:02 +00:00
v2.5.0: read quoted main proxy secret
This commit is contained in:
@@ -132,13 +132,24 @@ get_config_value() {
|
|||||||
awk '
|
awk '
|
||||||
/^\[access\.users\]/ { in_users=1; next }
|
/^\[access\.users\]/ { in_users=1; next }
|
||||||
/^\[/ && in_users { exit }
|
/^\[/ && in_users { exit }
|
||||||
in_users && $1 == "main" {
|
in_users && /^[[:space:]]*[^#[:space:]][^=]*=/ {
|
||||||
sub(/^[^=]*=[[:space:]]*"/, "")
|
user_key=$1
|
||||||
sub(/".*$/, "")
|
gsub(/"/, "", user_key)
|
||||||
print
|
if (user_key != "main") next
|
||||||
|
|
||||||
|
value=$0
|
||||||
|
sub(/^[^=]*=[[:space:]]*/, "", value)
|
||||||
|
sub(/^"/, "", value)
|
||||||
|
sub(/".*$/, "", value)
|
||||||
|
gsub(/[[:space:]]/, "", value)
|
||||||
|
if (value != "") {
|
||||||
|
print value
|
||||||
|
found=1
|
||||||
|
}
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
' "$config" | tr -d ' '
|
END { exit found ? 0 : 1 }
|
||||||
|
' "$config"
|
||||||
;;
|
;;
|
||||||
port)
|
port)
|
||||||
# [server] port = 443
|
# [server] port = 443
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import importlib.util
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import shlex
|
||||||
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
@@ -212,6 +214,35 @@ class AdminFeatureTests(unittest.TestCase):
|
|||||||
self.assertIn("clearInterval", app_js)
|
self.assertIn("clearInterval", app_js)
|
||||||
self.assertIn(".auto-refresh-toggle", styles)
|
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__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user