Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with whitespace in ADML data #55795

Merged
merged 2 commits into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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