Skip to content

Commit

Permalink
Allow all primitive grain types for autosign_grains (#607)
Browse files Browse the repository at this point in the history
* Allow all primitive grain types for autosign_grains

Signed-off-by: Marek Czernek <[email protected]>

* blacken daemons/masterapi.py and its test_auto_key

Signed-off-by: Marek Czernek <[email protected]>

---------

Signed-off-by: Marek Czernek <[email protected]>
Co-authored-by: Alexander Graul <[email protected]>
  • Loading branch information
m-czernek and agraul authored Oct 17, 2023
1 parent dea33d8 commit ae4e1d1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog/61416.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow all primitive grain types for autosign_grains
1 change: 1 addition & 0 deletions changelog/63708.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow all primitive grain types for autosign_grains
2 changes: 1 addition & 1 deletion salt/daemons/masterapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def check_autosign_grains(self, autosign_grains):
line = salt.utils.stringutils.to_unicode(line).strip()
if line.startswith("#"):
continue
if autosign_grains[grain] == line:
if str(autosign_grains[grain]) == line:
return True
return False

Expand Down
13 changes: 7 additions & 6 deletions tests/pytests/unit/daemons/masterapi/test_auto_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def gen_permissions(owner="", group="", others=""):
"""
ret = 0
for c in owner:
ret |= getattr(stat, "S_I{}USR".format(c.upper()), 0)
ret |= getattr(stat, f"S_I{c.upper()}USR", 0)
for c in group:
ret |= getattr(stat, "S_I{}GRP".format(c.upper()), 0)
ret |= getattr(stat, f"S_I{c.upper()}GRP", 0)
for c in others:
ret |= getattr(stat, "S_I{}OTH".format(c.upper()), 0)
ret |= getattr(stat, f"S_I{c.upper()}OTH", 0)
return ret


Expand Down Expand Up @@ -256,16 +256,17 @@ def test_func(mock_walk, mock_open, mock_permissions):
_test_check_autosign_grains(test_func, auto_key, autosign_grains_dir=None)


def test_check_autosign_grains_accept(auto_key):
@pytest.mark.parametrize("grain_value", ["test_value", 123, True])
def test_check_autosign_grains_accept(grain_value, auto_key):
"""
Asserts that autosigning from grains passes when a matching grain value is in an
autosign_grain file.
"""

def test_func(*args):
assert auto_key.check_autosign_grains({"test_grain": "test_value"}) is True
assert auto_key.check_autosign_grains({"test_grain": grain_value}) is True

file_content = "#test_ignore\ntest_value"
file_content = f"#test_ignore\n{grain_value}"
_test_check_autosign_grains(test_func, auto_key, file_content=file_content)


Expand Down

0 comments on commit ae4e1d1

Please sign in to comment.