Skip to content

Commit

Permalink
add processing of scope tags
Browse files Browse the repository at this point in the history
  • Loading branch information
almenscorner committed Feb 27, 2024
1 parent 50c207f commit 24d4e3a
Show file tree
Hide file tree
Showing 15 changed files with 451 additions and 5 deletions.
39 changes: 39 additions & 0 deletions tests/Backup/Intune/test_backup_apns.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,41 @@ def setUp(self):
"certificateSerialNumber": "11000000000000",
"certificate": None,
}
self.audit_data = {
"value": [
{
"resources": [
{"resourceId": "0", "auditResourceType": "MagicResource"}
],
"activityDateTime": "2021-01-01T00:00:00Z",
"activityOperationType": "Patch",
"activityResult": "Success",
"actor": [{"auditActorType": "ItPro"}],
}
]
}

self.makeapirequest_patch = patch(
"src.IntuneCD.backup.Intune.backup_apns.makeapirequest"
)
self.makeapirequest = self.makeapirequest_patch.start()

self.makeAuditRequest_patch = patch(
"src.IntuneCD.backup.Intune.backup_apns.makeAuditRequest"
)
self.makeAuditRequest = self.makeAuditRequest_patch.start()
self.makeAuditRequest.return_value = self.audit_data

self.process_audit_data_patch = patch(
"src.IntuneCD.backup.Intune.backup_apns.process_audit_data"
)
self.process_audit_data = self.process_audit_data_patch.start()

def tearDown(self):
self.directory.cleanup()
self.makeapirequest_patch.stop()
self.makeAuditRequest_patch.stop()
self.process_audit_data_patch.stop()

def test_backup_yml(self):
"""The folder should be created, the file should have the expected contents, and the count should be 1."""
Expand Down Expand Up @@ -88,6 +114,19 @@ def test_backup_with_no_return_data(self):
self.count = savebackup(self.directory.path, "json", False, self.token)
self.assertEqual(0, self.count["config_count"])

def test_backup_audit(self):
"""The folder should be created, the file should have the expected contents, and the count should be 1."""

self.makeapirequest.return_value = self.apns
self.count = savebackup(self.directory.path, "json", True, self.token)

with open(self.saved_path + "json", "r", encoding="utf-8") as f:
saved_data = json.load(f)

self.assertTrue(Path(f"{self.directory.path}/Apple Push Notification").exists())
self.assertEqual(self.expected_data, saved_data)
self.assertEqual(1, self.count["config_count"])


if __name__ == "__main__":
unittest.main()
49 changes: 48 additions & 1 deletion tests/Backup/Intune/test_backup_appConfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def setUp(self):
"@odata.type": "#microsoft.graph.iosMobileAppConfiguration",
"assignments": [{"target": {"groupName": "Group1"}}],
"displayName": "test",
"scopeTagIds": ["0"],
"settings": [
{
"appConfigKey": "sharedDevice",
Expand All @@ -54,6 +55,7 @@ def setUp(self):
"id": "0",
"targetedMobileApps": ["0"],
"displayName": "test",
"scopeTagIds": ["0"],
"settings": [
{
"appConfigKey": "sharedDevice",
Expand All @@ -74,6 +76,19 @@ def setUp(self):
"applicableDeviceType": {"iPhoneAndIPod": True},
"revokeLicenseActionResults": [],
}
self.audit_data = {
"value": [
{
"resources": [
{"resourceId": "0", "auditResourceType": "MagicResource"}
],
"activityDateTime": "2021-01-01T00:00:00Z",
"activityOperationType": "Patch",
"activityResult": "Success",
"actor": [{"auditActorType": "ItPro"}],
}
]
}

self.batch_assignment_patch = patch(
"src.IntuneCD.backup.Intune.backup_appConfiguration.batch_assignment"
Expand All @@ -93,11 +108,18 @@ def setUp(self):
self.makeapirequest = self.makeapirequest_patch.start()
self.makeapirequest.side_effect = self.app_config, self.app_data

self.makeAuditRequest_patch = patch(
"src.IntuneCD.backup.Intune.backup_appConfiguration.makeAuditRequest"
)
self.makeAuditRequest = self.makeAuditRequest_patch.start()
self.makeAuditRequest.return_value = self.audit_data

def tearDown(self):
self.directory.cleanup()
self.batch_assignment.stop()
self.object_assignment.stop()
self.makeapirequest.stop()
self.makeAuditRequest.stop()

def test_backup_yml(self):
"""The folder should be created, the file should have the expected contents, and the count should be 1."""
Expand All @@ -110,6 +132,7 @@ def test_backup_yml(self):
"",
self.append_id,
False,
[{"id": 0, "displayName": "default"}],
)

with open(self.saved_path + "yaml", "r", encoding="utf-8") as f:
Expand All @@ -131,6 +154,7 @@ def test_backup_json(self):
"",
self.append_id,
False,
None,
)

with open(self.saved_path + "json", "r", encoding="utf-8") as f:
Expand All @@ -151,6 +175,7 @@ def test_backup_with_no_returned_data(self):
"",
self.append_id,
False,
None,
)

self.assertEqual(0, self.count["config_count"])
Expand All @@ -165,6 +190,7 @@ def test_backup_with_prefix(self):
"test1",
self.append_id,
False,
None,
)

