Skip to content

Commit

Permalink
Allow all primitive grain types for autosign_grains
Browse files Browse the repository at this point in the history
  • Loading branch information
agraul authored and Megan Wilhite committed Oct 9, 2023
1 parent 6e64117 commit 31146ea
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 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 @@ -380,7 +380,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
7 changes: 4 additions & 3 deletions tests/pytests/unit/daemons/masterapi/test_auto_key.py
Original file line number Diff line number Diff line change
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 31146ea

Please sign in to comment.