def test_get_gvm_libs_version_with_error(self, mock_check_output): mock_check_output.side_effect = subprocess.SubprocessError('foo') self.assertIsNone(Openvas.get_gvm_libs_version()) mock_check_output.assert_called_with(['openvas', '-V'], stderr=subprocess.STDOUT) mock_check_output.reset_mock() mock_check_output.side_effect = OSError('foo') self.assertIsNone(Openvas.get_gvm_libs_version()) mock_check_output.assert_called_with(['openvas', '-V'], stderr=subprocess.STDOUT)
def test_get_gvm_libs_version_not_version(self, mock_check_output): mock_check_output.return_value = b"OpenVAS 20.04\n" self.assertIsNone(Openvas.get_gvm_libs_version()) mock_check_output.assert_called_with(['openvas', '-V'], stderr=subprocess.STDOUT)
def _set_nvti_cache_name(self): """Set nvticache name""" version_string = Openvas.get_gvm_libs_version() if not version_string: raise OspdOpenvasError( "Not possible to get the installed gvm-libs version. " "Outdated openvas version. openvas version needs to be at " "least 7.0.1.") # Remove pre-release sufix and git revision if exists # as the gvm-libs version has the format # e.g "20.8+beta1-git-a41b140d-zero-padding" version_string = version_string.split("+")[0] if self._is_compatible_version(version_string): self._nvti_cache_name = "nvticache{}".format(version_string) else: raise OspdOpenvasError( "Error setting nvticache. Incompatible nvticache " "version {}. Supported versions are {}.".format( version_string, ", ".join([ str(spec) for spec in SUPPORTED_NVTICACHE_VERSIONS_SPECIFIER ]), ))
def test_get_gvm_libs_version(self, mock_check_output): mock_check_output.return_value = b"OpenVAS 20.04\ngvm-libs 20.04" self.assertEqual(Openvas.get_gvm_libs_version(), '20.04') mock_check_output.assert_called_with(['openvas', '-V'], stderr=subprocess.STDOUT)
def _set_nvti_cache_name(self): """Set nvticache name""" version_string = Openvas.get_gvm_libs_version() if not version_string: raise OspdOpenvasError( "Not possible to get the installed gvm-libs version. " "Outdated openvas version. openvas version needs to be at " "least 7.0.1." ) if self._is_compatible_version(version_string): self._nvti_cache_name = "nvticache{}".format(version_string) else: raise OspdOpenvasError( "Error setting nvticache. Incompatible nvticache " "version {}. Supported versions are {}.".format( version_string, ", ".join( [ str(spec) for spec in SUPPORTED_NVTICACHE_VERSIONS_SPECIFIER ] ), ) )