Skip to content

Commit

Permalink
Add tests for new compliance types
Browse files Browse the repository at this point in the history
These tests cover the new entity types and the special cases for
handling permissions and tags referencing them.
  • Loading branch information
timopollmeier committed Dec 7, 2020
1 parent dd5f73c commit 850cdde
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/protocols/gmpv208/testtypes/test_entity_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def test_asset(self):
ct = get_entity_type_from_string('asset')
self.assertEqual(ct, EntityType.ASSET)

def test_audit(self):
ct = get_entity_type_from_string('audit')
self.assertEqual(ct, EntityType.AUDIT)

def test_cert_bund_adv(self):
ct = get_entity_type_from_string('cert_bund_adv')
self.assertEqual(ct, EntityType.CERT_BUND_ADV)
Expand Down Expand Up @@ -100,6 +104,10 @@ def test_permission(self):
ct = get_entity_type_from_string('permission')
self.assertEqual(ct, EntityType.PERMISSION)

def test_policy(self):
ct = get_entity_type_from_string('policy')
self.assertEqual(ct, EntityType.POLICY)

def test_port_list(self):
ct = get_entity_type_from_string('port_list')
self.assertEqual(ct, EntityType.PORT_LIST)
Expand Down
48 changes: 48 additions & 0 deletions tests/protocols/gmpv9/testcmds/test_create_permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,54 @@ def test_create_permission_with_resource(self):
'</create_permission>'
)

def test_create_permission_for_audit(self):
"""
Test special case where "audit" gets translated to "task"
"""
self.gmp.create_permission(
'create_task',
subject_id='u1',
subject_type=PermissionSubjectType.USER,
resource_id='t1',
resource_type=EntityType.AUDIT,
)

self.connection.send.has_been_called_with(
'<create_permission>'
'<name>create_task</name>'
'<subject id="u1">'
'<type>user</type>'
'</subject>'
'<resource id="t1">'
'<type>task</type>'
'</resource>'
'</create_permission>'
)

def test_create_permission_for_policy(self):
"""
Test special case where "policy" gets translated to "config"
"""
self.gmp.create_permission(
'create_task',
subject_id='u1',
subject_type=PermissionSubjectType.USER,
resource_id='t1',
resource_type=EntityType.POLICY,
)

self.connection.send.has_been_called_with(
'<create_permission>'
'<name>create_task</name>'
'<subject id="u1">'
'<type>user</type>'
'</subject>'
'<resource id="t1">'
'<type>config</type>'
'</resource>'
'</create_permission>'
)


if __name__ == '__main__':
unittest.main()
36 changes: 36 additions & 0 deletions tests/protocols/gmpv9/testcmds/test_create_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,42 @@ def test_create_tag_with_active(self):
'</create_tag>'
)

def test_create_tag_with_audit(self):
"""
Test special case where "audit" gets translated to "task"
"""
self.gmp.create_tag(
name='foo', resource_ids=['foo'], resource_type=EntityType.AUDIT
)

self.connection.send.has_been_called_with(
'<create_tag>'
'<name>foo</name>'
'<resources>'
'<resource id="foo"/>'
'<type>task</type>'
'</resources>'
'</create_tag>'
)

def test_create_tag_with_policy(self):
"""
Test special case where "policy" gets translated to "config"
"""
self.gmp.create_tag(
name='foo', resource_ids=['foo'], resource_type=EntityType.POLICY
)

self.connection.send.has_been_called_with(
'<create_tag>'
'<name>foo</name>'
'<resources>'
'<resource id="foo"/>'
'<type>config</type>'
'</resources>'
'</create_tag>'
)


if __name__ == '__main__':
unittest.main()
32 changes: 32 additions & 0 deletions tests/protocols/gmpv9/testcmds/test_modify_permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,38 @@ def test_modify_permission_with_name(self):
'</modify_permission>'
)

def test_modify_permission_with_resource_id_and_type(self):
"""
Test special case where "audit" gets translated to "task"
"""
self.gmp.modify_permission(
permission_id='p1', resource_id='r1', resource_type=EntityType.AUDIT
)

self.connection.send.has_been_called_with(
'<modify_permission permission_id="p1">'
'<resource id="r1">'
'<type>task</type>'
'</resource>'
'</modify_permission>'
)

def test_modify_permission_with_resource_id_and_type(self):
"""
Test special case where "policy" gets translated to "config"
"""
self.gmp.modify_permission(
permission_id='p1', resource_id='r1', resource_type=EntityType.POLICY
)

self.connection.send.has_been_called_with(
'<modify_permission permission_id="p1">'
'<resource id="r1">'
'<type>config</type>'
'</resource>'
'</modify_permission>'
)


if __name__ == '__main__':
unittest.main()
34 changes: 34 additions & 0 deletions tests/protocols/gmpv9/testcmds/test_modify_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,40 @@ def test_modify_tag_with_missing_resource_filter_and_ids(self):
'</modify_tag>'
)

def test_modify_tag_with_audit(self):
"""
Test special case where "policy" gets translated to "config"
"""
self.gmp.modify_tag(
tag_id='t1', resource_ids=['r1'], resource_type=EntityType.AUDIT
)

self.connection.send.has_been_called_with(
'<modify_tag tag_id="t1">'
'<resources>'
'<resource id="r1"/>'
'<type>task</type>'
'</resources>'
'</modify_tag>'
)

def test_modify_tag_with_audit(self):
"""
Test special case where "policy" gets translated to "config"
"""
self.gmp.modify_tag(
tag_id='t1', resource_ids=['r1'], resource_type=EntityType.POLICY
)

self.connection.send.has_been_called_with(
'<modify_tag tag_id="t1">'
'<resources>'
'<resource id="r1"/>'
'<type>config</type>'
'</resources>'
'</modify_tag>'
)


if __name__ == '__main__':
unittest.main()
8 changes: 8 additions & 0 deletions tests/protocols/gmpv9/testtypes/test_entity_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def test_agent(self):
ct = get_entity_type_from_string('agent')
self.assertEqual(ct, EntityType.AGENT)

def test_audit(self):
ct = get_entity_type_from_string('audit')
self.assertEqual(ct, EntityType.AUDIT)

def test_alert(self):
ct = get_entity_type_from_string('alert')
self.assertEqual(ct, EntityType.ALERT)
Expand Down Expand Up @@ -104,6 +108,10 @@ def test_permission(self):
ct = get_entity_type_from_string('permission')
self.assertEqual(ct, EntityType.PERMISSION)

def test_policy(self):
ct = get_entity_type_from_string('policy')
self.assertEqual(ct, EntityType.POLICY)

def test_port_list(self):
ct = get_entity_type_from_string('port_list')
self.assertEqual(ct, EntityType.PORT_LIST)
Expand Down

0 comments on commit 850cdde

Please sign in to comment.