Skip to content

Commit

Permalink
Dereference symlinks to set proper __cli opt (bsc#1215963) (#611)
Browse files Browse the repository at this point in the history
* Dereference symlinks to set proper __cli

* Add changelog entry

* Add unit tests to check path is expanded

---------

Co-authored-by: vzhestkov <[email protected]>
  • Loading branch information
meaksh and vzhestkov authored Nov 13, 2023
1 parent a7c98ce commit 9942c48
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/65435.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dereference symlinks to set proper __cli opt
8 changes: 6 additions & 2 deletions salt/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3747,7 +3747,9 @@ def apply_minion_config(
)
opts["fileserver_backend"][idx] = new_val

opts["__cli"] = salt.utils.stringutils.to_unicode(os.path.basename(sys.argv[0]))
opts["__cli"] = salt.utils.stringutils.to_unicode(
os.path.basename(salt.utils.path.expand(sys.argv[0]))
)

# No ID provided. Will getfqdn save us?
using_ip_for_id = False
Expand Down Expand Up @@ -3949,7 +3951,9 @@ def apply_master_config(overrides=None, defaults=None):
)
opts["keep_acl_in_token"] = True

opts["__cli"] = salt.utils.stringutils.to_unicode(os.path.basename(sys.argv[0]))
opts["__cli"] = salt.utils.stringutils.to_unicode(
os.path.basename(salt.utils.path.expand(sys.argv[0]))
)

if "environment" in opts:
if opts["saltenv"] is not None:
Expand Down
13 changes: 13 additions & 0 deletions tests/pytests/unit/config/test_master_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import salt.config
from tests.support.mock import MagicMock, patch


def test___cli_path_is_expanded():
defaults = salt.config.DEFAULT_MASTER_OPTS.copy()
overrides = {}
with patch(
"salt.utils.path.expand", MagicMock(return_value="/path/to/testcli")
) as expand_mock:
opts = salt.config.apply_master_config(overrides, defaults)
assert expand_mock.called
assert opts["__cli"] == "testcli"
13 changes: 13 additions & 0 deletions tests/pytests/unit/config/test_minion_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import salt.config
from tests.support.mock import MagicMock, patch


def test___cli_path_is_expanded():
defaults = salt.config.DEFAULT_MINION_OPTS.copy()
overrides = {}
with patch(
"salt.utils.path.expand", MagicMock(return_value="/path/to/testcli")
) as expand_mock:
opts = salt.config.apply_minion_config(overrides, defaults)
assert expand_mock.called
assert opts["__cli"] == "testcli"

0 comments on commit 9942c48

Please sign in to comment.