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

[3006.x] Fix lgpo.get functions not returning all boolean values #64414

Merged
merged 5 commits into from
Jun 10, 2023
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
2 changes: 2 additions & 0 deletions changelog/63296.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixes an issue with failing subsequent state runs with the lgpo state module.
The ``lgpo.get_polcy`` function now returns all boolean settings.
2 changes: 2 additions & 0 deletions changelog/63473.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixes an issue with boolean settings not being reported after being set. The
``lgpo.get_polcy`` function now returns all boolean settings.
4 changes: 2 additions & 2 deletions salt/modules/win_lgpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6927,7 +6927,7 @@ def _checkAllAdmxPolicies(

if etree.QName(child_item).localname == "boolean":
# https://msdn.microsoft.com/en-us/library/dn605978(v=vs.85).aspx
if child_item is not None:
if len(child_item) > 0:
if (
TRUE_VALUE_XPATH(child_item)
and this_element_name not in configured_elements
Expand Down Expand Up @@ -9195,7 +9195,7 @@ def _get_policy_adm_setting(
)
if etree.QName(child_item).localname == "boolean":
# https://msdn.microsoft.com/en-us/library/dn605978(v=vs.85).aspx
if child_item is not None:
if len(child_item) > 0:
if (
TRUE_VALUE_XPATH(child_item)
and this_element_name not in configured_elements
Expand Down
148 changes: 0 additions & 148 deletions tests/pytests/unit/modules/win_lgpo/test_admx_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,154 +107,6 @@ def lgpo_bin():
yield str(sys_dir / "lgpo.exe")


def test_get_policy_name(osrelease):
if osrelease == "2022Server":
pytest.skip(f"Test is failing on {osrelease}")
if osrelease == "11":
policy_name = "Allow Diagnostic Data"
else:
policy_name = "Allow Telemetry"
result = win_lgpo.get_policy(
policy_name=policy_name,
policy_class="machine",
return_value_only=True,
return_full_policy_names=True,
hierarchical_return=False,
)
expected = "Not Configured"
assert result == expected


def test_get_policy_id():
result = win_lgpo.get_policy(
policy_name="AllowTelemetry",
policy_class="machine",
return_value_only=True,
return_full_policy_names=True,
hierarchical_return=False,
)
expected = "Not Configured"
assert result == expected


def test_get_policy_name_full_return_full_names(osrelease):
if osrelease == "2022Server":
pytest.skip(f"Test is failing on {osrelease}")
if osrelease == "11":
policy_name = "Allow Diagnostic Data"
else:
policy_name = "Allow Telemetry"
result = win_lgpo.get_policy(
policy_name=policy_name,
policy_class="machine",
return_value_only=False,
return_full_policy_names=True,
hierarchical_return=False,
)
key = "Windows Components\\Data Collection and Preview Builds\\{}"
expected = {key.format(policy_name): "Not Configured"}
assert result == expected


def test_get_policy_id_full_return_full_names(osrelease):
if osrelease == "2022Server":
pytest.skip(f"Test is failing on {osrelease}")
if osrelease == "11":
policy_name = "Allow Diagnostic Data"
else:
policy_name = "Allow Telemetry"
result = win_lgpo.get_policy(
policy_name="AllowTelemetry",
policy_class="machine",
return_value_only=False,
return_full_policy_names=True,
hierarchical_return=False,
)
key = "Windows Components\\Data Collection and Preview Builds\\{}"
expected = {key.format(policy_name): "Not Configured"}
assert result == expected


def test_get_policy_name_full_return_ids(osrelease):
if osrelease == "2022Server":
pytest.skip(f"Test is failing on {osrelease}")
if osrelease == "11":
policy_name = "Allow Diagnostic Data"
else:
policy_name = "Allow Telemetry"
result = win_lgpo.get_policy(
policy_name=policy_name,
policy_class="machine",
return_value_only=False,
return_full_policy_names=False,
hierarchical_return=False,
)
expected = {"AllowTelemetry": "Not Configured"}
assert result == expected


def test_get_policy_id_full_return_ids():
result = win_lgpo.get_policy(
policy_name="AllowTelemetry",
policy_class="machine",
return_value_only=False,
return_full_policy_names=False,
hierarchical_return=False,
)
expected = {"AllowTelemetry": "Not Configured"}
assert result == expected


def test_get_policy_id_full_return_ids_hierarchical():
result = win_lgpo.get_policy(
policy_name="AllowTelemetry",
policy_class="machine",
return_value_only=False,
return_full_policy_names=False,
hierarchical_return=True,
)
expected = {
"Computer Configuration": {
"Administrative Templates": {
"WindowsComponents": {
"DataCollectionAndPreviewBuilds": {
"AllowTelemetry": "Not Configured"
},
},
},
},
}
assert result == expected


def test_get_policy_name_return_full_names_hierarchical(osrelease):
if osrelease == "2022Server":
pytest.skip(f"Test is failing on {osrelease}")
if osrelease == "11":
policy_name = "Allow Diagnostic Data"
else:
policy_name = "Allow Telemetry"
result = win_lgpo.get_policy(
policy_name=policy_name,
policy_class="machine",
return_value_only=False,
return_full_policy_names=True,
hierarchical_return=True,
)
expected = {
"Computer Configuration": {
"Administrative Templates": {
"Windows Components": {
"Data Collection and Preview Builds": {
policy_name: "Not Configured"
}
}
}
}
}
assert result == expected


@pytest.mark.destructive_test
def test__load_policy_definitions():
"""
Expand Down
Loading