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