Example #1
0
 def test_edit_scan_source(self):
     """Testing the edit scan source command successfully."""
     scan_out = StringIO()
     url_get_source = get_server_location() + SOURCE_URI + \
         '?name=source1'
     url_get_scan = get_server_location() + SCAN_URI + '?name=scan1'
     url_patch = get_server_location() + SCAN_URI + '1/'
     source_results = [{
         'id': 1,
         'name': 'source1',
         'cred': 'cred1',
         'hosts': ['1.2.3.4']
     }]
     source_data = {'count': 1, 'results': source_results}
     scan_entry = {'id': 1, 'name': 'scan1', 'sources': ['source2']}
     results = [scan_entry]
     scan_data = {'count': 1, 'results': results}
     with requests_mock.Mocker() as mocker:
         mocker.get(url_get_scan, status_code=200, json=scan_data)
         mocker.get(url_get_source, status_code=200, json=source_data)
         mocker.patch(url_patch, status_code=200, json=scan_entry)
         aec = ScanEditCommand(SUBPARSER)
         args = Namespace(name='scan1',
                          sources=['source1'],
                          max_concurrency=50,
                          disabled_optional_products=None,
                          enabled_ext_product_search=None,
                          ext_product_search_dirs=None)
         with redirect_stdout(scan_out):
             aec.main(args)
             self.assertEqual(scan_out.getvalue(),
                              messages.SCAN_UPDATED % 'scan1' + '\n')
Example #2
0
 def test_edit_scan_reset_dis_products(self):
     """Testing the edit scan command with reset successfully."""
     scan_out = StringIO()
     url_get_scan = get_server_location() + SCAN_URI + '?name=scan1'
     url_patch = get_server_location() + SCAN_URI + '1/'
     scan_entry = {'id': 1, 'name': 'scan1', 'sources': ['source1']}
     updated_entry = {
         'id': 1,
         'name': 'scan1',
         'sources': ['source1'],
         'options': {
             'disabled_optional_products': {
                 'jboss_eap': True,
                 'jboss_fuse': True,
                 'jboss_brms': True
             }
         }
     }
     results = [scan_entry]
     scan_data = {'count': 1, 'results': results}
     with requests_mock.Mocker() as mocker:
         mocker.get(url_get_scan, status_code=200, json=scan_data)
         mocker.patch(url_patch, status_code=200, json=updated_entry)
         aec = ScanEditCommand(SUBPARSER)
         args = Namespace(name='scan1',
                          sources=None,
                          max_concurrency=50,
                          disabled_optional_products=[],
                          enabled_ext_product_search=None,
                          ext_product_search_dirs=None)
         with redirect_stdout(scan_out):
             aec.main(args)
             self.assertEqual(scan_out.getvalue(),
                              messages.SCAN_UPDATED % 'scan1' + '\n')
Example #3
0
 def test_edit_scan_none(self):
     """Testing the edit scan command for non-existing scan."""
     scan_out = StringIO()
     url = get_server_location() + SCAN_URI + '?name=scan_none'
     with requests_mock.Mocker() as mocker:
         mocker.get(url, status_code=200, json={'count': 0})
         aec = ScanEditCommand(SUBPARSER)
         args = Namespace(name='scan_none', sources=['source1'])
         with self.assertRaises(SystemExit):
             with redirect_stdout(scan_out):
                 aec.main(args)
                 aec.main(args)
                 self.assertTrue(messages.SCAN_DOES_NOT_EXIST %
                                 'scan_none' in scan_out.getvalue())
Example #4
0
 def test_edit_scan_no_val(self):
     """Testing the edit scan command with a scan that doesn't exist."""
     scan_out = StringIO()
     url_get_scan = get_server_location() + SCAN_URI + '?name=scan1'
     with requests_mock.Mocker() as mocker:
         mocker.get(url_get_scan, status_code=500, json=None)
         aec = ScanEditCommand(SUBPARSER)
         args = Namespace(name='scan1',
                          sources=['source1'],
                          max_concurrency=50,
                          disabled_optional_products=None,
                          enabled_ext_product_search=None,
                          ext_product_search_dirs=None)
         with self.assertRaises(SystemExit):
             with redirect_stdout(scan_out):
                 aec.main(args)
                 self.assertEqual(scan_out.getvalue(),
                                  messages.SERVER_INTERNAL_ERROR)