| @@ 669-698 (lines=30) @@ | ||
| 666 | errors, |
|
| 667 | ) |
|
| 668 | ||
| 669 | @patch('ospd_openvas.db.KbDB') |
|
| 670 | def test_snmp_unknown_auth_alg_credentials(self, mock_kb): |
|
| 671 | dummy = DummyDaemon() |
|
| 672 | ||
| 673 | creds = { |
|
| 674 | 'snmp': { |
|
| 675 | 'type': 'snmp', |
|
| 676 | 'username': 'username', |
|
| 677 | 'password': 'pass', |
|
| 678 | 'community': 'some comunity', |
|
| 679 | 'auth_algorithm': 'sha2', |
|
| 680 | }, |
|
| 681 | } |
|
| 682 | ||
| 683 | dummy.scan_collection.get_credentials = MagicMock(return_value=creds) |
|
| 684 | ||
| 685 | p_handler = PreferenceHandler( |
|
| 686 | '1234-1234', mock_kb, dummy.scan_collection, None |
|
| 687 | ) |
|
| 688 | p_handler.scan_id = '456-789' |
|
| 689 | p_handler.kbdb.add_scan_preferences = MagicMock() |
|
| 690 | ret = p_handler.prepare_credentials_for_openvas() |
|
| 691 | errors = p_handler.get_error_messages() |
|
| 692 | ||
| 693 | self.assertFalse(ret) |
|
| 694 | self.assertIn( |
|
| 695 | "Unknown authentication algorithm: " |
|
| 696 | + "sha2" |
|
| 697 | + ". Use 'md5' or 'sha1'.", |
|
| 698 | errors, |
|
| 699 | ) |
|
| 700 | ||
| 701 | @patch('ospd_openvas.db.KbDB') |
|
| @@ 573-602 (lines=30) @@ | ||
| 570 | errors, |
|
| 571 | ) |
|
| 572 | ||
| 573 | @patch('ospd_openvas.db.KbDB') |
|
| 574 | def test_snmp_no_priv_alg_but_pw_credentials(self, mock_kb): |
|
| 575 | dummy = DummyDaemon() |
|
| 576 | ||
| 577 | creds = { |
|
| 578 | 'snmp': { |
|
| 579 | 'type': 'snmp', |
|
| 580 | 'username': 'username', |
|
| 581 | 'password': 'pass', |
|
| 582 | 'community': 'some comunity', |
|
| 583 | 'auth_algorithm': 'sha1', |
|
| 584 | 'privacy_password': 'privacy pass', |
|
| 585 | }, |
|
| 586 | } |
|
| 587 | ||
| 588 | dummy.scan_collection.get_credentials = MagicMock(return_value=creds) |
|
| 589 | ||
| 590 | p_handler = PreferenceHandler( |
|
| 591 | '1234-1234', mock_kb, dummy.scan_collection, None |
|
| 592 | ) |
|
| 593 | p_handler.scan_id = '456-789' |
|
| 594 | p_handler.kbdb.add_scan_preferences = MagicMock() |
|
| 595 | ret = p_handler.prepare_credentials_for_openvas() |
|
| 596 | errors = p_handler.get_error_messages() |
|
| 597 | ||
| 598 | self.assertFalse(ret) |
|
| 599 | self.assertIn( |
|
| 600 | "When no privacy algorithm is used, the privacy" |
|
| 601 | + " password also has to be empty.", |
|
| 602 | errors, |
|
| 603 | ) |
|
| 604 | ||
| 605 | @patch('ospd_openvas.db.KbDB') |
|
| @@ 511-540 (lines=30) @@ | ||
| 508 | self.assertFalse(ret) |
|
| 509 | self.assertIn("Port for SSH is out of range (1-65535): 65536", errors) |
|
| 510 | ||
| 511 | @patch('ospd_openvas.db.KbDB') |
|
| 512 | def test_bad_type_for_ssh_credentials(self, mock_kb): |
|
| 513 | dummy = DummyDaemon() |
|
| 514 | ||
| 515 | creds = { |
|
| 516 | 'ssh': { |
|
| 517 | 'type': 'ups', |
|
| 518 | 'port': '22', |
|
| 519 | 'username': 'username', |
|
| 520 | 'password': 'pass', |
|
| 521 | }, |
|
| 522 | } |
|
| 523 | ||
| 524 | dummy.scan_collection.get_credentials = MagicMock(return_value=creds) |
|
| 525 | ||
| 526 | p_handler = PreferenceHandler( |
|
| 527 | '1234-1234', mock_kb, dummy.scan_collection, None |
|
| 528 | ) |
|
| 529 | p_handler.scan_id = '456-789' |
|
| 530 | p_handler.kbdb.add_scan_preferences = MagicMock() |
|
| 531 | ret = p_handler.prepare_credentials_for_openvas() |
|
| 532 | errors = p_handler.get_error_messages() |
|
| 533 | ||
| 534 | self.assertFalse(ret) |
|
| 535 | self.assertIn( |
|
| 536 | "Unknown Credential Type for SSH: " |
|
| 537 | + "ups" |
|
| 538 | + ". Use 'up' for Username + Password" |
|
| 539 | + " or 'usk' for Username + SSH Key.", |
|
| 540 | errors, |
|
| 541 | ) |
|
| 542 | ||
| 543 | @patch('ospd_openvas.db.KbDB') |
|
| @@ 639-666 (lines=28) @@ | ||
| 636 | errors, |
|
| 637 | ) |
|
| 638 | ||
| 639 | @patch('ospd_openvas.db.KbDB') |
|
| 640 | def test_snmp_missing_auth_alg_credentials(self, mock_kb): |
|
| 641 | dummy = DummyDaemon() |
|
| 642 | ||
| 643 | creds = { |
|
| 644 | 'snmp': { |
|
| 645 | 'type': 'snmp', |
|
| 646 | 'username': 'username', |
|
| 647 | 'password': 'pass', |
|
| 648 | 'community': 'some comunity', |
|
| 649 | }, |
|
| 650 | } |
|
| 651 | ||
| 652 | dummy.scan_collection.get_credentials = MagicMock(return_value=creds) |
|
| 653 | ||
| 654 | p_handler = PreferenceHandler( |
|
| 655 | '1234-1234', mock_kb, dummy.scan_collection, None |
|
| 656 | ) |
|
| 657 | p_handler.scan_id = '456-789' |
|
| 658 | p_handler.kbdb.add_scan_preferences = MagicMock() |
|
| 659 | ret = p_handler.prepare_credentials_for_openvas() |
|
| 660 | errors = p_handler.get_error_messages() |
|
| 661 | ||
| 662 | self.assertFalse(ret) |
|
| 663 | self.assertIn( |
|
| 664 | "Missing authentication algorithm for SNMP." |
|
| 665 | + " Use 'md5' or 'sha1'.", |
|
| 666 | errors, |
|
| 667 | ) |
|
| 668 | ||
| 669 | @patch('ospd_openvas.db.KbDB') |
|
| @@ 543-570 (lines=28) @@ | ||
| 540 | errors, |
|
| 541 | ) |
|
| 542 | ||
| 543 | @patch('ospd_openvas.db.KbDB') |
|
| 544 | def test_missing_type_for_ssh_credentials(self, mock_kb): |
|
| 545 | dummy = DummyDaemon() |
|
| 546 | ||
| 547 | creds = { |
|
| 548 | 'ssh': { |
|
| 549 | 'port': '22', |
|
| 550 | 'username': 'username', |
|
| 551 | 'password': 'pass', |
|
| 552 | }, |
|
| 553 | } |
|
| 554 | ||
| 555 | dummy.scan_collection.get_credentials = MagicMock(return_value=creds) |
|
| 556 | ||
| 557 | p_handler = PreferenceHandler( |
|
| 558 | '1234-1234', mock_kb, dummy.scan_collection, None |
|
| 559 | ) |
|
| 560 | p_handler.scan_id = '456-789' |
|
| 561 | p_handler.kbdb.add_scan_preferences = MagicMock() |
|
| 562 | ret = p_handler.prepare_credentials_for_openvas() |
|
| 563 | errors = p_handler.get_error_messages() |
|
| 564 | ||
| 565 | self.assertFalse(ret) |
|
| 566 | self.assertIn( |
|
| 567 | "Missing Credential Type for SSH." |
|
| 568 | + " Use 'up' for Username + Password" |
|
| 569 | + " or 'usk' for Username + SSH Key.", |
|
| 570 | errors, |
|
| 571 | ) |
|
| 572 | ||
| 573 | @patch('ospd_openvas.db.KbDB') |
|
| @@ 409-434 (lines=26) @@ | ||
| 406 | self.assertTrue(ret) |
|
| 407 | assert_called_once(p_handler.kbdb.add_credentials_to_scan_preferences) |
|
| 408 | ||
| 409 | @patch('ospd_openvas.db.KbDB') |
|
| 410 | def test_set_bad_service_credentials(self, mock_kb): |
|
| 411 | dummy = DummyDaemon() |
|
| 412 | ||
| 413 | # bad cred type shh instead of ssh |
|
| 414 | creds = { |
|
| 415 | 'shh': { |
|
| 416 | 'type': 'up', |
|
| 417 | 'port': '22', |
|
| 418 | 'username': 'username', |
|
| 419 | 'password': 'pass', |
|
| 420 | }, |
|
| 421 | } |
|
| 422 | ||
| 423 | dummy.scan_collection.get_credentials = MagicMock(return_value=creds) |
|
| 424 | ||
| 425 | p_handler = PreferenceHandler( |
|
| 426 | '1234-1234', mock_kb, dummy.scan_collection, None |
|
| 427 | ) |
|
| 428 | p_handler.scan_id = '456-789' |
|
| 429 | p_handler.kbdb.add_scan_preferences = MagicMock() |
|
| 430 | ret = p_handler.prepare_credentials_for_openvas() |
|
| 431 | errors = p_handler.get_error_messages() |
|
| 432 | ||
| 433 | self.assertFalse(ret) |
|
| 434 | self.assertIn("Unknown service type for credential: shh", errors) |
|
| 435 | ||
| 436 | @patch('ospd_openvas.db.KbDB') |
|
| 437 | def test_set_bad_ssh_port_credentials(self, mock_kb): |
|
| @@ 485-509 (lines=25) @@ | ||
| 482 | ||
| 483 | self.assertTrue(ret) |
|
| 484 | ||
| 485 | @patch('ospd_openvas.db.KbDB') |
|
| 486 | def test_ssh_port_out_of_range_credentials(self, mock_kb): |
|
| 487 | dummy = DummyDaemon() |
|
| 488 | ||
| 489 | creds = { |
|
| 490 | 'ssh': { |
|
| 491 | 'type': 'up', |
|
| 492 | 'port': '65536', |
|
| 493 | 'username': 'username', |
|
| 494 | 'password': 'pass', |
|
| 495 | }, |
|
| 496 | } |
|
| 497 | ||
| 498 | dummy.scan_collection.get_credentials = MagicMock(return_value=creds) |
|
| 499 | ||
| 500 | p_handler = PreferenceHandler( |
|
| 501 | '1234-1234', mock_kb, dummy.scan_collection, None |
|
| 502 | ) |
|
| 503 | p_handler.scan_id = '456-789' |
|
| 504 | p_handler.kbdb.add_scan_preferences = MagicMock() |
|
| 505 | ret = p_handler.prepare_credentials_for_openvas() |
|
| 506 | errors = p_handler.get_error_messages() |
|
| 507 | ||
| 508 | self.assertFalse(ret) |
|
| 509 | self.assertIn("Port for SSH is out of range (1-65535): 65536", errors) |
|
| 510 | ||
| 511 | @patch('ospd_openvas.db.KbDB') |
|
| 512 | def test_bad_type_for_ssh_credentials(self, mock_kb): |
|
| @@ 436-460 (lines=25) @@ | ||
| 433 | self.assertFalse(ret) |
|
| 434 | self.assertIn("Unknown service type for credential: shh", errors) |
|
| 435 | ||
| 436 | @patch('ospd_openvas.db.KbDB') |
|
| 437 | def test_set_bad_ssh_port_credentials(self, mock_kb): |
|
| 438 | dummy = DummyDaemon() |
|
| 439 | ||
| 440 | creds = { |
|
| 441 | 'ssh': { |
|
| 442 | 'type': 'up', |
|
| 443 | 'port': 'ab', |
|
| 444 | 'username': 'username', |
|
| 445 | 'password': 'pass', |
|
| 446 | }, |
|
| 447 | } |
|
| 448 | ||
| 449 | dummy.scan_collection.get_credentials = MagicMock(return_value=creds) |
|
| 450 | ||
| 451 | p_handler = PreferenceHandler( |
|
| 452 | '1234-1234', mock_kb, dummy.scan_collection, None |
|
| 453 | ) |
|
| 454 | p_handler.scan_id = '456-789' |
|
| 455 | p_handler.kbdb.add_scan_preferences = MagicMock() |
|
| 456 | ret = p_handler.prepare_credentials_for_openvas() |
|
| 457 | errors = p_handler.get_error_messages() |
|
| 458 | ||
| 459 | self.assertFalse(ret) |
|
| 460 | self.assertIn("Port for SSH 'ab' is not a valid number.", errors) |
|
| 461 | ||
| 462 | @patch('ospd_openvas.db.KbDB') |
|
| 463 | def test_missing_ssh_port_credentials(self, mock_kb): |
|