Exemple #1
0
 def test_enabled_products_only(self):
     """Testing that the enabled-ext-product-search flag works."""
     scan_out = StringIO()
     url_get_source = get_server_location() + SOURCE_URI + '?name=source1'
     url_post = get_server_location() + SCAN_URI
     results = [{
         'id': 1,
         'name': 'scan1',
         'sources': ['source1'],
         'max-concurrency': 4,
         'enabled_extended_product_search': {
             'jboss_eap': True,
             'jboss_fuse': False,
             'jboss_brms': True
         }
     }]
     source_data = {'count': 1, 'results': results}
     with requests_mock.Mocker() as mocker:
         mocker.get(url_get_source, status_code=200, json=source_data)
         mocker.post(url_post, status_code=201, json={'name': 'scan1'})
         ssc = ScanAddCommand(SUBPARSER)
         args = Namespace(
             name='scan1',
             sources=['source1'],
             max_concurrency=50,
             disabled_optional_products=None,
             enabled_ext_product_search=['jboss_eap', 'jboss_brms'],
             ext_product_search_dirs=None)
         with redirect_stdout(scan_out):
             ssc.main(args)
             self.assertEqual(scan_out.getvalue(),
                              messages.SCAN_ADDED % 'scan1' + '\n')
Exemple #2
0
 def test_add_scan_conn_err(self):
     """Testing the add scan command with a connection error."""
     scan_out = StringIO()
     url = get_server_location() + SOURCE_URI + '?name=source1'
     with requests_mock.Mocker() as mocker:
         mocker.get(url, exc=requests.exceptions.ConnectTimeout)
         ssc = ScanAddCommand(SUBPARSER)
         args = Namespace(sources=['source1'])
         with self.assertRaises(SystemExit):
             with redirect_stdout(scan_out):
                 ssc.main(args)
                 self.assertEqual(scan_out.getvalue(), CONNECTION_ERROR_MSG)
Exemple #3
0
 def test_add_scan_bad_resp(self):
     """Testing the add scan command with a 500."""
     scan_out = StringIO()
     url_get_source = get_server_location() + SOURCE_URI + '?name=source1'
     with requests_mock.Mocker() as mocker:
         mocker.get(url_get_source, status_code=500, json=None)
         ssc = ScanAddCommand(SUBPARSER)
         args = Namespace(sources=['source1'], max_concurrency=50)
         with self.assertRaises(SystemExit):
             with redirect_stdout(scan_out):
                 ssc.main(args)
                 self.assertEqual(scan_out.getvalue(),
                                  messages.SERVER_INTERNAL_ERROR)
Exemple #4
0
 def test_scan_source_none(self):
     """Testing the scan add command for none existing source."""
     scan_out = StringIO()
     url = get_server_location() + SOURCE_URI + '?name=source_none'
     with requests_mock.Mocker() as mocker:
         mocker.get(url, status_code=200, json={'count': 0})
         ssc = ScanAddCommand(SUBPARSER)
         args = Namespace(sources=['source_none'])
         with self.assertRaises(SystemExit):
             with redirect_stdout(scan_out):
                 ssc.main(args)
                 ssc.main(args)
                 self.assertTrue('Source "source_none" does not exist' in
                                 scan_out.getvalue())