Skip to content

Commit

Permalink
Merge pull request #55795 from twangboy/fix_win_lgpo
Browse files Browse the repository at this point in the history
Fix issue with whitespace in ADML data
  • Loading branch information
dwoz authored Jan 7, 2020
2 parents ed9dd37 + 9639b56 commit 1f50bb2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion salt/modules/win_lgpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5639,7 +5639,9 @@ def _getAdmlDisplayName(adml_xml_data, display_name):
displayNameId=displayname_id)
if search_results:
for result in search_results:
return result.text
# Needs the `strip()` because some adml data has an extra space
# at the end
return result.text.strip()

return None

Expand Down
13 changes: 13 additions & 0 deletions tests/unit/modules/test_win_lgpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# Import Salt Testing Libs
from tests.support.helpers import destructiveTest
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.mock import MagicMock, Mock, patch
from tests.support.unit import TestCase, skipIf

# Import Salt Libs
Expand Down Expand Up @@ -47,6 +48,18 @@ class WinLGPOTestCase(TestCase):
'''
encoded_null = chr(0).encode('utf-16-le')

def test__getAdmlDisplayName(self):
display_name = '$(string.KeepAliveTime1)'
adml_xml_data = 'junk, we are mocking the return'
obj_xpath = Mock()
obj_xpath.text = '300000 or 5 minutes (recommended) '
mock_xpath_obj = MagicMock(return_value=[obj_xpath])
with patch.object(win_lgpo, 'ADML_DISPLAY_NAME_XPATH', mock_xpath_obj):
result = win_lgpo._getAdmlDisplayName(adml_xml_data=adml_xml_data,
display_name=display_name)
expected = '300000 or 5 minutes (recommended)'
self.assertEqual(result, expected)

def test__encode_string(self):
'''
``_encode_string`` should return a null terminated ``utf-16-le`` encoded
Expand Down

0 comments on commit 1f50bb2

Please sign in to comment.