self.assertEqual(0, self.count["config_count"])
Expand All @@ -173,7 +199,7 @@ def test_backup_append_id(self):
"""The folder should be created, the file should have the expected contents, and the count should be 1."""

self.count = savebackup(
self.directory.path, "yaml", self.exclude, self.token, "", True, False
self.directory.path, "yaml", self.exclude, self.token, "", True, False, None
)

self.assertTrue(
Expand All @@ -182,6 +208,27 @@ def test_backup_append_id(self):
).exists()
)

def test_backup_scope_tag_and_audit(self):
"""The folder should be created, the file should have the expected contents, and the count should be 1."""
self.count = savebackup(
self.directory.path,
"yaml",
self.exclude,
self.token,
"",
self.append_id,
True,
[{"id": 0, "displayName": "default"}],
)

with open(self.saved_path + "yaml", "r", encoding="utf-8") as f:
data = json.dumps(yaml.safe_load(f))
saved_data = json.loads(data)

self.assertTrue(Path(f"{self.directory.path}/App Configuration").exists())
self.assertEqual(self.expected_data, saved_data)
self.assertEqual(1, self.count["config_count"])


if __name__ == "__main__":
unittest.main()
39 changes: 39 additions & 0 deletions tests/Backup/Intune/test_backup_appleEnrollmentProfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ def setUp(self):
]
}
]
self.audit_data = {
"value": [
{
"resources": [
{"resourceId": "0", "auditResourceType": "MagicResource"}
],
"activityDateTime": "2021-01-01T00:00:00Z",
"activityOperationType": "Patch",
"activityResult": "Success",
"actor": [{"auditActorType": "ItPro"}],
}
]
}

self.patch_makeapirequest = patch(
"src.IntuneCD.backup.Intune.backup_appleEnrollmentProfile.makeapirequest"
Expand All @@ -73,10 +86,23 @@ def setUp(self):
)
self.batch_request = self.patch_batch_request.start()

self.makeAuditRequest_patch = patch(
"src.IntuneCD.backup.Intune.backup_appleEnrollmentProfile.makeAuditRequest"
)
self.makeAuditRequest = self.makeAuditRequest_patch.start()
self.makeAuditRequest.return_value = self.audit_data

self.process_audit_data_patch = patch(
"src.IntuneCD.backup.Intune.backup_appleEnrollmentProfile.process_audit_data"
)
self.process_audit_data = self.process_audit_data_patch.start()

def tearDown(self):
self.directory.cleanup()
self.patch_batch_request.stop()
self.patch_makeapirequest.stop()
self.makeAuditRequest_patch.stop()
self.process_audit_data_patch.stop()

def test_backup_yml(self):
"""The folder should be created, the file should have the expected contents, and the count should be 1."""
Expand Down Expand Up @@ -149,6 +175,19 @@ def test_backup_append_id(self):
).exists()
)

def test_backup_audit(self):
"""The folder should be created, the file should have the expected contents, and the count should be 1."""
self.makeapirequest.return_value = self.token_response
self.batch_request.return_value = self.batch_intune

self.count = savebackup(self.directory.path, "json", self.token, "", True, True)

