| @@ 589-616 (lines=28) @@ | ||
| 586 | e, |
|
| 587 | ) |
|
| 588 | ||
| 589 | @patch('ospd_openvas.db.KbDB') |
|
| 590 | def test_snmp_unknown_auth_alg_credentials(self, mock_kb): |
|
| 591 | w = DummyDaemon() |
|
| 592 | ||
| 593 | creds = { |
|
| 594 | 'snmp': { |
|
| 595 | 'type': 'snmp', |
|
| 596 | 'username': 'username', |
|
| 597 | 'password': 'pass', |
|
| 598 | 'community': 'some comunity', |
|
| 599 | 'auth_algorithm': 'sha2', |
|
| 600 | }, |
|
| 601 | } |
|
| 602 | ||
| 603 | w.scan_collection.get_credentials = MagicMock(return_value=creds) |
|
| 604 | ||
| 605 | p = PreferenceHandler('1234-1234', mock_kb, w.scan_collection, None) |
|
| 606 | p.scan_id = '456-789' |
|
| 607 | p.kbdb.add_scan_preferences = MagicMock() |
|
| 608 | r = p.prepare_credentials_for_openvas() |
|
| 609 | e = p.get_error_messages() |
|
| 610 | ||
| 611 | self.assertFalse(r) |
|
| 612 | self.assertIn( |
|
| 613 | "Unknown authentification algorithm: " |
|
| 614 | + "sha2" |
|
| 615 | + ". Use 'md5' or 'sha1'.", |
|
| 616 | e, |
|
| 617 | ) |
|
| 618 | ||
| 619 | @patch('ospd_openvas.db.KbDB') |
|
| @@ 499-526 (lines=28) @@ | ||
| 496 | e, |
|
| 497 | ) |
|
| 498 | ||
| 499 | @patch('ospd_openvas.db.KbDB') |
|
| 500 | def test_snmp_no_priv_alg_but_pw_credentials(self, mock_kb): |
|
| 501 | w = DummyDaemon() |
|
| 502 | ||
| 503 | creds = { |
|
| 504 | 'snmp': { |
|
| 505 | 'type': 'snmp', |
|
| 506 | 'username': 'username', |
|
| 507 | 'password': 'pass', |
|
| 508 | 'community': 'some comunity', |
|
| 509 | 'auth_algorithm': 'sha1', |
|
| 510 | 'privacy_password': 'privacy pass', |
|
| 511 | }, |
|
| 512 | } |
|
| 513 | ||
| 514 | w.scan_collection.get_credentials = MagicMock(return_value=creds) |
|
| 515 | ||
| 516 | p = PreferenceHandler('1234-1234', mock_kb, w.scan_collection, None) |
|
| 517 | p.scan_id = '456-789' |
|
| 518 | p.kbdb.add_scan_preferences = MagicMock() |
|
| 519 | r = p.prepare_credentials_for_openvas() |
|
| 520 | e = p.get_error_messages() |
|
| 521 | ||
| 522 | self.assertFalse(r) |
|
| 523 | self.assertIn( |
|
| 524 | "When no privacy algorithm is used, the privacy" |
|
| 525 | + " password also has to be empty.", |
|
| 526 | e, |
|
| 527 | ) |
|
| 528 | ||
| 529 | @patch('ospd_openvas.db.KbDB') |
|
| @@ 441-468 (lines=28) @@ | ||
| 438 | self.assertFalse(r) |
|
| 439 | self.assertIn("Port for SSH is out of range (1-65535): 65536", e) |
|
| 440 | ||
| 441 | @patch('ospd_openvas.db.KbDB') |
|
| 442 | def test_bad_type_for_ssh_credentials(self, mock_kb): |
|
| 443 | w = DummyDaemon() |
|
| 444 | ||
| 445 | creds = { |
|
| 446 | 'ssh': { |
|
| 447 | 'type': 'ups', |
|
| 448 | 'port': '22', |
|
| 449 | 'username': 'username', |
|
| 450 | 'password': 'pass', |
|
| 451 | }, |
|
| 452 | } |
|
| 453 | ||
| 454 | w.scan_collection.get_credentials = MagicMock(return_value=creds) |
|
| 455 | ||
| 456 | p = PreferenceHandler('1234-1234', mock_kb, w.scan_collection, None) |
|
| 457 | p.scan_id = '456-789' |
|
| 458 | p.kbdb.add_scan_preferences = MagicMock() |
|
| 459 | r = p.prepare_credentials_for_openvas() |
|
| 460 | e = p.get_error_messages() |
|
| 461 | ||
| 462 | self.assertFalse(r) |
|
| 463 | self.assertIn( |
|
| 464 | "Unknown Credential Type for SSH: " |
|
| 465 | + "ups" |
|
| 466 | + ". Use 'up' for Username + Password" |
|
| 467 | + " or 'usk' for Username + SSH Key.", |
|
| 468 | e, |
|
| 469 | ) |
|
| 470 | ||
| 471 | @patch('ospd_openvas.db.KbDB') |
|
| @@ 561-586 (lines=26) @@ | ||
| 558 | e, |
|
| 559 | ) |
|
| 560 | ||
| 561 | @patch('ospd_openvas.db.KbDB') |
|
| 562 | def test_snmp_missing_auth_alg_credentials(self, mock_kb): |
|
| 563 | w = DummyDaemon() |
|
| 564 | ||
| 565 | creds = { |
|
| 566 | 'snmp': { |
|
| 567 | 'type': 'snmp', |
|
| 568 | 'username': 'username', |
|
| 569 | 'password': 'pass', |
|
| 570 | 'community': 'some comunity', |
|
| 571 | }, |
|
| 572 | } |
|
| 573 | ||
| 574 | w.scan_collection.get_credentials = MagicMock(return_value=creds) |
|
| 575 | ||
| 576 | p = PreferenceHandler('1234-1234', mock_kb, w.scan_collection, None) |
|
| 577 | p.scan_id = '456-789' |
|
| 578 | p.kbdb.add_scan_preferences = MagicMock() |
|
| 579 | r = p.prepare_credentials_for_openvas() |
|
| 580 | e = p.get_error_messages() |
|
| 581 | ||
| 582 | self.assertFalse(r) |
|
| 583 | self.assertIn( |
|
| 584 | "Missing authentification algorithm for SNMP." |
|
| 585 | + " Use 'md5' or 'sha1'.", |
|
| 586 | e, |
|
| 587 | ) |
|
| 588 | ||
| 589 | @patch('ospd_openvas.db.KbDB') |
|
| @@ 471-496 (lines=26) @@ | ||
| 468 | e, |
|
| 469 | ) |
|
| 470 | ||
| 471 | @patch('ospd_openvas.db.KbDB') |
|
| 472 | def test_missing_type_for_ssh_credentials(self, mock_kb): |
|
| 473 | w = DummyDaemon() |
|
| 474 | ||
| 475 | creds = { |
|
| 476 | 'ssh': { |
|
| 477 | 'port': '22', |
|
| 478 | 'username': 'username', |
|
| 479 | 'password': 'pass', |
|
| 480 | }, |
|
| 481 | } |
|
| 482 | ||
| 483 | w.scan_collection.get_credentials = MagicMock(return_value=creds) |
|
| 484 | ||
| 485 | p = PreferenceHandler('1234-1234', mock_kb, w.scan_collection, None) |
|
| 486 | p.scan_id = '456-789' |
|
| 487 | p.kbdb.add_scan_preferences = MagicMock() |
|
| 488 | r = p.prepare_credentials_for_openvas() |
|
| 489 | e = p.get_error_messages() |
|
| 490 | ||
| 491 | self.assertFalse(r) |
|
| 492 | self.assertIn( |
|
| 493 | "Missing Credential Type for SSH." |
|
| 494 | + " Use 'up' for Username + Password" |
|
| 495 | + " or 'usk' for Username + SSH Key.", |
|
| 496 | e, |
|
| 497 | ) |
|
| 498 | ||
| 499 | @patch('ospd_openvas.db.KbDB') |
|
| @@ 347-370 (lines=24) @@ | ||
| 344 | self.assertTrue(r) |
|
| 345 | assert_called_once(p.kbdb.add_credentials_to_scan_preferences) |
|
| 346 | ||
| 347 | @patch('ospd_openvas.db.KbDB') |
|
| 348 | def test_set_bad_service_credentials(self, mock_kb): |
|
| 349 | w = DummyDaemon() |
|
| 350 | ||
| 351 | # bad cred type shh instead of ssh |
|
| 352 | creds = { |
|
| 353 | 'shh': { |
|
| 354 | 'type': 'up', |
|
| 355 | 'port': '22', |
|
| 356 | 'username': 'username', |
|
| 357 | 'password': 'pass', |
|
| 358 | }, |
|
| 359 | } |
|
| 360 | ||
| 361 | w.scan_collection.get_credentials = MagicMock(return_value=creds) |
|
| 362 | ||
| 363 | p = PreferenceHandler('1234-1234', mock_kb, w.scan_collection, None) |
|
| 364 | p.scan_id = '456-789' |
|
| 365 | p.kbdb.add_scan_preferences = MagicMock() |
|
| 366 | r = p.prepare_credentials_for_openvas() |
|
| 367 | e = p.get_error_messages() |
|
| 368 | ||
| 369 | self.assertFalse(r) |
|
| 370 | self.assertIn("Unknown service type for credential: shh", e) |
|
| 371 | ||
| 372 | @patch('ospd_openvas.db.KbDB') |
|
| 373 | def test_set_bad_ssh_port_credentials(self, mock_kb): |
|
| @@ 417-439 (lines=23) @@ | ||
| 414 | ||
| 415 | self.assertTrue(r) |
|
| 416 | ||
| 417 | @patch('ospd_openvas.db.KbDB') |
|
| 418 | def test_ssh_port_out_of_range_credentials(self, mock_kb): |
|
| 419 | w = DummyDaemon() |
|
| 420 | ||
| 421 | creds = { |
|
| 422 | 'ssh': { |
|
| 423 | 'type': 'up', |
|
| 424 | 'port': '65536', |
|
| 425 | 'username': 'username', |
|
| 426 | 'password': 'pass', |
|
| 427 | }, |
|
| 428 | } |
|
| 429 | ||
| 430 | w.scan_collection.get_credentials = MagicMock(return_value=creds) |
|
| 431 | ||
| 432 | p = PreferenceHandler('1234-1234', mock_kb, w.scan_collection, None) |
|
| 433 | p.scan_id = '456-789' |
|
| 434 | p.kbdb.add_scan_preferences = MagicMock() |
|
| 435 | r = p.prepare_credentials_for_openvas() |
|
| 436 | e = p.get_error_messages() |
|
| 437 | ||
| 438 | self.assertFalse(r) |
|
| 439 | self.assertIn("Port for SSH is out of range (1-65535): 65536", e) |
|
| 440 | ||
| 441 | @patch('ospd_openvas.db.KbDB') |
|
| 442 | def test_bad_type_for_ssh_credentials(self, mock_kb): |
|
| @@ 372-394 (lines=23) @@ | ||
| 369 | self.assertFalse(r) |
|
| 370 | self.assertIn("Unknown service type for credential: shh", e) |
|
| 371 | ||
| 372 | @patch('ospd_openvas.db.KbDB') |
|
| 373 | def test_set_bad_ssh_port_credentials(self, mock_kb): |
|
| 374 | w = DummyDaemon() |
|
| 375 | ||
| 376 | creds = { |
|
| 377 | 'ssh': { |
|
| 378 | 'type': 'up', |
|
| 379 | 'port': 'ab', |
|
| 380 | 'username': 'username', |
|
| 381 | 'password': 'pass', |
|
| 382 | }, |
|
| 383 | } |
|
| 384 | ||
| 385 | w.scan_collection.get_credentials = MagicMock(return_value=creds) |
|
| 386 | ||
| 387 | p = PreferenceHandler('1234-1234', mock_kb, w.scan_collection, None) |
|
| 388 | p.scan_id = '456-789' |
|
| 389 | p.kbdb.add_scan_preferences = MagicMock() |
|
| 390 | r = p.prepare_credentials_for_openvas() |
|
| 391 | e = p.get_error_messages() |
|
| 392 | ||
| 393 | self.assertFalse(r) |
|
| 394 | self.assertIn("Port for SSH 'ab' is not a valid number.", e) |
|
| 395 | ||
| 396 | @patch('ospd_openvas.db.KbDB') |
|
| 397 | def test_missing_ssh_port_credentials(self, mock_kb): |
|