Skip to content

Commit

Permalink
Add tests for invalid resource_type to GMP v9
Browse files Browse the repository at this point in the history
These tests check if the create and modify functions for permissions
and tags detect an invalid resource type.
  • Loading branch information
timopollmeier committed Dec 7, 2020
1 parent 9ea9b7c commit 6cb0a1a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
13 changes: 13 additions & 0 deletions tests/protocols/gmpv9/testcmds/test_create_permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@ def test_create_permission_for_policy(self):
'</create_permission>'
)

def test_create_permission_with_invalid_resource_type(self):
"""
Test detection of invalid resource_type
"""
with self.assertRaises(InvalidArgumentType):
self.gmp.create_permission(
'create_task',
subject_id='u1',
subject_type=PermissionSubjectType.USER,
resource_id='t1',
resource_type='INVALID',
)


if __name__ == '__main__':
unittest.main()
13 changes: 12 additions & 1 deletion tests/protocols/gmpv9/testcmds/test_create_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import unittest

from gvm.errors import InvalidArgument, RequiredArgument
from gvm.errors import InvalidArgument, RequiredArgument, InvalidArgumentType
from gvm.protocols.gmpv9 import EntityType


Expand Down Expand Up @@ -268,6 +268,17 @@ def test_create_tag_with_policy(self):
'</create_tag>'
)

def test_create_tag_with_invalid_resource_type(self):
"""
Test detection of invalid resource_type
"""
with self.assertRaises(InvalidArgumentType):
self.gmp.create_tag(
name='foo',
resource_ids=['foo'],
resource_type='INVALID',
)


if __name__ == '__main__':
unittest.main()
13 changes: 12 additions & 1 deletion tests/protocols/gmpv9/testcmds/test_modify_permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ def test_modify_permission_with_policy(self):
Test special case where "policy" gets translated to "config"
"""
self.gmp.modify_permission(
permission_id='p1', resource_id='r1', resource_type=EntityType.POLICY
permission_id='p1',
resource_id='r1',
resource_type=EntityType.POLICY,
)

self.connection.send.has_been_called_with(
Expand All @@ -211,6 +213,15 @@ def test_modify_permission_with_policy(self):
'</modify_permission>'
)

def test_modify_permission_with_invalid_resource_type(self):
"""
Test detection of invalid resource_type
"""
with self.assertRaises(InvalidArgumentType):
self.gmp.modify_permission(
permission_id='p1', resource_id='r1', resource_type='INVALID'
)


if __name__ == '__main__':
unittest.main()
11 changes: 10 additions & 1 deletion tests/protocols/gmpv9/testcmds/test_modify_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import unittest

from gvm.errors import RequiredArgument
from gvm.errors import RequiredArgument, InvalidArgumentType
from gvm.protocols.gmpv9 import EntityType


Expand Down Expand Up @@ -199,6 +199,15 @@ def test_modify_tag_with_policy(self):
'</modify_tag>'
)

def test_modify_tag_with_invalid_resource_type(self):
"""
Test detection of invalid resource_type
"""
with self.assertRaises(InvalidArgumentType):
self.gmp.modify_tag(
tag_id='t1', resource_ids=['r1'], resource_type='INVALID'
)


if __name__ == '__main__':
unittest.main()

0 comments on commit 6cb0a1a

Please sign in to comment.