self.assertTrue(
Path(
f"{self.directory.path}/Enrollment Profiles/Apple/test__0.json"
).exists()
)


if __name__ == "__main__":
unittest.main()
39 changes: 39 additions & 0 deletions tests/Backup/Intune/test_backup_compliancePartner.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,42 @@ def setUp(self):
}
]
}
self.audit_data = {
"value": [
{
"resources": [
{"resourceId": "0", "auditResourceType": "MagicResource"}
],
"activityDateTime": "2021-01-01T00:00:00Z",
"activityOperationType": "Patch",
"activityResult": "Success",
"actor": [{"auditActorType": "ItPro"}],
}
]
}

self.patch_makeapirequest = patch(
"src.IntuneCD.backup.Intune.backup_compliancePartner.makeapirequest",
return_value=self.compliance_partner,
)
self.makeapirequest = self.patch_makeapirequest.start()

self.makeAuditRequest_patch = patch(
"src.IntuneCD.backup.Intune.backup_compliancePartner.makeAuditRequest"
)
self.makeAuditRequest = self.makeAuditRequest_patch.start()
self.makeAuditRequest.return_value = self.audit_data

self.process_audit_data_patch = patch(
"src.IntuneCD.backup.Intune.backup_compliancePartner.process_audit_data"
)
self.process_audit_data = self.process_audit_data_patch.start()

def tearDown(self):
self.directory.cleanup()
self.makeapirequest.stop()
self.makeAuditRequest_patch.stop()
self.process_audit_data_patch.stop()

def test_backup_yml(self):
"""The folder should be created, the file should have the expected contents, and the count should be 1."""
Expand Down Expand Up @@ -135,6 +161,19 @@ def test_backup_exclude_lastHeartbeatDateTime(self):

self.assertNotIn("lastHeartbeatDateTime", saved_data)

def test_backup_audit(self):
"""The folder should be created, the file should have the expected contents, and the count should be 1."""

self.count = savebackup(
self.directory.path, "json", self.exclude, self.token, True, True
)

self.assertTrue(
Path(
f"{self.directory.path}/Partner Connections/Compliance/test__0.json"
).exists()
)


if __name__ == "__main__":
unittest.main()
40 changes: 40 additions & 0 deletions tests/Backup/Intune/test_backup_deviceManagementSettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,35 @@ def setUp(self):
"enableEnhancedTroubleshootingExperience": False,
"enableDeviceGroupMembershipReport": False,
}
self.audit_data = {
"value": [
{
"resources": [
{"resourceId": "0", "auditResourceType": "MagicResource"}
],
"activityDateTime": "2021-01-01T00:00:00Z",
"activityOperationType": "Patch",
"activityResult": "Success",
"actor": [{"auditActorType": "ItPro"}],
}
]
}

self.makeAuditRequest_patch = patch(
"src.IntuneCD.backup.Intune.backup_deviceManagementSettings.makeAuditRequest"
)
self.makeAuditRequest = self.makeAuditRequest_patch.start()
self.makeAuditRequest.return_value = self.audit_data

self.process_audit_data_patch = patch(
"src.IntuneCD.backup.Intune.backup_deviceManagementSettings.process_audit_data"
)
self.process_audit_data = self.process_audit_data_patch.start()

def tearDown(self):
self.directory.cleanup()
self.makeAuditRequest_patch.stop()
self.process_audit_data_patch.stop()

def test_backup_yml(self, _, __):
"""The folder should be created, the file should have the expected contents, and the count should be 1."""
Expand Down Expand Up @@ -91,6 +117,20 @@ def test_backup_json(self, _, __):
self.assertEqual(self.expected_data, self.saved_data)
self.assertEqual(1, self.count["config_count"])

def test_backup_audit(self, _, __):
"""The folder should be created, the file should have the expected contents, and the count should be 1."""

self.count = savebackup(self.directory.path, "json", True, self.token)

with open(self.saved_path + "json", "r", encoding="utf-8") as f:
self.saved_data = json.load(f)

self.assertTrue(
Path(f"{self.directory.path}/Device Management Settings").exists()
)
self.assertEqual(self.expected_data, self.saved_data)
self.assertEqual(1, self.count["config_count"])


if __name__ == "__main__":
unittest.main()
Loading

0 comments on commit 24d4e3a

Please sign in to comment.