Skip to content

Commit

Permalink
Fix set config empty values
Browse files Browse the repository at this point in the history
Fixes Bug: [#2925]
  • Loading branch information
dheyay committed Mar 15, 2024
1 parent 57a3956 commit 37df4f8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
3 changes: 3 additions & 0 deletions uaclient/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,9 @@ def action_config_set(args, *, cfg, **kwargs):
raise exceptions.InvalidArgChoice(
arg="<key>", choices=", ".join(config.UA_CONFIGURABLE_KEYS)
)
if not set_value.strip():
subparser.print_help()
raise exceptions.InvalidArgValue(arg=set_key)
if set_key in ("http_proxy", "https_proxy"):
protocol_type = set_key.split("_")[0]
if protocol_type == "http":
Expand Down
22 changes: 8 additions & 14 deletions uaclient/cli/tests/test_cli_config_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ class TestMainConfigSet:
" global_apt_https_proxy, update_messaging_timer,"
" metering_timer",
),
(
"http_proxy=",
"Empty value provided for http_proxy.",
),
(
"https_proxy= ",
"Empty value provided for https_proxy.",
),
),
)
@mock.patch("uaclient.cli.contract.get_available_resources")
Expand Down Expand Up @@ -274,13 +282,6 @@ def test_set_apt_http_proxy_and_apt_https_proxy_prints_warning(
"https://proxy",
"https://proxy",
),
(
"global_apt_http_proxy",
"",
apt.AptProxyScope.GLOBAL,
"https://proxy",
"https://proxy",
),
),
)
@mock.patch("uaclient.cli.configure_apt_proxy")
Expand Down Expand Up @@ -384,13 +385,6 @@ def test_set_global_apt_http_and_global_apt_https_proxy(
"https://proxy",
"https://proxy",
),
(
"ua_apt_https_proxy",
"",
apt.AptProxyScope.UACLIENT,
"https://proxy",
"https://proxy",
),
),
)
@mock.patch("uaclient.cli.configure_apt_proxy")
Expand Down
5 changes: 4 additions & 1 deletion uaclient/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ class EntitlementNotFoundError(UbuntuProError):


class EntitlementsNotEnabledError(UbuntuProError):

exit_code = 4
_msg = messages.E_ENTITLEMENTS_NOT_ENABLED_ERROR

Expand Down Expand Up @@ -496,6 +495,10 @@ class InvalidArgChoice(UbuntuProError):
_formatted_msg = messages.E_CLI_VALID_CHOICES


class InvalidArgValue(UbuntuProError):
_formatted_msg = messages.E_CLI_VALID_VALUE


class GenericInvalidFormat(UbuntuProError):
_formatted_msg = messages.E_CLI_EXPECTED_FORMAT

Expand Down
5 changes: 5 additions & 0 deletions uaclient/messages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2425,6 +2425,11 @@ def __repr__(self):
"invalid-arg-choice", "\n" + t.gettext("{arg} must be one of: {choices}")
)

E_CLI_VALID_VALUE = FormattedNamedMessage(
"empty-value",
t.gettext("Empty value provided for {arg}."),
)

E_CLI_EXPECTED_FORMAT = FormattedNamedMessage(
"generic-invalid-format",
"\n" + t.gettext("Expected {expected} but found: {actual}"),
Expand Down

0 comments on commit 37df4f8

Please sign in to comment.