Completed
Push — master ( b519bb...486e1a )
by Jaspar
25s queued 15s
created

tests.protocols.gmpv208.entities.credentials.test_get_credential   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 49
dl 0
loc 102
rs 10
c 0
b 0
f 0
wmc 11

7 Methods

Rating   Name   Duplication   Size   Complexity  
A GmpGetCredentialTestMixin.test_get_credential_with_credential_format() 0 29 1
A GmpGetCredentialTestMixin.test_get_credential_with_invalid_credential_format() 0 3 2
A GmpGetCredentialTestMixin.test_get_credential_with_targets() 0 11 1
A GmpGetCredentialTestMixin.test_get_credential_invalid_credential_id() 0 6 3
A GmpGetCredentialTestMixin.test_get_credential() 0 5 1
A GmpGetCredentialTestMixin.test_get_credential_missing_credential_id() 0 3 2
A GmpGetCredentialTestMixin.test_get_credential_with_scanners() 0 11 1
1
# -*- coding: utf-8 -*-
2
# Copyright (C) 2018-2021 Greenbone Networks GmbH
3
#
4
# SPDX-License-Identifier: GPL-3.0-or-later
5
#
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19
from gvm.errors import InvalidArgumentType, RequiredArgument
20
21
from gvm.protocols.gmpv208 import CredentialFormat
22
23
24
class GmpGetCredentialTestMixin:
25
    def test_get_credential(self):
26
        self.gmp.get_credential('id')
27
28
        self.connection.send.has_been_called_with(
29
            '<get_credentials credential_id="id"/>'
30
        )
31
32
    def test_get_credential_missing_credential_id(self):
33
        with self.assertRaises(RequiredArgument):
34
            self.gmp.get_credential(None)
35
36
    def test_get_credential_invalid_credential_id(self):
37
        with self.assertRaises(RequiredArgument):
38
            self.gmp.get_credential(credential_id=None)
39
40
        with self.assertRaises(RequiredArgument):
41
            self.gmp.get_credential('')
42
43
    def test_get_credential_with_credential_format(self):
44
        self.gmp.get_credential('id', credential_format=CredentialFormat.KEY)
45
46
        self.connection.send.has_been_called_with(
47
            '<get_credentials credential_id="id" format="key"/>'
48
        )
49
50
        self.gmp.get_credential('id', credential_format=CredentialFormat.RPM)
51
52
        self.connection.send.has_been_called_with(
53
            '<get_credentials credential_id="id" format="rpm"/>'
54
        )
55
56
        self.gmp.get_credential('id', credential_format=CredentialFormat.DEB)
57
58
        self.connection.send.has_been_called_with(
59
            '<get_credentials credential_id="id" format="deb"/>'
60
        )
61
62
        self.gmp.get_credential('id', credential_format=CredentialFormat.EXE)
63
64
        self.connection.send.has_been_called_with(
65
            '<get_credentials credential_id="id" format="exe"/>'
66
        )
67
68
        self.gmp.get_credential('id', credential_format=CredentialFormat.PEM)
69
70
        self.connection.send.has_been_called_with(
71
            '<get_credentials credential_id="id" format="pem"/>'
72
        )
73
74
    def test_get_credential_with_invalid_credential_format(self):
75
        with self.assertRaises(InvalidArgumentType):
76
            self.gmp.get_credential('id', credential_format='foo')
77
78
    def test_get_credential_with_scanners(self):
79
        self.gmp.get_credential('id', scanners=True)
80
81
        self.connection.send.has_been_called_with(
82
            '<get_credentials credential_id="id" scanners="1"/>'
83
        )
84
85
        self.gmp.get_credential('id', scanners=False)
86
87
        self.connection.send.has_been_called_with(
88
            '<get_credentials credential_id="id" scanners="0"/>'
89
        )
90
91
    def test_get_credential_with_targets(self):
92
        self.gmp.get_credential('id', targets=True)
93
94
        self.connection.send.has_been_called_with(
95
            '<get_credentials credential_id="id" targets="1"/>'
96
        )
97
98
        self.gmp.get_credential('id', targets=False)
99
100
        self.connection.send.has_been_called_with(
101
            '<get_credentials credential_id="id" targets="0"/>'
102
        )
103