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

Default patch to 0 for macOS with osquery #813

Merged
merged 1 commit into from
Oct 5, 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
26 changes: 24 additions & 2 deletions tests/osquery/test_osquery_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,14 @@ def get_default_inventory_query_snapshot(
missing_windows_build_data=False,
unknown_windows_build=False,
macos_os_version_name=None,
macos_os_version_empty_patch=False,
):
if platform == "macos":
qs = [d.copy() for d in INVENTORY_QUERY_SNAPSHOT]
if macos_os_version_name is not None:
qs[0]["name"] = macos_os_version_name
if macos_os_version_empty_patch:
qs[0]["patch"] = ""
elif platform == "windows":
qs = [d.copy() for d in WIN_INVENTORY_QUERY_SNAPSHOT]
if no_windows_build_data:
Expand Down Expand Up @@ -448,13 +451,32 @@ def test_os_version_with_build_numbers_cleanup(self):
tree = {}
snapshot = self.get_default_inventory_query_snapshot("macos")
update_tree_with_inventory_query_snapshot(tree, snapshot)
self.assertEqual(tree["os_version"]["major"], 10)
self.assertEqual(
tree["os_version"],
{'build': '19H1824', 'major': 10, 'minor': 15, 'name': 'macOS', 'patch': 7}
)

def test_os_version_numbers_cleanup(self):
tree = {}
snapshot = self.get_default_inventory_query_snapshot("macos", macos_os_version_name="macOS")
update_tree_with_inventory_query_snapshot(tree, snapshot)
self.assertEqual(tree["os_version"]["major"], 10)
self.assertEqual(
tree["os_version"],
{'build': '19H1824', 'major': 10, 'minor': 15, 'name': 'macOS', 'patch': 7}
)

def test_os_version_numbers_empty_patch(self):
tree = {}
snapshot = self.get_default_inventory_query_snapshot(
"macos",
macos_os_version_name="macOS",
macos_os_version_empty_patch=True
)
update_tree_with_inventory_query_snapshot(tree, snapshot)
self.assertEqual(
tree["os_version"],
{'build': '19H1824', 'major': 10, 'minor': 15, 'name': 'macOS', 'patch': 0}
)

def test_osx_app_instance_schedule(self):
em = self.force_enrolled_machine()
Expand Down
3 changes: 3 additions & 0 deletions zentral/contrib/osquery/views/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def update_os_version(tree, t):
pass
else:
return
elif "macos" in name:
if "patch" not in os_version:
os_version["patch"] = 0
elif "windows" in name:
os_version = cleanup_windows_os_version(os_version)
if os_version.get("major"):
Expand Down