fix: multiple fixes + cleanup and formatting
This commit is contained in:
59 files changed
+1357
-920
No files matched your search
@@ -377,7 +377,12 @@ def cmd_tor(verb="status", *args):
|
||||
usage("tor [status|on|off|newnym]")
|
||||
_toggle(unit, "tor", verb, *args)
|
||||
if verb == "status" and svc_active(unit):
|
||||
print(f"bootstrap {_tor_bootstrap()}")
|
||||
# Extra detail: the unit's state stands without it, for a user outside the group
|
||||
# or a Tor that has not opened its socket yet. The reason is on stderr.
|
||||
try:
|
||||
print(f"bootstrap {_tor_bootstrap()}")
|
||||
except SystemExit:
|
||||
print("bootstrap unknown")
|
||||
|
||||
|
||||
def _emit(text, qr):
|
||||
@@ -1279,7 +1284,8 @@ def cmd_pin(tag="", *_):
|
||||
# Dismissed.
|
||||
if status or not tag:
|
||||
return
|
||||
if os.path.exists(_outbound_disabled_marker(tag)):
|
||||
# The inventory too: the marker sits in a dir only root and the group can look into.
|
||||
if os.path.exists(_outbound_disabled_marker(tag)) or tag in _outbound_disabled():
|
||||
die(f"Outbound '{tag}' is disabled; enable it first: proxy-ctl proxy outbounds enable {tag}")
|
||||
status, escaped = _run(["systemd-escape", "--", tag], capture=True)
|
||||
if status:
|
||||
@@ -1481,6 +1487,9 @@ def _runtime_entry_rm(kind, tag="", *_):
|
||||
usage(f"proxy {_runtime_noun(kind)} rm <tag>")
|
||||
path = _runtime_path(kind, tag)
|
||||
if not os.path.exists(path):
|
||||
# The dir may be root-only: an entry that is there looks absent from outside it.
|
||||
if _runtime_hidden(kind):
|
||||
die(f"Cannot see the entry for '{tag}' in {_runtime_dir(kind)} - {ask_group()}")
|
||||
die(f"No runtime {kind} named '{tag}'. Ones declared in the NixOS configuration are removed there.")
|
||||
try:
|
||||
os.unlink(path)
|
||||
|
||||
@@ -307,7 +307,8 @@ def inbound_rows(_):
|
||||
# A listener behind the onion service has a second row, for its .onion link.
|
||||
return [
|
||||
{
|
||||
"key": "/".join(ctl._s(x.get(k) or "") for k in ("tag", "user", "variant")),
|
||||
# The TUI titles its menu with the key: no trailing "/" for the plain link.
|
||||
"key": "/".join(ctl._s(x.get(k)) for k in ("tag", "user", "variant") if x.get(k)),
|
||||
**{k: ctl._s(x.get(k) or "") for k in ("tag", "user", "type", "port", "variant")},
|
||||
**({"type": f"{ctl._s(x.get('type') or '')} (onion)"} if x.get("variant") == "onion" else {}),
|
||||
}
|
||||
|
||||
@@ -540,6 +540,19 @@ class RuntimeEntryTest(EnvTest):
|
||||
self.assertNotEqual(run(ctl.cmd_outbounds, "enable", "primary")[0], 0)
|
||||
self.assertNotEqual(run(ctl.cmd_outbounds, "enable", "../primary")[0], 0)
|
||||
|
||||
@unittest.skipIf(os.geteuid() == 0, "root reads anything")
|
||||
def test_rm_says_so_when_the_dir_is_out_of_reach(self):
|
||||
"""outbounds.d is root-only without the group: the entry is there, it just cannot be seen."""
|
||||
ok(ctl.cmd_outbounds, "add", "de", "vless://u@de.test:443")
|
||||
os.chmod(self.path("outbounds.d"), 0o000)
|
||||
try:
|
||||
status, _, err = run(ctl.cmd_outbounds, "rm", "de")
|
||||
finally:
|
||||
os.chmod(self.path("outbounds.d"), 0o700)
|
||||
self.assertNotEqual(status, 0)
|
||||
self.assertIn("Cannot see the entry for 'de'", err)
|
||||
self.assertNotIn("No runtime outbound", err)
|
||||
|
||||
def test_rm_takes_the_marker_along(self):
|
||||
ok(ctl.cmd_outbounds, "add", "de", "vless://u@de.test:443")
|
||||
ok(ctl.cmd_outbounds, "disable", "de")
|
||||
@@ -955,6 +968,11 @@ class TorTest(EnvTest):
|
||||
self.assertNotEqual(status, 0)
|
||||
self.assertIn("not running", err)
|
||||
self.assertNotEqual(run(ctl.cmd_tor, "bogus")[0], 0)
|
||||
# Status still reports the unit.
|
||||
status, out, err = run(ctl.cmd_tor)
|
||||
self.assertEqual(status, 0)
|
||||
self.assertIn("bootstrap unknown", out)
|
||||
self.assertIn("not running", err)
|
||||
|
||||
|
||||
class BadExitTest(EnvTest):
|
||||
|
||||
@@ -114,7 +114,7 @@ class ModelTest(unittest.TestCase):
|
||||
]
|
||||
with mock.patch.object(ctl, "_inbound_links", lambda: links):
|
||||
plain, onion = model.inbound_rows({})
|
||||
self.assertNotEqual(plain["key"], onion["key"])
|
||||
self.assertEqual((plain["key"], onion["key"]), ("ws/alice", "ws/alice/onion"))
|
||||
self.assertEqual((plain["type"], onion["type"]), ("vless", "vless (onion)"))
|
||||
self.assertEqual(model._link(plain, "--qr"), ["inbounds", "link", "ws", "alice", "--qr"])
|
||||
self.assertEqual(model._link(onion, "--qr"), ["inbounds", "link", "ws", "alice", "--onion", "--qr"])
|
||||
|
||||
Reference in new issue
Block a user