From dc2389067e0f0e498ff06eb9bc2d46a3becedd01 Mon Sep 17 00:00:00 2001 From: twangboy Date: Mon, 6 Jan 2020 13:04:23 -0700 Subject: [PATCH 1/2] Fix issue with whitespace in ADML data --- salt/modules/win_lgpo.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/salt/modules/win_lgpo.py b/salt/modules/win_lgpo.py index 5881987b03da..0c9c30376ad3 100644 --- a/salt/modules/win_lgpo.py +++ b/salt/modules/win_lgpo.py @@ -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 From 9639b562fd3d2d2c6f6c2fecbd93cb2936d3f772 Mon Sep 17 00:00:00 2001 From: twangboy Date: Mon, 6 Jan 2020 13:38:04 -0700 Subject: [PATCH 2/2] Add a test --- tests/unit/modules/test_win_lgpo.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/unit/modules/test_win_lgpo.py b/tests/unit/modules/test_win_lgpo.py index 719280254b54..7b54e5d8e89c 100644 --- a/tests/unit/modules/test_win_lgpo.py +++ b/tests/unit/modules/test_win_lgpo.py @@ -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 @@ -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