| Conditions | 4 |
| Total Lines | 90 |
| Code Lines | 80 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | from ospd_openvas.wrapper import OSPDopenvas |
||
| 5 | def __init__(self, nvti, redis): |
||
| 6 | |||
| 7 | self.VT = { |
||
| 8 | '1.3.6.1.4.1.25623.1.0.100061': { |
||
| 9 | 'creation_time': '2009-03-19 11:22:36 +0100 (Thu, 19 Mar 2009)', |
||
| 10 | 'custom': {'category': '3', |
||
| 11 | 'excluded_keys': 'Settings/disable_cgi_scanning', |
||
| 12 | 'family': 'Product detection', |
||
| 13 | 'filename': 'mantis_detect.nasl', |
||
| 14 | 'required_ports': 'Services/www, 80', |
||
| 15 | 'timeout': '0'}, |
||
| 16 | 'modification_time': ('$Date: 2018-08-10 15:09:25 +0200 (Fri, ' |
||
| 17 | '10 Aug 2018) $'), |
||
| 18 | 'name': 'Mantis Detection', |
||
| 19 | 'qod_type': 'remote_banner', |
||
| 20 | 'insight': 'some insight', |
||
| 21 | 'severities': { |
||
| 22 | 'severity_base_vector': 'AV:N/AC:L/Au:N/C:N/I:N/A:N', |
||
| 23 | 'severity_type': 'cvss_base_v2'}, |
||
| 24 | 'solution': 'some solution', |
||
| 25 | 'solution_type': 'WillNotFix', |
||
| 26 | 'impact': 'some impact', |
||
| 27 | 'summary': 'some summary', |
||
| 28 | 'affected': 'some affection', |
||
| 29 | 'vt_dependencies': [], |
||
| 30 | 'vt_params': { |
||
| 31 | 'Data length : ': { |
||
| 32 | 'default': '', |
||
| 33 | 'description': 'Description', |
||
| 34 | 'name': 'Data length : ', |
||
| 35 | 'type': 'entry'}, |
||
| 36 | 'Do not randomize the order in which ports are scanned': { |
||
| 37 | 'default': 'no', |
||
| 38 | 'description': 'Description', |
||
| 39 | 'name': 'Do not randomize the order in which ports are scanned', |
||
| 40 | 'type': 'checkbox'}, |
||
| 41 | }, |
||
| 42 | 'vt_refs': { |
||
| 43 | 'bid': [''], |
||
| 44 | 'cve': [''], |
||
| 45 | 'xref': ['URL:http://www.mantisbt.org/']}} |
||
| 46 | } |
||
| 47 | |||
| 48 | oids = [['mantis_detect.nasl', '1.3.6.1.4.1.25623.1.0.100061']] |
||
| 49 | nvti.get_oids.return_value = oids |
||
| 50 | nvti.get_nvt_params.return_value = { |
||
| 51 | 'Data length : ': { |
||
| 52 | 'default': '', |
||
| 53 | 'description': 'Description', |
||
| 54 | 'name': 'Data length : ', |
||
| 55 | 'type': 'entry' |
||
| 56 | }, |
||
| 57 | 'Do not randomize the order in which ports are scanned': { |
||
| 58 | 'default': 'no', |
||
| 59 | 'description': 'Description', |
||
| 60 | 'name': 'Do not randomize the order in which ports are scanned', |
||
| 61 | 'type': 'checkbox'}, |
||
| 62 | } |
||
| 63 | nvti.get_nvt_refs.return_value = { |
||
| 64 | 'bid': [''], |
||
| 65 | 'cve': [''], |
||
| 66 | 'xref': ['URL:http://www.mantisbt.org/'] |
||
| 67 | } |
||
| 68 | nvti.get_nvt_metadata.return_value = { |
||
| 69 | 'category': '3', |
||
| 70 | 'creation_date': '2009-03-19 11:22:36 +0100 (Thu, 19 Mar 2009)', |
||
| 71 | 'cvss_base_vector': 'AV:N/AC:L/Au:N/C:N/I:N/A:N', |
||
| 72 | 'excluded_keys': 'Settings/disable_cgi_scanning', |
||
| 73 | 'family': 'Product detection', |
||
| 74 | 'filename': 'mantis_detect.nasl', |
||
| 75 | 'last_modification': ( |
||
| 76 | '$Date: 2018-08-10 15:09:25 +0200 (Fri, 10 Aug 2018) $'), |
||
| 77 | 'name': 'Mantis Detection', |
||
| 78 | 'qod_type': 'remote_banner', |
||
| 79 | 'required_ports': 'Services/www, 80', |
||
| 80 | 'solution': 'some solution', |
||
| 81 | 'solution_type': 'WillNotFix', |
||
| 82 | 'impact': 'some impact', |
||
| 83 | 'insight': 'some insight', |
||
| 84 | 'summary': ('some summary'), |
||
| 85 | 'affected': 'some affection', |
||
| 86 | 'timeout': '0' |
||
| 87 | } |
||
| 88 | |||
| 89 | self.openvas_db = redis |
||
| 90 | self.nvti = nvti |
||
| 91 | with patch('ospd_openvas.wrapper.OpenvasDB', return_value=redis): |
||
| 92 | with patch('ospd_openvas.wrapper.NVTICache', return_value=nvti): |
||
| 93 | with patch.object(OSPDopenvas, 'load_vts', return_value=None): |
||
| 94 | super().__init__('cert', 'key', 'ca') |
||
| 95 |