Read the environment with typed parsers and apply the documented defaults
set_defaults() assigned os.getenv() results directly, which overwrote the argparse defaults with None whenever a variable was unset. A default container therefore ran "seaf-cli config -k delete_confirm_threshold -v None", and the same for upload_limit and download_limit: none of the three documented defaults were ever applied. SEAFILE_UID and SEAFILE_GID had a second problem. argparse type=int applies only to command line flags, never to set_defaults, so both stayed strings. The check in setup_uid compares them against pwd integers, and a string is never equal to one, so usermod ran on every start. dsc/config.py reads each variable with its documented default and rejects a malformed or negative value at startup, naming the variable, instead of passing it on. An empty variable counts as unset. Booleans are now rendered as true and false rather than Python's True and False. The daemon reads disable_verify_certificate with its boolean accessor, which does not recognise the capitalised form. I could not run the daemon to confirm the previous value's effect, since the AppImage is x86_64 only. seaf-cli is no longer given a None value for any option.
This commit is contained in:
1 parent
87b76b80f6
commit
e6034a69a6
8 files changed
+283
-26
No files matched your search
+31
-1
@@ -8,7 +8,7 @@ import pytest
|
||||
|
||||
from dsc import client as client_module
|
||||
from dsc import const
|
||||
from dsc.errors import DaemonError
|
||||
from dsc.errors import ConfigError, DaemonError
|
||||
from dsc.client import SeafileClient
|
||||
from dsc.misc import hide_secrets, user_cmd
|
||||
|
||||
@@ -235,3 +235,33 @@ def test_local_libraries_error_keeps_the_original_cause(client, monkeypatch):
|
||||
with pytest.raises(DaemonError) as err:
|
||||
client.get_local_libraries()
|
||||
assert err.value.__cause__ is not None
|
||||
|
||||
|
||||
def test_configure_never_sends_none_as_a_value(client, calls):
|
||||
"""A None here reaches seaf-cli as the literal string "None"."""
|
||||
with pytest.raises(ConfigError):
|
||||
client.configure(argparse.Namespace(upload_limit=None), check_for_daemon=False)
|
||||
|
||||
for argv, _ in calls:
|
||||
assert "None" not in argv
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value, expected", [
|
||||
(True, "true"),
|
||||
(False, "false"),
|
||||
(0, "0"),
|
||||
(500, "500"),
|
||||
])
|
||||
def test_configure_renders_values_the_way_seaf_cli_stores_them(
|
||||
client, calls, monkeypatch, value, expected):
|
||||
# Changing an option restarts the daemon; keep this on the value only.
|
||||
monkeypatch.setattr(client, "stop_daemon", lambda: None)
|
||||
monkeypatch.setattr(client, "start_daemon", lambda: None)
|
||||
|
||||
client.configure(argparse.Namespace(disable_verify_certificate=value)
|
||||
if isinstance(value, bool)
|
||||
else argparse.Namespace(upload_limit=value),
|
||||
check_for_daemon=False)
|
||||
|
||||
setting = [argv for argv, _ in calls if "-v" in argv][-1]
|
||||
assert setting[setting.index("-v") + 1] == expected
|
||||
Reference in new issue
Block a user