From 850cdde8144cc038d7db722f7e13f46cf40cb95f Mon Sep 17 00:00:00 2001 From: Timo Pollmeier Date: Mon, 7 Dec 2020 10:35:23 +0100 Subject: [PATCH] Add tests for new compliance types These tests cover the new entity types and the special cases for handling permissions and tags referencing them. --- .../gmpv208/testtypes/test_entity_type.py | 8 ++++ .../gmpv9/testcmds/test_create_permission.py | 48 +++++++++++++++++++ .../gmpv9/testcmds/test_create_tag.py | 36 ++++++++++++++ .../gmpv9/testcmds/test_modify_permission.py | 32 +++++++++++++ .../gmpv9/testcmds/test_modify_tag.py | 34 +++++++++++++ .../gmpv9/testtypes/test_entity_type.py | 8 ++++ 6 files changed, 166 insertions(+) diff --git a/tests/protocols/gmpv208/testtypes/test_entity_type.py b/tests/protocols/gmpv208/testtypes/test_entity_type.py index 7980e8d75..a22a420a3 100644 --- a/tests/protocols/gmpv208/testtypes/test_entity_type.py +++ b/tests/protocols/gmpv208/testtypes/test_entity_type.py @@ -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) @@ -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) diff --git a/tests/protocols/gmpv9/testcmds/test_create_permission.py b/tests/protocols/gmpv9/testcmds/test_create_permission.py index f32d7d18f..0a55c4d8b 100644 --- a/tests/protocols/gmpv9/testcmds/test_create_permission.py +++ b/tests/protocols/gmpv9/testcmds/test_create_permission.py @@ -137,6 +137,54 @@ def test_create_permission_with_resource(self): '' ) + 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_task' + '' + 'user' + '' + '' + 'task' + '' + '' + ) + + 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_task' + '' + 'user' + '' + '' + 'config' + '' + '' + ) + if __name__ == '__main__': unittest.main() diff --git a/tests/protocols/gmpv9/testcmds/test_create_tag.py b/tests/protocols/gmpv9/testcmds/test_create_tag.py index 3b83d85f3..16df4baa6 100644 --- a/tests/protocols/gmpv9/testcmds/test_create_tag.py +++ b/tests/protocols/gmpv9/testcmds/test_create_tag.py @@ -232,6 +232,42 @@ def test_create_tag_with_active(self): '' ) + 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( + '' + 'foo' + '' + '' + 'task' + '' + '' + ) + + 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( + '' + 'foo' + '' + '' + 'config' + '' + '' + ) + if __name__ == '__main__': unittest.main() diff --git a/tests/protocols/gmpv9/testcmds/test_modify_permission.py b/tests/protocols/gmpv9/testcmds/test_modify_permission.py index 6a444cd78..52aed41c8 100644 --- a/tests/protocols/gmpv9/testcmds/test_modify_permission.py +++ b/tests/protocols/gmpv9/testcmds/test_modify_permission.py @@ -179,6 +179,38 @@ def test_modify_permission_with_name(self): '' ) + 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( + '' + '' + 'task' + '' + '' + ) + + 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( + '' + '' + 'config' + '' + '' + ) + if __name__ == '__main__': unittest.main() diff --git a/tests/protocols/gmpv9/testcmds/test_modify_tag.py b/tests/protocols/gmpv9/testcmds/test_modify_tag.py index 67a97112a..5936fc657 100644 --- a/tests/protocols/gmpv9/testcmds/test_modify_tag.py +++ b/tests/protocols/gmpv9/testcmds/test_modify_tag.py @@ -165,6 +165,40 @@ def test_modify_tag_with_missing_resource_filter_and_ids(self): '' ) + 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( + '' + '' + '' + 'task' + '' + '' + ) + + 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( + '' + '' + '' + 'config' + '' + '' + ) + if __name__ == '__main__': unittest.main() diff --git a/tests/protocols/gmpv9/testtypes/test_entity_type.py b/tests/protocols/gmpv9/testtypes/test_entity_type.py index dc313ef5e..c23a5e67e 100644 --- a/tests/protocols/gmpv9/testtypes/test_entity_type.py +++ b/tests/protocols/gmpv9/testtypes/test_entity_type.py @@ -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) @@ -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)