| 1 |
# SPDX-FileCopyrightText: 2023-2024 Greenbone AG |
| 2 |
# |
| 3 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 4 |
# |
| 5 |
|
| 6 |
# pylint: disable=line-too-long, too-many-lines |
| 7 |
|
| 8 |
import io |
| 9 |
import sys |
| 10 |
import unittest |
| 11 |
from contextlib import redirect_stderr, redirect_stdout |
| 12 |
from pathlib import Path |
| 13 |
from unittest.mock import MagicMock, patch |
| 14 |
|
| 15 |
from pontos.testing import temp_file |
| 16 |
|
| 17 |
from greenbone.feed.sync.config import ( |
| 18 |
DEFAULT_CONFIG_FILE, |
| 19 |
DEFAULT_DESTINATION_PREFIX, |
| 20 |
DEFAULT_ENTERPRISE_KEY_PATH, |
| 21 |
DEFAULT_FEED_RELEASE, |
| 22 |
DEFAULT_GVMD_LOCK_FILE_PATH, |
| 23 |
DEFAULT_OPENVAS_LOCK_FILE_PATH, |
| 24 |
DEFAULT_USER_CONFIG_FILE, |
| 25 |
) |
| 26 |
from greenbone.feed.sync.errors import ConfigFileError |
| 27 |
from greenbone.feed.sync.helper import DEFAULT_FLOCK_WAIT_INTERVAL |
| 28 |
from greenbone.feed.sync.parser import CliParser, feed_type |
| 29 |
from greenbone.feed.sync.rsync import ( |
| 30 |
DEFAULT_RSYNC_COMPRESSION_LEVEL, |
| 31 |
DEFAULT_RSYNC_URL, |
| 32 |
) |
| 33 |
|
| 34 |
|
| 35 |
class FeedTypeTestCase(unittest.TestCase): |
| 36 |
def test_nvt(self): |
| 37 |
self.assertEqual("nvt", feed_type("nvt")) |
| 38 |
self.assertEqual("nvt", feed_type("nvts")) |
| 39 |
self.assertEqual("nvt", feed_type("NVT")) |
| 40 |
self.assertEqual("nvt", feed_type("NVTS")) |
| 41 |
|
| 42 |
def test_report_format(self): |
| 43 |
self.assertEqual("report-format", feed_type("report-format")) |
| 44 |
self.assertEqual("report-format", feed_type("report-formats")) |
| 45 |
self.assertEqual("report-format", feed_type("report_format")) |
| 46 |
self.assertEqual("report-format", feed_type("report_formats")) |
| 47 |
self.assertEqual("report-format", feed_type("REPORT_FORMAT")) |
| 48 |
self.assertEqual("report-format", feed_type("REPORT_FORMATS")) |
| 49 |
self.assertEqual("report-format", feed_type("REPORT-FORMAT")) |
| 50 |
self.assertEqual("report-format", feed_type("REPORT-FORMATS")) |
| 51 |
|
| 52 |
def test_port_list(self): |
| 53 |
self.assertEqual("port-list", feed_type("port-list")) |
| 54 |
self.assertEqual("port-list", feed_type("port-lists")) |
| 55 |
self.assertEqual("port-list", feed_type("port_list")) |
| 56 |
self.assertEqual("port-list", feed_type("port_lists")) |
| 57 |
self.assertEqual("port-list", feed_type("PORT_LIST")) |
| 58 |
self.assertEqual("port-list", feed_type("PORT_LISTS")) |
| 59 |
self.assertEqual("port-list", feed_type("PORT-LIST")) |
| 60 |
self.assertEqual("port-list", feed_type("PORT-LISTS")) |
| 61 |
|
| 62 |
def test_scan_config(self): |
| 63 |
self.assertEqual("scan-config", feed_type("scan-config")) |
| 64 |
self.assertEqual("scan-config", feed_type("scan-configs")) |
| 65 |
self.assertEqual("scan-config", feed_type("scan_config")) |
| 66 |
self.assertEqual("scan-config", feed_type("scan_configs")) |
| 67 |
self.assertEqual("scan-config", feed_type("SCAN_CONFIG")) |
| 68 |
self.assertEqual("scan-config", feed_type("SCAN_CONFIGS")) |
| 69 |
self.assertEqual("scan-config", feed_type("SCAN-CONFIG")) |
| 70 |
self.assertEqual("scan-config", feed_type("SCAN-CONFIGS")) |
| 71 |
|
| 72 |
def test_gvmd_data(self): |
| 73 |
self.assertEqual("gvmd-data", feed_type("gvmd-data")) |
| 74 |
self.assertEqual("gvmd-data", feed_type("gvmd_data")) |
| 75 |
self.assertEqual("gvmd-data", feed_type("GVMD-DATA")) |
| 76 |
self.assertEqual("gvmd-data", feed_type("GVMD_DATA")) |
| 77 |
|
| 78 |
|
| 79 |
class CliParserTestCase(unittest.TestCase): |
| 80 |
def test_output_group(self): |
| 81 |
parser = CliParser() |
| 82 |
|
| 83 |
with redirect_stderr(io.StringIO()) as f, self.assertRaises(SystemExit): |
| 84 |
parser.parse_arguments(["-vvv", "--quiet"]) |
| 85 |
|
| 86 |
self.assertIn( |
| 87 |
"argument --quiet: not allowed with argument --verbose/-v", |
| 88 |
f.getvalue(), |
| 89 |
) |
| 90 |
|
| 91 |
def test_wait_group(self): |
| 92 |
parser = CliParser() |
| 93 |
|
| 94 |
with redirect_stderr(io.StringIO()) as f, self.assertRaises(SystemExit): |
| 95 |
parser.parse_arguments(["--no-wait", "--wait-interval", "20"]) |
| 96 |
|
| 97 |
self.assertIn( |
| 98 |
"argument --wait-interval: not allowed with argument --no-wait", |
| 99 |
f.getvalue(), |
| 100 |
) |
| 101 |
|
| 102 |
def test_defaults(self): |
| 103 |
parser = CliParser() |
| 104 |
args = parser.parse_arguments([]) |
| 105 |
|
| 106 |
self.assertEqual(args.type, "all") |
| 107 |
self.assertEqual( |
| 108 |
args.destination_prefix, Path(DEFAULT_DESTINATION_PREFIX) |
| 109 |
) |
| 110 |
self.assertEqual(args.feed_url, DEFAULT_RSYNC_URL) |
| 111 |
self.assertEqual( |
| 112 |
args.gvmd_data_destination, |
| 113 |
Path(DEFAULT_DESTINATION_PREFIX) / "gvm" / "data-objects" / "gvmd", |
| 114 |
) |
| 115 |
self.assertEqual( |
| 116 |
args.gvmd_data_url, |
| 117 |
f"{DEFAULT_RSYNC_URL}/data-feed/{DEFAULT_FEED_RELEASE}/", |
| 118 |
) |
| 119 |
self.assertEqual( |
| 120 |
args.notus_destination, |
| 121 |
Path(DEFAULT_DESTINATION_PREFIX) / "notus", |
| 122 |
) |
| 123 |
self.assertEqual( |
| 124 |
args.notus_url, |
| 125 |
f"{DEFAULT_RSYNC_URL}/vulnerability-feed/{DEFAULT_FEED_RELEASE}/vt-data/notus/", |
| 126 |
) |
| 127 |
self.assertEqual( |
| 128 |
args.nasl_destination, |
| 129 |
Path(DEFAULT_DESTINATION_PREFIX) / "openvas" / "plugins", |
| 130 |
) |
| 131 |
self.assertEqual( |
| 132 |
args.nasl_url, |
| 133 |
f"{DEFAULT_RSYNC_URL}/vulnerability-feed/{DEFAULT_FEED_RELEASE}/vt-data/nasl/", |
| 134 |
) |
| 135 |
self.assertEqual( |
| 136 |
args.scap_data_destination, |
| 137 |
Path(DEFAULT_DESTINATION_PREFIX) / "gvm" / "scap-data", |
| 138 |
) |
| 139 |
self.assertEqual( |
| 140 |
args.scap_data_url, |
| 141 |
f"{DEFAULT_RSYNC_URL}/vulnerability-feed/{DEFAULT_FEED_RELEASE}/scap-data/", |
| 142 |
) |
| 143 |
self.assertEqual( |
| 144 |
args.cert_data_destination, |
| 145 |
Path(DEFAULT_DESTINATION_PREFIX) / "gvm" / "cert-data", |
| 146 |
) |
| 147 |
self.assertEqual( |
| 148 |
args.cert_data_url, |
| 149 |
f"{DEFAULT_RSYNC_URL}/vulnerability-feed/{DEFAULT_FEED_RELEASE}/cert-data/", |
| 150 |
) |
| 151 |
self.assertEqual( |
| 152 |
args.report_formats_destination, |
| 153 |
Path(DEFAULT_DESTINATION_PREFIX) |
| 154 |
/ "gvm" |
| 155 |
/ "data-objects" |
| 156 |
/ "gvmd" |
| 157 |
/ "report-formats", |
| 158 |
) |
| 159 |
self.assertEqual( |
| 160 |
args.report_formats_url, |
| 161 |
f"{DEFAULT_RSYNC_URL}/data-feed/{DEFAULT_FEED_RELEASE}/report-formats/", |
| 162 |
) |
| 163 |
self.assertEqual( |
| 164 |
args.scan_configs_destination, |
| 165 |
Path(DEFAULT_DESTINATION_PREFIX) |
| 166 |
/ "gvm" |
| 167 |
/ "data-objects" |
| 168 |
/ "gvmd" |
| 169 |
/ "scan-configs", |
| 170 |
) |
| 171 |
self.assertEqual( |
| 172 |
args.scan_configs_url, |
| 173 |
f"{DEFAULT_RSYNC_URL}/data-feed/{DEFAULT_FEED_RELEASE}/scan-configs/", |
| 174 |
) |
| 175 |
self.assertEqual( |
| 176 |
args.port_lists_destination, |
| 177 |
Path(DEFAULT_DESTINATION_PREFIX) |
| 178 |
/ "gvm" |
| 179 |
/ "data-objects" |
| 180 |
/ "gvmd" |
| 181 |
/ "port-lists", |
| 182 |
) |
| 183 |
self.assertEqual( |
| 184 |
args.port_lists_url, |
| 185 |
f"{DEFAULT_RSYNC_URL}/data-feed/{DEFAULT_FEED_RELEASE}/port-lists/", |
| 186 |
) |
| 187 |
self.assertEqual( |
| 188 |
args.gvmd_lock_file, |
| 189 |
Path(DEFAULT_DESTINATION_PREFIX) / DEFAULT_GVMD_LOCK_FILE_PATH, |
| 190 |
) |
| 191 |
self.assertEqual( |
| 192 |
args.openvas_lock_file, |
| 193 |
Path(DEFAULT_DESTINATION_PREFIX) / DEFAULT_OPENVAS_LOCK_FILE_PATH, |
| 194 |
) |
| 195 |
self.assertEqual(args.wait_interval, DEFAULT_FLOCK_WAIT_INTERVAL) |
| 196 |
self.assertFalse(args.no_wait) |
| 197 |
self.assertEqual( |
| 198 |
args.compression_level, DEFAULT_RSYNC_COMPRESSION_LEVEL |
| 199 |
) |
| 200 |
self.assertIsNone(args.private_directory) |
| 201 |
self.assertIsNone(args.verbose) |
| 202 |
self.assertFalse(args.fail_fast) |
| 203 |
self.assertIsNone(args.rsync_timeout) |
| 204 |
self.assertEqual( |
| 205 |
args.greenbone_enterprise_feed_key, |
| 206 |
Path(DEFAULT_ENTERPRISE_KEY_PATH), |
| 207 |
) |
| 208 |
self.assertEqual(args.feed_release, DEFAULT_FEED_RELEASE) |
| 209 |
|
| 210 |
def test_help(self): |
| 211 |
parser = CliParser() |
| 212 |
|
| 213 |
with ( |
| 214 |
redirect_stdout(io.StringIO()) as f, |
| 215 |
self.assertRaises(SystemExit) as cm, |
| 216 |
): |
| 217 |
parser.parse_arguments(["--help"]) |
| 218 |
|
| 219 |
self.assertEqual(cm.exception.code, 0) |
| 220 |
self.assertTrue(f.getvalue().startswith("usage: ")) |
| 221 |
|
| 222 |
def test_verbose(self): |
| 223 |
parser = CliParser() |
| 224 |
|
| 225 |
args = parser.parse_arguments(["-v"]) |
| 226 |
self.assertEqual(args.verbose, 1) |
| 227 |
|
| 228 |
args = parser.parse_arguments(["--verbose"]) |
| 229 |
self.assertEqual(args.verbose, 1) |
| 230 |
|
| 231 |
args = parser.parse_arguments(["-vv"]) |
| 232 |
self.assertEqual(args.verbose, 2) |
| 233 |
|
| 234 |
args = parser.parse_arguments(["-vvv"]) |
| 235 |
self.assertEqual(args.verbose, 3) |
| 236 |
|
| 237 |
args = parser.parse_arguments(["-vvvv"]) |
| 238 |
self.assertEqual(args.verbose, 4) |
| 239 |
|
| 240 |
def test_quiet(self): |
| 241 |
parser = CliParser() |
| 242 |
args = parser.parse_arguments(["--quiet"]) |
| 243 |
self.assertTrue(args.quiet) |
| 244 |
|
| 245 |
def test_selftest(self): |
| 246 |
parser = CliParser() |
| 247 |
args = parser.parse_arguments(["--selftest"]) |
| 248 |
self.assertTrue(args.selftest) |
| 249 |
|
| 250 |
@patch("greenbone.feed.sync.parser.Path") |
| 251 |
def test_use_default_config_files(self, path_mock): |
| 252 |
path_mock_instance = path_mock.return_value |
| 253 |
path_mock_instance.expanduser.return_value = path_mock_instance |
| 254 |
path_mock_instance.resolve.return_value = path_mock_instance |
| 255 |
path_mock_instance.exists.return_value = False |
| 256 |
|
| 257 |
parser = CliParser() |
| 258 |
parser.parse_arguments([]) |
| 259 |
|
| 260 |
path_mock.assert_any_call(DEFAULT_USER_CONFIG_FILE) |
| 261 |
path_mock.assert_any_call(DEFAULT_CONFIG_FILE) |
| 262 |
|
| 263 |
def test_private_directory(self): |
| 264 |
parser = CliParser() |
| 265 |
args = parser.parse_arguments(["--private-directory", "foobar"]) |
| 266 |
self.assertEqual(args.private_directory, Path("foobar")) |
| 267 |
|
| 268 |
def test_compression_level(self): |
| 269 |
parser = CliParser() |
| 270 |
args = parser.parse_arguments(["--compression-level", "0"]) |
| 271 |
self.assertEqual(args.compression_level, 0) |
| 272 |
|
| 273 |
args = parser.parse_arguments(["--compression-level", "1"]) |
| 274 |
self.assertEqual(args.compression_level, 1) |
| 275 |
|
| 276 |
args = parser.parse_arguments(["--compression-level", "2"]) |
| 277 |
self.assertEqual(args.compression_level, 2) |
| 278 |
|
| 279 |
args = parser.parse_arguments(["--compression-level", "3"]) |
| 280 |
self.assertEqual(args.compression_level, 3) |
| 281 |
|
| 282 |
args = parser.parse_arguments(["--compression-level", "4"]) |
| 283 |
self.assertEqual(args.compression_level, 4) |
| 284 |
|
| 285 |
args = parser.parse_arguments(["--compression-level", "5"]) |
| 286 |
self.assertEqual(args.compression_level, 5) |
| 287 |
|
| 288 |
args = parser.parse_arguments(["--compression-level", "6"]) |
| 289 |
self.assertEqual(args.compression_level, 6) |
| 290 |
|
| 291 |
args = parser.parse_arguments(["--compression-level", "7"]) |
| 292 |
self.assertEqual(args.compression_level, 7) |
| 293 |
|
| 294 |
args = parser.parse_arguments(["--compression-level", "8"]) |
| 295 |
self.assertEqual(args.compression_level, 8) |
| 296 |
|
| 297 |
args = parser.parse_arguments(["--compression-level", "9"]) |
| 298 |
self.assertEqual(args.compression_level, 9) |
| 299 |
|
| 300 |
with redirect_stderr(io.StringIO()) as f, self.assertRaises(SystemExit): |
| 301 |
parser.parse_arguments(["--compression-level", "10"]) |
| 302 |
|
| 303 |
self.assertIn( |
| 304 |
"error: argument --compression-level: invalid choice:", |
| 305 |
f.getvalue(), |
| 306 |
) |
| 307 |
|
| 308 |
def test_gvmd_data_destination(self): |
| 309 |
parser = CliParser() |
| 310 |
args = parser.parse_arguments(["--gvmd-data-destination", "foo/bar"]) |
| 311 |
self.assertEqual(args.gvmd_data_destination, Path("foo/bar")) |
| 312 |
|
| 313 |
def test_gvmd_data_url(self): |
| 314 |
parser = CliParser() |
| 315 |
args = parser.parse_arguments( |
| 316 |
["--gvmd-data-url", "rsync://foo.bar/gvmd-data"] |
| 317 |
) |
| 318 |
self.assertEqual(args.gvmd_data_url, "rsync://foo.bar/gvmd-data") |
| 319 |
|
| 320 |
def test_notus_destination(self): |
| 321 |
parser = CliParser() |
| 322 |
args = parser.parse_arguments(["--notus-destination", "foo/bar"]) |
| 323 |
self.assertEqual(args.notus_destination, Path("foo/bar")) |
| 324 |
|
| 325 |
def test_notus_url(self): |
| 326 |
parser = CliParser() |
| 327 |
args = parser.parse_arguments(["--notus-url", "rsync://foo.bar/notus"]) |
| 328 |
self.assertEqual(args.notus_url, "rsync://foo.bar/notus") |
| 329 |
|
| 330 |
def test_nasl_destination(self): |
| 331 |
parser = CliParser() |
| 332 |
args = parser.parse_arguments(["--nasl-destination", "foo/bar"]) |
| 333 |
self.assertEqual(args.nasl_destination, Path("foo/bar")) |
| 334 |
|
| 335 |
def test_nasl_url(self): |
| 336 |
parser = CliParser() |
| 337 |
args = parser.parse_arguments(["--nasl-url", "rsync://foo.bar/nasl"]) |
| 338 |
self.assertEqual(args.nasl_url, "rsync://foo.bar/nasl") |
| 339 |
|
| 340 |
def test_scap_data_destination(self): |
| 341 |
parser = CliParser() |
| 342 |
args = parser.parse_arguments(["--scap-data-destination", "foo/bar"]) |
| 343 |
self.assertEqual(args.scap_data_destination, Path("foo/bar")) |
| 344 |
|
| 345 |
def test_scap_data_url(self): |
| 346 |
parser = CliParser() |
| 347 |
args = parser.parse_arguments( |
| 348 |
["--scap-data-url", "rsync://foo.bar/scap-data"] |
| 349 |
) |
| 350 |
self.assertEqual(args.scap_data_url, "rsync://foo.bar/scap-data") |
| 351 |
|
| 352 |
def test_cert_data_destination(self): |
| 353 |
parser = CliParser() |
| 354 |
args = parser.parse_arguments(["--cert-data-destination", "foo/bar"]) |
| 355 |
self.assertEqual(args.cert_data_destination, Path("foo/bar")) |
| 356 |
|
| 357 |
def test_cert_data_url(self): |
| 358 |
parser = CliParser() |
| 359 |
args = parser.parse_arguments( |
| 360 |
["--cert-data-url", "rsync://foo.bar/cert-data"] |
| 361 |
) |
| 362 |
self.assertEqual(args.cert_data_url, "rsync://foo.bar/cert-data") |
| 363 |
|
| 364 |
def test_report_formats_destination(self): |
| 365 |
parser = CliParser() |
| 366 |
args = parser.parse_arguments( |
| 367 |
["--report-formats-destination", "foo/bar"] |
| 368 |
) |
| 369 |
self.assertEqual(args.report_formats_destination, Path("foo/bar")) |
| 370 |
|
| 371 |
def test_report_formats_url(self): |
| 372 |
parser = CliParser() |
| 373 |
args = parser.parse_arguments( |
| 374 |
["--report-formats-url", "rsync://foo.bar/report-formats"] |
| 375 |
) |
| 376 |
self.assertEqual( |
| 377 |
args.report_formats_url, "rsync://foo.bar/report-formats" |
| 378 |
) |
| 379 |
|
| 380 |
def test_scan_configs_destination(self): |
| 381 |
parser = CliParser() |
| 382 |
args = parser.parse_arguments(["--scan-configs-destination", "foo/bar"]) |
| 383 |
self.assertEqual(args.scan_configs_destination, Path("foo/bar")) |
| 384 |
|
| 385 |
def test_scan_configs_url(self): |
| 386 |
parser = CliParser() |
| 387 |
args = parser.parse_arguments( |
| 388 |
["--scan-configs-url", "rsync://foo.bar/scan-configs"] |
| 389 |
) |
| 390 |
self.assertEqual(args.scan_configs_url, "rsync://foo.bar/scan-configs") |
| 391 |
|
| 392 |
def test_port_lists_destination(self): |
| 393 |
parser = CliParser() |
| 394 |
args = parser.parse_arguments(["--port-lists-destination", "foo/bar"]) |
| 395 |
self.assertEqual(args.port_lists_destination, Path("foo/bar")) |
| 396 |
|
| 397 |
def test_port_lists_url(self): |
| 398 |
parser = CliParser() |
| 399 |
args = parser.parse_arguments( |
| 400 |
["--port-lists-url", "rsync://foo.bar/port-lists"] |
| 401 |
) |
| 402 |
self.assertEqual(args.port_lists_url, "rsync://foo.bar/port-lists") |
| 403 |
|
| 404 |
def test_gvmd_lock_file(self): |
| 405 |
parser = CliParser() |
| 406 |
args = parser.parse_arguments(["--gvmd-lock-file", "/run/gvmd.lock"]) |
| 407 |
self.assertEqual(args.gvmd_lock_file, Path("/run/gvmd.lock")) |
| 408 |
|
| 409 |
def test_openvas_lock_file(self): |
| 410 |
parser = CliParser() |
| 411 |
args = parser.parse_arguments( |
| 412 |
["--openvas-lock-file", "/run/openvas.lock"] |
| 413 |
) |
| 414 |
self.assertEqual(args.openvas_lock_file, Path("/run/openvas.lock")) |
| 415 |
|
| 416 |
def test_fail_fast(self): |
| 417 |
parser = CliParser() |
| 418 |
args = parser.parse_arguments(["--fail-fast"]) |
| 419 |
self.assertTrue(args.fail_fast) |
| 420 |
|
| 421 |
args = parser.parse_arguments(["--failfast"]) |
| 422 |
self.assertTrue(args.fail_fast) |
| 423 |
|
| 424 |
def test_no_wait(self): |
| 425 |
parser = CliParser() |
| 426 |
args = parser.parse_arguments(["--no-wait"]) |
| 427 |
self.assertTrue(args.no_wait) |
| 428 |
|
| 429 |
def test_wait_interval(self): |
| 430 |
parser = CliParser() |
| 431 |
args = parser.parse_arguments(["--wait-interval", "100"]) |
| 432 |
self.assertEqual(args.wait_interval, 100) |
| 433 |
|
| 434 |
def test_rsync_timeout(self): |
| 435 |
parser = CliParser() |
| 436 |
args = parser.parse_arguments(["--rsync-timeout", "120"]) |
| 437 |
self.assertEqual(args.rsync_timeout, 120) |
| 438 |
|
| 439 |
def test_greenbone_enterprise_feed_key(self): |
| 440 |
parser = CliParser() |
| 441 |
args = parser.parse_arguments( |
| 442 |
["--greenbone-enterprise-feed-key", "/tmp/some.key"] |
| 443 |
) |
| 444 |
self.assertEqual( |
| 445 |
args.greenbone_enterprise_feed_key, Path("/tmp/some.key") |
| 446 |
) |
| 447 |
|
| 448 |
def test_other(self): |
| 449 |
parser = CliParser() |
| 450 |
|
| 451 |
with ( |
| 452 |
redirect_stderr(io.StringIO()) as f, |
| 453 |
self.assertRaises(SystemExit) as cm, |
| 454 |
): |
| 455 |
parser.parse_arguments(["--foo-bar", "10"]) |
| 456 |
|
| 457 |
self.assertIn("error: unrecognized arguments: --foo-bar", f.getvalue()) |
| 458 |
self.assertEqual(cm.exception.code, 2) |
| 459 |
|
| 460 |
@patch("greenbone.feed.sync.parser.Path") |
| 461 |
def test_config(self, path_mock: MagicMock): |
| 462 |
content = """[greenbone-feed-sync] |
| 463 |
verbose = 3 |
| 464 |
feed-url = "rsync://foo.bar" |
| 465 |
destination-prefix = "/usr/lib" |
| 466 |
""" |
| 467 |
path_mock_instance = path_mock.return_value |
| 468 |
path_mock_instance.absolute.return_value = "/foo/bar/foo.toml" |
| 469 |
path_mock_instance.expanduser.return_value = path_mock_instance |
| 470 |
path_mock_instance.resolve.return_value = path_mock_instance |
| 471 |
path_mock_instance.exists.return_value = True |
| 472 |
path_mock_instance.read_text.return_value = content |
| 473 |
|
| 474 |
parser = CliParser() |
| 475 |
args = parser.parse_arguments(["--config", "foo.toml"]) |
| 476 |
|
| 477 |
self.assertEqual(args.verbose, 3) |
| 478 |
self.assertEqual(args.feed_url, "rsync://foo.bar") |
| 479 |
self.assertEqual(args.destination_prefix, Path("/usr/lib")) |
| 480 |
|
| 481 |
@patch("greenbone.feed.sync.parser.Path") |
| 482 |
def test_load_from_default_config(self, path_mock: MagicMock): |
| 483 |
content = """[greenbone-feed-sync] |
| 484 |
verbose = 3 |
| 485 |
feed-url = "rsync://foo.bar" |
| 486 |
destination-prefix = "/usr/lib" |
| 487 |
""" |
| 488 |
path_mock_instance = path_mock.return_value |
| 489 |
path_mock_instance.absolute.return_value = ( |
| 490 |
"/foo/bar/.config/greenbone-feed-sync.toml" |
| 491 |
) |
| 492 |
path_mock_instance.expanduser.return_value = path_mock_instance |
| 493 |
path_mock_instance.resolve.return_value = path_mock_instance |
| 494 |
path_mock_instance.exists.return_value = True |
| 495 |
path_mock_instance.read_text.return_value = content |
| 496 |
|
| 497 |
parser = CliParser() |
| 498 |
args = parser.parse_arguments([]) |
| 499 |
|
| 500 |
self.assertEqual(args.verbose, 3) |
| 501 |
self.assertEqual(args.feed_url, "rsync://foo.bar") |
| 502 |
self.assertEqual(args.destination_prefix, Path("/usr/lib")) |
| 503 |
|
| 504 |
@patch.dict( |
| 505 |
"os.environ", |
| 506 |
{ |
| 507 |
"GREENBONE_FEED_SYNC_DESTINATION_PREFIX": "/usr/lib", |
| 508 |
"GREENBONE_FEED_SYNC_URL": "rsync://foo.bar", |
| 509 |
"GREENBONE_FEED_SYNC_VERBOSE": "3", |
| 510 |
}, |
| 511 |
) |
| 512 |
def test_from_environment(self): |
| 513 |
parser = CliParser() |
| 514 |
args = parser.parse_arguments([]) |
| 515 |
|
| 516 |
self.assertEqual(args.verbose, 3) |
| 517 |
self.assertEqual(args.feed_url, "rsync://foo.bar") |
| 518 |
self.assertEqual(args.destination_prefix, Path("/usr/lib")) |
| 519 |
|
| 520 |
@patch.dict( |
| 521 |
"os.environ", |
| 522 |
{ |
| 523 |
"GREENBONE_FEED_SYNC_DESTINATION_PREFIX": "/usr/lib", |
| 524 |
"GREENBONE_FEED_SYNC_URL": "rsync://foo.bar", |
| 525 |
"GREENBONE_FEED_SYNC_VERBOSE": "3", |
| 526 |
}, |
| 527 |
) |
| 528 |
@patch("greenbone.feed.sync.parser.Path") |
| 529 |
def test_environment_takes_precedence(self, path_mock): |
| 530 |
content = """[greenbone-feed-sync] |
| 531 |
verbose = 9 |
| 532 |
feed-url = "rsync://lorem.ipsum" |
| 533 |
destination-prefix = "/opt/lib" |
| 534 |
wait-interval = 100 |
| 535 |
""" |
| 536 |
path_mock_instance = path_mock.return_value |
| 537 |
path_mock_instance.absolute.return_value = ( |
| 538 |
"/foo/bar/.config/greenbone-feed-sync.toml" |
| 539 |
) |
| 540 |
path_mock_instance.expanduser.return_value = path_mock_instance |
| 541 |
path_mock_instance.resolve.return_value = path_mock_instance |
| 542 |
path_mock_instance.exists.return_value = True |
| 543 |
path_mock_instance.read_text.return_value = content |
| 544 |
|
| 545 |
parser = CliParser() |
| 546 |
args = parser.parse_arguments([]) |
| 547 |
|
| 548 |
self.assertEqual(args.verbose, 3) |
| 549 |
self.assertEqual(args.feed_url, "rsync://foo.bar") |
| 550 |
self.assertEqual(args.destination_prefix, Path("/usr/lib")) |
| 551 |
self.assertEqual(args.wait_interval, 100) |
| 552 |
|
| 553 |
@patch.dict( |
| 554 |
"os.environ", |
| 555 |
{ |
| 556 |
"GREENBONE_FEED_SYNC_DESTINATION_PREFIX": "/usr/lib", |
| 557 |
"GREENBONE_FEED_SYNC_URL": "rsync://foo.bar", |
| 558 |
"GREENBONE_FEED_SYNC_VERBOSE": "3", |
| 559 |
}, |
| 560 |
) |
| 561 |
@patch("greenbone.feed.sync.parser.Path") |
| 562 |
def test_argument_takes_precedence(self, path_mock): |
| 563 |
content = """[greenbone-feed-sync] |
| 564 |
verbose = 9 |
| 565 |
feed-url = "rsync://lorem.ipsum" |
| 566 |
destination-prefix = "/opt/lib" |
| 567 |
wait-interval = 100 |
| 568 |
""" |
| 569 |
path_mock_instance = path_mock.return_value |
| 570 |
path_mock_instance.absolute.return_value = ( |
| 571 |
"/foo/bar/.config/greenbone-feed-sync.toml" |
| 572 |
) |
| 573 |
path_mock_instance.expanduser.return_value = path_mock_instance |
| 574 |
path_mock_instance.resolve.return_value = path_mock_instance |
| 575 |
path_mock_instance.exists.return_value = True |
| 576 |
path_mock_instance.read_text.return_value = content |
| 577 |
|
| 578 |
parser = CliParser() |
| 579 |
args = parser.parse_arguments( |
| 580 |
[ |
| 581 |
"--wait-interval", |
| 582 |
"90", |
| 583 |
] |
| 584 |
) |
| 585 |
|
| 586 |
self.assertEqual(args.verbose, 3) |
| 587 |
self.assertEqual(args.feed_url, "rsync://foo.bar") |
| 588 |
self.assertEqual(args.destination_prefix, Path("/usr/lib")) |
| 589 |
self.assertEqual(args.wait_interval, 90) |
| 590 |
|
| 591 |
def test_config_file_not_exists(self): |
| 592 |
parser = CliParser() |
| 593 |
|
| 594 |
with self.assertRaisesRegex( |
| 595 |
ConfigFileError, "Config file foo.bar does not exist." |
| 596 |
): |
| 597 |
parser.parse_arguments(["--config", "foo.bar"]) |
| 598 |
|
| 599 |
def test_type(self): |
| 600 |
parser = CliParser() |
| 601 |
args = parser.parse_arguments(["--type", "nvt"]) |
| 602 |
self.assertEqual(args.type, "nvt") |
| 603 |
args = parser.parse_arguments(["--type", "nvts"]) |
| 604 |
self.assertEqual(args.type, "nvt") |
| 605 |
args = parser.parse_arguments(["--type", "NVT"]) |
| 606 |
self.assertEqual(args.type, "nvt") |
| 607 |
args = parser.parse_arguments(["--type", "NVTS"]) |
| 608 |
self.assertEqual(args.type, "nvt") |
| 609 |
|
| 610 |
args = parser.parse_arguments(["--type", "notus"]) |
| 611 |
self.assertEqual(args.type, "notus") |
| 612 |
args = parser.parse_arguments(["--type", "NOTUS"]) |
| 613 |
self.assertEqual(args.type, "notus") |
| 614 |
args = parser.parse_arguments(["--type", "NoTuS"]) |
| 615 |
self.assertEqual(args.type, "notus") |
| 616 |
|
| 617 |
args = parser.parse_arguments(["--type", "nasl"]) |
| 618 |
self.assertEqual(args.type, "nasl") |
| 619 |
args = parser.parse_arguments(["--type", "NASL"]) |
| 620 |
self.assertEqual(args.type, "nasl") |
| 621 |
args = parser.parse_arguments(["--type", "NaSl"]) |
| 622 |
self.assertEqual(args.type, "nasl") |
| 623 |
|
| 624 |
args = parser.parse_arguments(["--type", "scap"]) |
| 625 |
self.assertEqual(args.type, "scap") |
| 626 |
args = parser.parse_arguments(["--type", "SCAP"]) |
| 627 |
self.assertEqual(args.type, "scap") |
| 628 |
args = parser.parse_arguments(["--type", "ScAp"]) |
| 629 |
self.assertEqual(args.type, "scap") |
| 630 |
|
| 631 |
args = parser.parse_arguments(["--type", "cert"]) |
| 632 |
self.assertEqual(args.type, "cert") |
| 633 |
args = parser.parse_arguments(["--type", "CERT"]) |
| 634 |
self.assertEqual(args.type, "cert") |
| 635 |
args = parser.parse_arguments(["--type", "CeRt"]) |
| 636 |
self.assertEqual(args.type, "cert") |
| 637 |
|
| 638 |
args = parser.parse_arguments(["--type", "all"]) |
| 639 |
self.assertEqual(args.type, "all") |
| 640 |
args = parser.parse_arguments(["--type", "ALL"]) |
| 641 |
self.assertEqual(args.type, "all") |
| 642 |
args = parser.parse_arguments(["--type", "AlL"]) |
| 643 |
self.assertEqual(args.type, "all") |
| 644 |
|
| 645 |
args = parser.parse_arguments(["--type", "report-format"]) |
| 646 |
self.assertEqual(args.type, "report-format") |
| 647 |
args = parser.parse_arguments(["--type", "REPORT-FORMAT"]) |
| 648 |
self.assertEqual(args.type, "report-format") |
| 649 |
args = parser.parse_arguments(["--type", "report_format"]) |
| 650 |
self.assertEqual(args.type, "report-format") |
| 651 |
args = parser.parse_arguments(["--type", "REPORT_FORMAT"]) |
| 652 |
self.assertEqual(args.type, "report-format") |
| 653 |
args = parser.parse_arguments(["--type", "Report-Format"]) |
| 654 |
self.assertEqual(args.type, "report-format") |
| 655 |
args = parser.parse_arguments(["--type", "report-formats"]) |
| 656 |
self.assertEqual(args.type, "report-format") |
| 657 |
args = parser.parse_arguments(["--type", "REPORT_FORMATS"]) |
| 658 |
self.assertEqual(args.type, "report-format") |
| 659 |
|
| 660 |
args = parser.parse_arguments(["--type", "scan-config"]) |
| 661 |
self.assertEqual(args.type, "scan-config") |
| 662 |
args = parser.parse_arguments(["--type", "SCAN-CONFIG"]) |
| 663 |
self.assertEqual(args.type, "scan-config") |
| 664 |
args = parser.parse_arguments(["--type", "scan_config"]) |
| 665 |
self.assertEqual(args.type, "scan-config") |
| 666 |
args = parser.parse_arguments(["--type", "SCAN_config"]) |
| 667 |
self.assertEqual(args.type, "scan-config") |
| 668 |
args = parser.parse_arguments(["--type", "Scan-Config"]) |
| 669 |
self.assertEqual(args.type, "scan-config") |
| 670 |
args = parser.parse_arguments(["--type", "scan-configs"]) |
| 671 |
self.assertEqual(args.type, "scan-config") |
| 672 |
args = parser.parse_arguments(["--type", "SCAN_CONFIGS"]) |
| 673 |
self.assertEqual(args.type, "scan-config") |
| 674 |
|
| 675 |
args = parser.parse_arguments(["--type", "port-list"]) |
| 676 |
self.assertEqual(args.type, "port-list") |
| 677 |
args = parser.parse_arguments(["--type", "PORT-LIST"]) |
| 678 |
self.assertEqual(args.type, "port-list") |
| 679 |
args = parser.parse_arguments(["--type", "port_list"]) |
| 680 |
self.assertEqual(args.type, "port-list") |
| 681 |
args = parser.parse_arguments(["--type", "PORT_LIST"]) |
| 682 |
self.assertEqual(args.type, "port-list") |
| 683 |
args = parser.parse_arguments(["--type", "port-list"]) |
| 684 |
self.assertEqual(args.type, "port-list") |
| 685 |
args = parser.parse_arguments(["--type", "port-lists"]) |
| 686 |
self.assertEqual(args.type, "port-list") |
| 687 |
args = parser.parse_arguments(["--type", "PORT_LISTS"]) |
| 688 |
self.assertEqual(args.type, "port-list") |
| 689 |
|
| 690 |
args = parser.parse_arguments(["--type", "gvmd-data"]) |
| 691 |
self.assertEqual(args.type, "gvmd-data") |
| 692 |
args = parser.parse_arguments(["--type", "GVMD-DATA"]) |
| 693 |
self.assertEqual(args.type, "gvmd-data") |
| 694 |
args = parser.parse_arguments(["--type", "gvmd_data"]) |
| 695 |
self.assertEqual(args.type, "gvmd-data") |
| 696 |
args = parser.parse_arguments(["--type", "GVMD_DATA"]) |
| 697 |
self.assertEqual(args.type, "gvmd-data") |
| 698 |
args = parser.parse_arguments(["--type", "gvmd-data"]) |
| 699 |
self.assertEqual(args.type, "gvmd-data") |
| 700 |
|
| 701 |
def test_group(self): |
| 702 |
parser = CliParser() |
| 703 |
args = parser.parse_arguments(["--group", "some_group"]) |
| 704 |
self.assertEqual(args.group, "some_group") |
| 705 |
|
| 706 |
args = parser.parse_arguments(["--group", "123"]) |
| 707 |
self.assertEqual(args.group, 123) |
| 708 |
|
| 709 |
def test_user(self): |
| 710 |
parser = CliParser() |
| 711 |
args = parser.parse_arguments(["--user", "some_user"]) |
| 712 |
self.assertEqual(args.user, "some_user") |
| 713 |
|
| 714 |
args = parser.parse_arguments(["--user", "123"]) |
| 715 |
self.assertEqual(args.user, 123) |
| 716 |
|
| 717 |
def test_feed_url_from_enterprise_feed_key(self): |
| 718 |
parser = CliParser() |
| 719 |
content = """[email protected]:/feed/ |
| 720 |
Lorem ipsum dolor sit amet, |
| 721 |
consetetur sadipscing elitr, |
| 722 |
sed diam nonumy eirmod tempor |
| 723 |
""" |
| 724 |
with temp_file(content=content, name="enterprise.key") as f: |
| 725 |
args = parser.parse_arguments( |
| 726 |
["--greenbone-enterprise-feed-key", str(f)] |
| 727 |
) |
| 728 |
|
| 729 |
self.assertEqual( |
| 730 |
args.feed_url, "ssh://[email protected]/enterprise" |
| 731 |
) |
| 732 |
self.assertEqual( |
| 733 |
args.gvmd_data_url, |
| 734 |
f"ssh://[email protected]/enterprise/data-feed/{DEFAULT_FEED_RELEASE}/", |
| 735 |
) |
| 736 |
self.assertEqual( |
| 737 |
args.port_lists_url, |
| 738 |
f"ssh://[email protected]/enterprise/data-feed/{DEFAULT_FEED_RELEASE}/port-lists/", |
| 739 |
) |
| 740 |
self.assertEqual( |
| 741 |
args.report_formats_url, |
| 742 |
f"ssh://[email protected]/enterprise/data-feed/{DEFAULT_FEED_RELEASE}/report-formats/", |
| 743 |
) |
| 744 |
self.assertEqual( |
| 745 |
args.scan_configs_url, |
| 746 |
f"ssh://[email protected]/enterprise/data-feed/{DEFAULT_FEED_RELEASE}/scan-configs/", |
| 747 |
) |
| 748 |
self.assertEqual( |
| 749 |
args.notus_url, |
| 750 |
f"ssh://[email protected]/enterprise/vulnerability-feed/{DEFAULT_FEED_RELEASE}/vt-data/notus/", |
| 751 |
) |
| 752 |
self.assertEqual( |
| 753 |
args.nasl_url, |
| 754 |
f"ssh://[email protected]/enterprise/vulnerability-feed/{DEFAULT_FEED_RELEASE}/vt-data/nasl/", |
| 755 |
) |
| 756 |
self.assertEqual( |
| 757 |
args.scap_data_url, |
| 758 |
f"ssh://[email protected]/enterprise/vulnerability-feed/{DEFAULT_FEED_RELEASE}/scap-data/", |
| 759 |
) |
| 760 |
self.assertEqual( |
| 761 |
args.cert_data_url, |
| 762 |
f"ssh://[email protected]/enterprise/vulnerability-feed/{DEFAULT_FEED_RELEASE}/cert-data/", |
| 763 |
) |
| 764 |
|
| 765 |
def test_ignore_non_existing_enterprise_feed_key(self): |
| 766 |
parser = CliParser() |
| 767 |
args = parser.parse_arguments( |
| 768 |
["--greenbone-enterprise-feed-key", "/tmp/some.key"] |
| 769 |
) |
| 770 |
|
| 771 |
self.assertEqual( |
| 772 |
args.feed_url, "rsync://feed.community.greenbone.net/community" |
| 773 |
) |
| 774 |
self.assertEqual( |
| 775 |
args.gvmd_data_url, |
| 776 |
f"rsync://feed.community.greenbone.net/community/data-feed/{DEFAULT_FEED_RELEASE}/", |
| 777 |
) |
| 778 |
self.assertEqual( |
| 779 |
args.port_lists_url, |
| 780 |
f"rsync://feed.community.greenbone.net/community/data-feed/{DEFAULT_FEED_RELEASE}/port-lists/", |
| 781 |
) |
| 782 |
self.assertEqual( |
| 783 |
args.report_formats_url, |
| 784 |
f"rsync://feed.community.greenbone.net/community/data-feed/{DEFAULT_FEED_RELEASE}/report-formats/", |
| 785 |
) |
| 786 |
self.assertEqual( |
| 787 |
args.scan_configs_url, |
| 788 |
f"rsync://feed.community.greenbone.net/community/data-feed/{DEFAULT_FEED_RELEASE}/scan-configs/", |
| 789 |
) |
| 790 |
self.assertEqual( |
| 791 |
args.notus_url, |
| 792 |
f"rsync://feed.community.greenbone.net/community/vulnerability-feed/{DEFAULT_FEED_RELEASE}/vt-data/notus/", |
| 793 |
) |
| 794 |
self.assertEqual( |
| 795 |
args.nasl_url, |
| 796 |
f"rsync://feed.community.greenbone.net/community/vulnerability-feed/{DEFAULT_FEED_RELEASE}/vt-data/nasl/", |
| 797 |
) |
| 798 |
self.assertEqual( |
| 799 |
args.scap_data_url, |
| 800 |
f"rsync://feed.community.greenbone.net/community/vulnerability-feed/{DEFAULT_FEED_RELEASE}/scap-data/", |
| 801 |
) |
| 802 |
self.assertEqual( |
| 803 |
args.cert_data_url, |
| 804 |
f"rsync://feed.community.greenbone.net/community/vulnerability-feed/{DEFAULT_FEED_RELEASE}/cert-data/", |
| 805 |
) |
| 806 |
|
| 807 |
@patch.object(sys, "argv", ["greenbone-nvt-sync"]) |
| 808 |
def test_greenbone_nvt_sync(self): |
| 809 |
parser = CliParser() |
| 810 |
args = parser.parse_arguments([]) |
| 811 |
|
| 812 |
self.assertEqual(args.type, "nvt") |
| 813 |
|
| 814 |
@patch.object(sys, "argv", ["greenbone-scapdata-sync"]) |
| 815 |
def test_greenbone_scap_data_sync(self): |
| 816 |
parser = CliParser() |
| 817 |
args = parser.parse_arguments([]) |
| 818 |
|
| 819 |
self.assertEqual(args.type, "scap") |
| 820 |
|
| 821 |
@patch.object(sys, "argv", ["greenbone-certdata-sync"]) |
| 822 |
def test_greenbone_cert_data_sync(self): |
| 823 |
parser = CliParser() |
| 824 |
args = parser.parse_arguments([]) |
| 825 |
|
| 826 |
self.assertEqual(args.type, "cert") |
| 827 |
|
| 828 |
def test_feed_release(self): |
| 829 |
parser = CliParser() |
| 830 |
feed_release = "1.2.3" |
| 831 |
args = parser.parse_arguments(["--feed-release", feed_release]) |
| 832 |
self.assertTrue(args.feed_release, "1.2.3") |
| 833 |
|
| 834 |
self.assertEqual( |
| 835 |
args.feed_url, "rsync://feed.community.greenbone.net/community" |
| 836 |
) |
| 837 |
self.assertEqual( |
| 838 |
args.gvmd_data_url, |
| 839 |
f"rsync://feed.community.greenbone.net/community/data-feed/{feed_release}/", |
| 840 |
) |
| 841 |
self.assertEqual( |
| 842 |
args.port_lists_url, |
| 843 |
f"rsync://feed.community.greenbone.net/community/data-feed/{feed_release}/port-lists/", |
| 844 |
) |
| 845 |
self.assertEqual( |
| 846 |
args.report_formats_url, |
| 847 |
f"rsync://feed.community.greenbone.net/community/data-feed/{feed_release}/report-formats/", |
| 848 |
) |
| 849 |
self.assertEqual( |
| 850 |
args.scan_configs_url, |
| 851 |
f"rsync://feed.community.greenbone.net/community/data-feed/{feed_release}/scan-configs/", |
| 852 |
) |
| 853 |
self.assertEqual( |
| 854 |
args.notus_url, |
| 855 |
f"rsync://feed.community.greenbone.net/community/vulnerability-feed/{feed_release}/vt-data/notus/", |
| 856 |
) |
| 857 |
self.assertEqual( |
| 858 |
args.nasl_url, |
| 859 |
f"rsync://feed.community.greenbone.net/community/vulnerability-feed/{feed_release}/vt-data/nasl/", |
| 860 |
) |
| 861 |
self.assertEqual( |
| 862 |
args.scap_data_url, |
| 863 |
f"rsync://feed.community.greenbone.net/community/vulnerability-feed/{feed_release}/scap-data/", |
| 864 |
) |
| 865 |
self.assertEqual( |
| 866 |
args.cert_data_url, |
| 867 |
f"rsync://feed.community.greenbone.net/community/vulnerability-feed/{feed_release}/cert-data/", |
| 868 |
) |
| 869 |
|
| 870 |
def test_feed_version(self): |
| 871 |
parser = CliParser() |
| 872 |
feed_release = "1.2.3" |
| 873 |
args = parser.parse_arguments(["--feed-version", feed_release]) |
| 874 |
self.assertTrue(args.feed_version, "1.2.3") |
| 875 |
self.assertTrue(args.feed_release, "1.2.3") |
| 876 |
|
| 877 |
self.assertEqual( |
| 878 |
args.feed_url, "rsync://feed.community.greenbone.net/community" |
| 879 |
) |
| 880 |
self.assertEqual( |
| 881 |
args.gvmd_data_url, |
| 882 |
f"rsync://feed.community.greenbone.net/community/data-feed/{feed_release}/", |
| 883 |
) |
| 884 |
self.assertEqual( |
| 885 |
args.port_lists_url, |
| 886 |
f"rsync://feed.community.greenbone.net/community/data-feed/{feed_release}/port-lists/", |
| 887 |
) |
| 888 |
self.assertEqual( |
| 889 |
args.report_formats_url, |
| 890 |
f"rsync://feed.community.greenbone.net/community/data-feed/{feed_release}/report-formats/", |
| 891 |
) |
| 892 |
self.assertEqual( |
| 893 |
args.scan_configs_url, |
| 894 |
f"rsync://feed.community.greenbone.net/community/data-feed/{feed_release}/scan-configs/", |
| 895 |
) |
| 896 |
self.assertEqual( |
| 897 |
args.notus_url, |
| 898 |
f"rsync://feed.community.greenbone.net/community/vulnerability-feed/{feed_release}/vt-data/notus/", |
| 899 |
) |
| 900 |
self.assertEqual( |
| 901 |
args.nasl_url, |
| 902 |
f"rsync://feed.community.greenbone.net/community/vulnerability-feed/{feed_release}/vt-data/nasl/", |
| 903 |
) |
| 904 |
self.assertEqual( |
| 905 |
args.scap_data_url, |
| 906 |
f"rsync://feed.community.greenbone.net/community/vulnerability-feed/{feed_release}/scap-data/", |
| 907 |
) |
| 908 |
self.assertEqual( |
| 909 |
args.cert_data_url, |
| 910 |
f"rsync://feed.community.greenbone.net/community/vulnerability-feed/{feed_release}/cert-data/", |
| 911 |
) |
| 912 |
|
| 913 |
def test_feed_release_overrules_version(self): |
| 914 |
parser = CliParser() |
| 915 |
feed_release = "1.2.3" |
| 916 |
args = parser.parse_arguments( |
| 917 |
["--feed-version", "2.3.4", "--feed-release", feed_release] |
| 918 |
) |
| 919 |
self.assertTrue(args.feed_version, "2.3.4") |
| 920 |
self.assertTrue(args.feed_release, "1.2.3") |
| 921 |
|
| 922 |
self.assertEqual( |
| 923 |
args.feed_url, "rsync://feed.community.greenbone.net/community" |
| 924 |
) |
| 925 |
self.assertEqual( |
| 926 |
args.gvmd_data_url, |
| 927 |
f"rsync://feed.community.greenbone.net/community/data-feed/{feed_release}/", |
| 928 |
) |
| 929 |
self.assertEqual( |
| 930 |
args.port_lists_url, |
| 931 |
f"rsync://feed.community.greenbone.net/community/data-feed/{feed_release}/port-lists/", |
| 932 |
) |
| 933 |
self.assertEqual( |
| 934 |
args.report_formats_url, |
| 935 |
f"rsync://feed.community.greenbone.net/community/data-feed/{feed_release}/report-formats/", |
| 936 |
) |
| 937 |
self.assertEqual( |
| 938 |
args.scan_configs_url, |
| 939 |
f"rsync://feed.community.greenbone.net/community/data-feed/{feed_release}/scan-configs/", |
| 940 |
) |
| 941 |
self.assertEqual( |
| 942 |
args.notus_url, |
| 943 |
f"rsync://feed.community.greenbone.net/community/vulnerability-feed/{feed_release}/vt-data/notus/", |
| 944 |
) |
| 945 |
self.assertEqual( |
| 946 |
args.nasl_url, |
| 947 |
f"rsync://feed.community.greenbone.net/community/vulnerability-feed/{feed_release}/vt-data/nasl/", |
| 948 |
) |
| 949 |
self.assertEqual( |
| 950 |
args.scap_data_url, |
| 951 |
f"rsync://feed.community.greenbone.net/community/vulnerability-feed/{feed_release}/scap-data/", |
| 952 |
) |
| 953 |
self.assertEqual( |
| 954 |
args.cert_data_url, |
| 955 |
f"rsync://feed.community.greenbone.net/community/vulnerability-feed/{feed_release}/cert-data/", |
| 956 |
) |
| 957 |
|
| 958 |
def test_destination_prefix(self): |
| 959 |
parser = CliParser() |
| 960 |
destination_prefix = "/tmp/foo/bar" |
| 961 |
args = parser.parse_arguments( |
| 962 |
["--destination-prefix", destination_prefix] |
| 963 |
) |
| 964 |
|
| 965 |
self.assertEqual(args.type, "all") |
| 966 |
self.assertEqual(args.destination_prefix, Path(destination_prefix)) |
| 967 |
self.assertEqual( |
| 968 |
args.gvmd_data_destination, |
| 969 |
Path(destination_prefix) / "gvm" / "data-objects" / "gvmd", |
| 970 |
) |
| 971 |
self.assertEqual( |
| 972 |
args.notus_destination, |
| 973 |
Path(destination_prefix) / "notus", |
| 974 |
) |
| 975 |
self.assertEqual( |
| 976 |
args.nasl_destination, |
| 977 |
Path(destination_prefix) / "openvas" / "plugins", |
| 978 |
) |
| 979 |
self.assertEqual( |
| 980 |
args.scap_data_destination, |
| 981 |
Path(destination_prefix) / "gvm" / "scap-data", |
| 982 |
) |
| 983 |
self.assertEqual( |
| 984 |
args.cert_data_destination, |
| 985 |
Path(destination_prefix) / "gvm" / "cert-data", |
| 986 |
) |
| 987 |
self.assertEqual( |
| 988 |
args.report_formats_destination, |
| 989 |
Path(destination_prefix) |
| 990 |
/ "gvm" |
| 991 |
/ "data-objects" |
| 992 |
/ "gvmd" |
| 993 |
/ "report-formats", |
| 994 |
) |
| 995 |
self.assertEqual( |
| 996 |
args.scan_configs_destination, |
| 997 |
Path(destination_prefix) |
| 998 |
/ "gvm" |
| 999 |
/ "data-objects" |
| 1000 |
/ "gvmd" |
| 1001 |
/ "scan-configs", |
| 1002 |
) |
| 1003 |
self.assertEqual( |
| 1004 |
args.port_lists_destination, |
| 1005 |
Path(destination_prefix) |
| 1006 |
/ "gvm" |
| 1007 |
/ "data-objects" |
| 1008 |
/ "gvmd" |
| 1009 |
/ "port-lists", |
| 1010 |
) |
| 1011 |
self.assertEqual( |
| 1012 |
args.gvmd_lock_file, |
| 1013 |
Path(destination_prefix) / DEFAULT_GVMD_LOCK_FILE_PATH, |
| 1014 |
) |
| 1015 |
self.assertEqual( |
| 1016 |
args.openvas_lock_file, |
| 1017 |
Path(destination_prefix) / DEFAULT_OPENVAS_LOCK_FILE_PATH, |
| 1018 |
) |