This repository has been archived by the owner on Aug 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AzStorageAccountAllowTrustedServicesEvent tests
Added test cases for the `AzStorageAccountAllowTrustedServicesEvent` plugin. Also, in this commit a few changes have been made to the `AzStorageAccountAllowTrustedServicesEvent` plugin to take care of the corner cases.
- Loading branch information
1 parent
e4d0ac6
commit 5ecdb4c
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
cloudmarker/test/test_azstorageaccountallowtrustedservicesevent.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
"""Tests for AzStorageAccountAllowTrustedServicesEvent plugin.""" | ||
|
||
|
||
import copy | ||
import unittest | ||
|
||
from cloudmarker.events import azstorageaccountallowtrustedservicesevent | ||
|
||
base_record = { | ||
'com': { | ||
'cloud_type': 'azure', | ||
'record_type': 'storage_account_properties', | ||
}, | ||
'ext': { | ||
'record_type': 'storage_account_properties', | ||
'trusted_services_allowed': False | ||
} | ||
} | ||
|
||
|
||
class AzStorageAccountAllowTrustedServicesEventTest(unittest.TestCase): | ||
"""Tests for AzStorageAccountAllowTrustedServicesEvent plugin.""" | ||
|
||
def test_com_bucket_missing(self): | ||
record = copy.deepcopy(base_record) | ||
record['com'] = None | ||
plugin = azstorageaccountallowtrustedservicesevent. \ | ||
AzStorageAccountAllowTrustedServicesEvent() | ||
events = list(plugin.eval(record)) | ||
self.assertEqual(events, []) | ||
|
||
def test_cloud_non_azure(self): | ||
record = copy.deepcopy(base_record) | ||
record['com']['cloud_type'] = 'non_azure' | ||
plugin = azstorageaccountallowtrustedservicesevent. \ | ||
AzStorageAccountAllowTrustedServicesEvent() | ||
events = list(plugin.eval(record)) | ||
self.assertEqual(events, []) | ||
|
||
def test_record_type_non_storage_account_properties(self): | ||
record = copy.deepcopy(base_record) | ||
record['ext']['record_type'] = 'non_storage_account_properties' | ||
plugin = azstorageaccountallowtrustedservicesevent. \ | ||
AzStorageAccountAllowTrustedServicesEvent() | ||
events = list(plugin.eval(record)) | ||
self.assertEqual(events, []) | ||
|
||
def test_ext_bucket_missing(self): | ||
record = copy.deepcopy(base_record) | ||
record['ext'] = None | ||
plugin = azstorageaccountallowtrustedservicesevent. \ | ||
AzStorageAccountAllowTrustedServicesEvent() | ||
events = list(plugin.eval(record)) | ||
self.assertEqual(events, []) | ||
|
||
def test_trusted_services_allowed(self): | ||
record = copy.deepcopy(base_record) | ||
record['ext']['trusted_services_allowed'] = True | ||
plugin = azstorageaccountallowtrustedservicesevent. \ | ||
AzStorageAccountAllowTrustedServicesEvent() | ||
events = list(plugin.eval(record)) | ||
self.assertEqual(events, []) | ||
|
||
def test_trusted_services_not_allowed(self): | ||
record = copy.deepcopy(base_record) | ||
plugin = azstorageaccountallowtrustedservicesevent. \ | ||
AzStorageAccountAllowTrustedServicesEvent() | ||
events = list(plugin.eval(record)) | ||
self.assertEqual(len(events), 1) | ||
self.assertEqual(events[0]['ext']['record_type'], | ||
'storage_account_allow_trusted_services_event') | ||
self.assertEqual(events[0]['com']['cloud_type'], | ||
'azure') | ||
self.assertEqual(events[0]['com']['record_type'], | ||
'storage_account_allow_trusted_services_event') | ||
self.assertTrue('reference' in events[0]['com']) | ||
self.assertIsNotNone(events[0]['com']['description']) | ||
self.assertIsNotNone(events[0]['com']['recommendation']) |