Exemple #1
0
    def test_merge_jobs_no_results(self):
        """Test merge job no results."""
        # pylint: disable=no-member
        scan_job1, _ = create_scan_job(
            self.source, ScanTask.SCAN_TYPE_INSPECT,
            scan_name='test1')

        scan_job2, _ = create_scan_job(
            self.source, ScanTask.SCAN_TYPE_INSPECT,
            scan_name='test2')

        scan_job1.status = ScanTask.COMPLETED
        scan_job1.save()

        scan_job2.status = ScanTask.COMPLETED
        scan_job2.save()

        url = reverse('scanjob-merge')
        data = {'jobs': [scan_job1.id, scan_job2.id]}
        response = self.client.put(url, json.dumps(data),
                                   content_type='application/json',
                                   format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        json_response = response.json()
        validation_result = {'sources': 'Required. May not be null or empty.'}
        error_message = messages.SJ_MERGE_JOB_NO_RESULTS % validation_result
        self.assertEqual(
            json_response, {'jobs': [error_message]})
Exemple #2
0
    def test_pause_restart_task(self):
        """Test pause and restart task."""
        scan_job, _ = create_scan_job(
            self.source, scan_type=ScanTask.SCAN_TYPE_CONNECT)

        # Queue job to run
        scan_job.queue()
        self.assertEqual(scan_job.status, ScanTask.PENDING)

        # Queue should have created scan tasks
        tasks = scan_job.tasks.all()
        self.assertEqual(len(tasks), 1)
        connect_task = scan_job.tasks.first()
        self.assertEqual(connect_task.status, ScanTask.PENDING)

        # Start job
        scan_job.start()
        self.assertEqual(scan_job.status, ScanTask.RUNNING)

        scan_job.pause()
        connect_task = scan_job.tasks.first()
        self.assertEqual(scan_job.status, ScanTask.PAUSED)
        self.assertEqual(connect_task.status, ScanTask.PAUSED)

        scan_job.restart()
        connect_task = scan_job.tasks.first()
        self.assertEqual(scan_job.status, ScanTask.RUNNING)
        self.assertEqual(connect_task.status, ScanTask.PENDING)

        scan_job.cancel()
        connect_task = scan_job.tasks.first()
        self.assertEqual(scan_job.status, ScanTask.CANCELED)
        self.assertEqual(connect_task.status, ScanTask.CANCELED)
    def setUp(self):
        """Create test case setup."""
        self.cred = Credential(name='cred1',
                               cred_type=Credential.SATELLITE_CRED_TYPE,
                               username='******',
                               password='******',
                               become_password=None,
                               become_method=None,
                               become_user=None,
                               ssh_keyfile=None)
        self.cred.save()

        self.source = Source(name='source1', port=443, hosts='["1.2.3.4"]')

        self.source.save()
        self.source.credentials.add(self.cred)

        self.scan_job, self.scan_task = create_scan_job(
            self.source, ScanTask.SCAN_TYPE_INSPECT)

        self.api = SatelliteFive(self.scan_job, self.scan_task)
        connection_results = TaskConnectionResult()
        connection_results.save()
        self.api.connect_scan_task.connection_result = connection_results
        self.api.connect_scan_task.connection_result.save()

        sys_result = SystemConnectionResult(
            name='sys1_1', status=SystemInspectionResult.SUCCESS)
        sys_result.save()
        self.api.connect_scan_task.connection_result.systems.add(sys_result)
        self.api.connect_scan_task.connection_result.save()
        self.api.connect_scan_task.save()
Exemple #4
0
    def test_queue_invalid_state_changes(self):
        """Test create queue failed."""
        scan_job, _ = create_scan_job(
            self.source, scan_type=ScanTask.SCAN_TYPE_INSPECT)
        scan_job.status = ScanTask.FAILED

        # Queue job to run
        scan_job.queue()
        self.assertEqual(scan_job.status, ScanTask.FAILED)

        scan_job.complete()
        self.assertEqual(scan_job.status, ScanTask.FAILED)

        scan_job.pause()
        self.assertEqual(scan_job.status, ScanTask.FAILED)

        scan_job.start()
        self.assertEqual(scan_job.status, ScanTask.FAILED)

        scan_job.cancel()
        self.assertEqual(scan_job.status, ScanTask.FAILED)

        scan_job.restart()
        self.assertEqual(scan_job.status, ScanTask.FAILED)

        scan_job.fail('test failure')
        self.assertEqual(scan_job.status, ScanTask.FAILED)

        scan_job.status = ScanTask.CREATED
        scan_job.fail('test failure')
        self.assertEqual(scan_job.status, ScanTask.CREATED)

        scan_job.status = ScanTask.RUNNING
        scan_job.complete()
        self.assertEqual(scan_job.status, ScanTask.COMPLETED)
    def test_scan_with_options(self, mock_run):
        """Setup second scan with scan and source options."""
        # setup source with paramiko option for scan
        source_options = SourceOptions()
        source_options.save()
        self.source = Source(name='source2',
                             port=22,
                             options=source_options,
                             hosts='["1.2.3.4"]')
        self.source.save()
        self.source.credentials.add(self.cred)

        # setup scan with options
        extended = ExtendedProductSearchOptions()
        extended.save()
        scan_options = ScanOptions(enabled_extended_product_search=extended)
        scan_options.save()

        self.scan_job, self.scan_task = create_scan_job(
            self.source,
            ScanTask.SCAN_TYPE_INSPECT,
            'scan2',
            scan_options=scan_options)

        # run scan
        scanner = InspectTaskRunner(self.scan_job, self.scan_task)

        scanner.connect_scan_task = self.connect_scan_task
        scanner._inspect_scan(self.host_list)
        mock_run.assert_called_with(ANY)
    def setUp(self):
        """Create test case setup."""
        self.cred = Credential(
            name='cred1',
            cred_type=Credential.SATELLITE_CRED_TYPE,
            username='******',
            password='******',
            become_password=None,
            become_method=None,
            become_user=None,
            ssh_keyfile=None)
        self.cred.save()

        self.source = Source(
            name='source1',
            port=443,
            hosts='["1.2.3.4"]')

        self.source.save()
        self.source.credentials.add(self.cred)

        self.scan_job, self.scan_task = create_scan_job(
            self.source, ScanTask.SCAN_TYPE_INSPECT)

        self.api = SatelliteFive(self.scan_task)
Exemple #7
0
    def test_format_source(self):
        """Test the format source method."""
        start = datetime.now()
        source = Source(
            name='source1',
            hosts=json.dumps(['1.2.3.4']),
            source_type='network',
            port=22)
        source.save()
        end = datetime.now()
        scan_job, scan_task = create_scan_job(source)
        scan_task.update_stats(
            '', sys_count=10, sys_scanned=9, sys_failed=1, sys_unreachable=0)
        scan_job.start_time = start
        scan_job.end_time = end
        scan_job.status = ScanTask.COMPLETED
        scan_job.save()
        source.most_recent_connect_scan = scan_job
        source.save()

        serializer = SourceSerializer(source)
        json_source = serializer.data
        out = format_source(json_source)

        # pylint: disable=line-too-long
        expected = {'id': 1, 'name': 'source1', 'source_type': 'network', 'port': 22, 'hosts': ['1.2.3.4'], 'connection': {'id': 1, 'start_time': start, 'end_time': end, 'systems_count': 10, 'systems_scanned': 9, 'systems_failed': 1, 'systems_unreachable': 0, 'status_details': {'job_status_message': 'Job is pending.'}, 'status': 'completed', 'source_systems_count': 10, 'source_systems_scanned': 9, 'source_systems_failed': 1, 'source_systems_unreachable': 0}}  # noqa
        self.assertEqual(out, expected)
Exemple #8
0
    def test_expand_scan(self):
        """Test view expand_scan."""
        scan_job, scan_task = create_scan_job(
            self.source, scan_type=ScanTask.SCAN_TYPE_INSPECT)

        scan_task.update_stats('TEST_VC.',
                               sys_count=2,
                               sys_failed=1,
                               sys_scanned=1,
                               sys_unreachable=0)

        serializer = ScanSerializer(scan_job.scan)
        json_scan = serializer.data
        json_scan = expand_scan(json_scan)

        self.assertEqual(
            json_scan.get('sources').first().get('name'), 'source1')
        self.assertEqual(
            json_scan.get('most_recent'), {
                'id': 1,
                'scan_type': 'inspect',
                'status': 'pending',
                'status_details': {
                    'job_status_message': 'Job is pending.'
                }
            })
Exemple #9
0
    def test_get_extra_vars_false(self):
        """Tests the get_extra_vars method with all False."""
        extended = ExtendedProductSearchOptions()
        extended.save()
        disabled = DisabledOptionalProductsOptions(
            jboss_eap=True,
            jboss_fuse=True,
            jboss_brms=True)
        disabled.save()
        scan_options = ScanOptions(
            disabled_optional_products=disabled,
            enabled_extended_product_search=extended)
        scan_options.save()
        scan_job, _ = create_scan_job(self.source,
                                      ScanTask.SCAN_TYPE_INSPECT,
                                      scan_options=scan_options)

        extra_vars = scan_job.options.get_extra_vars()

        expected_vars = {'jboss_eap': False,
                         'jboss_fuse': False,
                         'jboss_brms': False,
                         'jboss_eap_ext': False,
                         'jboss_fuse_ext': False,
                         'jboss_brms_ext': False}
        self.assertEqual(extra_vars, expected_vars)
Exemple #10
0
    def test_expand_inspect_results(self):
        """Test view expand_inspect_results."""
        # pylint: disable=no-member
        scan_job, scan_task = create_scan_job(self.source,
                                              ScanTask.SCAN_TYPE_INSPECT)

        sys_result = SystemInspectionResult(name='Foo',
                                            status=SystemConnectionResult
                                            .SUCCESS)
        sys_result.save()

        fact = RawFact(name='foo', value='"value"')
        fact.save()

        sys_result.facts.add(fact)
        sys_result.save()

        inspect_result = scan_task.inspection_result
        inspect_result.systems.add(sys_result)
        inspect_result.save()

        inspect_results_json = {'task_results': [{}]}
        expand_inspect_results(
            scan_job.inspection_results, inspect_results_json)
        self.assertEqual(
            inspect_results_json['task_results'][0]['systems'][0]
            ['facts'][0]['name'],
            'foo')
    def setUp(self):
        """Create test case setup."""
        self.cred = Credential(
            name='cred1',
            cred_type=Credential.SATELLITE_CRED_TYPE,
            username='******',
            password='******',
            become_password=None,
            become_method=None,
            become_user=None,
            ssh_keyfile=None)
        self.cred.save()

        self.source = Source(
            name='source1',
            port=443,
            hosts='["1.2.3.4"]')
        self.source.save()
        self.source.credentials.add(self.cred)
        self.options = SourceOptions(ssl_cert_verify=False)
        self.options.save()
        self.source.options = self.options
        self.source.save()

        self.scan_job, self.scan_task = create_scan_job(
            self.source, scan_type=ScanTask.SCAN_TYPE_CONNECT)
Exemple #12
0
    def test_format_source(self):
        """Test the format source method."""
        start = datetime.now()
        source = Source(
            name='source1',
            hosts=json.dumps(['1.2.3.4']),
            source_type='network',
            port=22)
        source.save()
        end = datetime.now()
        scan_job, scan_task = create_scan_job(source)
        scan_task.update_stats('', sys_count=10, sys_scanned=9, sys_failed=1)
        scan_job.start_time = start
        scan_job.end_time = end
        scan_job.status = ScanTask.COMPLETED
        scan_job.save()

        serializer = SourceSerializer(source)
        json_source = serializer.data
        out = format_source(json_source)
        expected = {'id': 1,
                    'name': 'source1',
                    'source_type': 'network',
                    'port': 22,
                    'hosts': ['1.2.3.4'],
                    'connection': {'id': 1, 'start_time': start,
                                   'end_time': end, 'status': 'completed',
                                   'systems_count': 10,
                                   'systems_scanned': 9,
                                   'systems_failed': 1}}

        self.assertEqual(out, expected)
Exemple #13
0
    def create_scan_job(self):
        """Create scan job for tests."""
        scan_job, inspect_task = create_scan_job(self.source,
                                                 ScanTask.SCAN_TYPE_INSPECT)

        inspect_task.update_stats('TEST_SAT.', sys_scanned=0)
        return scan_job, inspect_task
Exemple #14
0
    def setUp(self):
        """Create test case setup."""
        self.cred = Credential(
            name='cred1',
            username='******',
            password='******',
            ssh_keyfile=None,
            become_method=None,
            become_user=None,
            become_password=None)
        self.cred.save()

        hc_serializer = CredentialSerializer(self.cred)
        self.cred_data = hc_serializer.data

        self.source = Source(
            name='source1',
            port=22,
            hosts='["1.2.3.4"]')
        self.source.save()
        self.source.credentials.add(self.cred)

        self.host_list = [('1.2.3.4', self.cred_data)]

        # setup scan options

        self.scan_job, self.scan_task = create_scan_job(
            self.source,
            ScanTask.SCAN_TYPE_INSPECT)

        self.connect_scan_task = self.scan_task.prerequisites.first()
        self.connect_scan_task.update_stats(
            'TEST NETWORK CONNECT.', sys_failed=0)

        success_sys = SystemConnectionResult(
            name='1.2.3.4', credential=self.cred,
            status=SystemConnectionResult.SUCCESS)
        success_sys.save()
        failed_sys = SystemConnectionResult(
            name='1.1.1.2', status=SystemConnectionResult.FAILED)
        failed_sys.save()
        conn_result = self.connect_scan_task.connection_result
        conn_result.systems.add(success_sys)
        conn_result.systems.add(failed_sys)
        conn_result.save()

        self.connect_scan_task.update_stats(
            'TEST_VC.', sys_count=2, sys_failed=1, sys_scanned=1)
        self.connect_scan_task.complete()

        self.scan_task.update_stats(
            'TEST NETWORK INSPECT.', sys_failed=0)

        self.fact_endpoint = 'http://testserver' + reverse('facts-list')

        self.scan_job.save()

        scan_data_log.disable_log_for_test()
    def setUp(self):
        """Create test case setup."""
        self.cred = Credential(name='cred1',
                               username='******',
                               password='******',
                               ssh_keyfile=None,
                               become_method=None,
                               become_user=None,
                               become_password=None)
        self.cred.save()

        hc_serializer = CredentialSerializer(self.cred)
        self.cred_data = hc_serializer.data

        # setup source for scan
        self.source = Source(name='source1', port=22, hosts='["1.2.3.4"]')
        self.source.save()
        self.source.credentials.add(self.cred)

        self.host_list = [('1.2.3.4', self.cred_data)]

        self.scan_job, self.scan_task = create_scan_job(
            self.source, ScanTask.SCAN_TYPE_INSPECT)

        self.connect_scan_task = self.scan_task.prerequisites.first()
        self.connect_scan_task.update_stats('TEST NETWORK CONNECT.',
                                            sys_failed=0)

        conn_result = self.connect_scan_task.connection_result
        success_sys = SystemConnectionResult(
            name='1.2.3.4',
            credential=self.cred,
            status=SystemConnectionResult.SUCCESS,
            task_connection_result=conn_result)
        success_sys.save()
        failed_sys = SystemConnectionResult(
            name='1.1.1.2',
            status=SystemConnectionResult.FAILED,
            task_connection_result=conn_result)
        failed_sys.save()
        conn_result.save()

        self.connect_scan_task.update_stats('TEST_VC.',
                                            sys_count=2,
                                            sys_failed=1,
                                            sys_scanned=1)
        self.connect_scan_task.complete()

        self.scan_task.update_stats('TEST NETWORK INSPECT.', sys_failed=0)

        self.fact_endpoint = 'http://testserver' + reverse('reports-list')

        self.scan_job.save()
        self.stop_states = [
            ScanJob.JOB_TERMINATE_CANCEL, ScanJob.JOB_TERMINATE_PAUSE
        ]
        self.interrupt = Mock(value=ScanJob.JOB_RUN)
Exemple #16
0
    def test_details(self):
        """Get ScanJob result details by primary key."""
        # pylint: disable=no-member
        scan_job, scan_task = create_scan_job(
            self.source, ScanTask.SCAN_TYPE_INSPECT)

        # Create a connection system result
        sys_result = SystemConnectionResult(name='Foo',
                                            credential=self.cred,
                                            status=SystemConnectionResult
                                            .SUCCESS)
        sys_result.save()
        conn_result = scan_task.prerequisites.first().connection_result
        conn_result.systems.add(sys_result)
        conn_result.save()

        # Create an inspection system result
        sys_result = SystemInspectionResult(name='Foo',
                                            status=SystemConnectionResult
                                            .SUCCESS)
        sys_result.save()

        fact = RawFact(name='fact_key', value='"fact_value"')
        fact.save()
        sys_result.facts.add(fact)
        sys_result.save()

        inspect_result = scan_task.inspection_result
        inspect_result.systems.add(sys_result)
        inspect_result.save()
        scan_job.save()

        url = reverse('scanjob-detail', args=(scan_job.id,)) + 'results/'
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        json_response = response.json()
        self.assertIn('connection_results', json_response)
        self.assertIn('inspection_results', json_response)

        self.assertEqual(
            json_response, {
                'connection_results': {'task_results': [
                    {'source':
                     {'id': 1, 'name': 'source1', 'source_type': 'network'},
                     'systems':
                     [{'name': 'Foo', 'credential':
                       {'id': 1, 'name': 'cred1'},
                       'status': 'success'}]}]},
                'inspection_results': {'task_results': [
                    {'source':
                     {'id': 1, 'name': 'source1', 'source_type': 'network'},
                     'systems':
                     [{'name': 'Foo', 'status': 'success',
                       'facts': [
                           {'name': 'fact_key', 'value': 'fact_value'}]}]}]}})
Exemple #17
0
 def setUp(self):
     """Create test case setup."""
     self.server_id = ServerInformation.create_or_retreive_server_id()
     self.source = Source(name='source1',
                          hosts=json.dumps(['1.2.3.4']),
                          source_type='network',
                          port=22)
     self.source.save()
     scan_job, _ = create_scan_job(self.source)
     self.fp_task = scan_job.tasks.last()  # pylint: disable=no-member
     self.fp_task_runner = FingerprintTaskRunner(scan_job, self.fp_task)
Exemple #18
0
    def test_merge_jobs_not_complete(self):
        """Test merge jobs not complete."""
        # pylint: disable=no-member
        scan_job1, _ = create_scan_job(
            self.source, ScanTask.SCAN_TYPE_INSPECT,
            scan_name='test1')

        scan_job2, _ = create_scan_job(
            self.source, ScanTask.SCAN_TYPE_INSPECT,
            scan_name='test2')

        url = reverse('scanjob-merge')
        data = {'jobs': [scan_job1.id, scan_job2.id]}
        response = self.client.put(url, json.dumps(data),
                                   content_type='application/json',
                                   format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        json_response = response.json()
        error_message = messages.SJ_MERGE_JOB_NOT_COMPLETE % (
            ', '.join([str(i) for i in [scan_job1.id, scan_job2.id]]))
        self.assertEqual(
            json_response, {'jobs': [error_message]})
    def setUp(self):
        """Create test case setup."""
        self.cred = Credential(name='cred1',
                               username='******',
                               password='******',
                               ssh_keyfile='keyfile',
                               become_method='sudo',
                               become_user='******',
                               become_password='******')
        self.cred.save()

        # Source with excluded hosts
        self.source = Source(name='source1',
                             hosts='["1.2.3.4", "1.2.3.5"]',
                             exclude_hosts='["1.2.3.5", "1.2.3.6"]',
                             source_type='network',
                             port=22)
        self.source.save()
        self.source.credentials.add(self.cred)
        self.source.save()

        self.scan_job, self.scan_task = create_scan_job(
            self.source, ScanTask.SCAN_TYPE_CONNECT)

        self.scan_task.update_stats('TEST NETWORK CONNECT.', sys_failed=0)

        # Source without excluded hosts
        self.source2 = Source(name='source2',
                              hosts='["1.2.3.4"]',
                              source_type='network',
                              port=22)
        self.source2.save()
        self.source2.credentials.add(self.cred)
        self.source2.save()

        self.scan_job2, self.scan_task2 = create_scan_job(
            self.source, ScanTask.SCAN_TYPE_CONNECT, 'source2')

        self.scan_task2.update_stats('TEST NETWORK CONNECT.', sys_failed=0)
Exemple #20
0
    def test_expand_scanjob(self):
        """Test view expand_scanjob."""
        scan_job, scan_task = create_scan_job(
            self.source, scan_type=ScanTask.SCAN_TYPE_INSPECT)
        scan_task.update_stats('TEST_VC.', sys_count=2,
                               sys_failed=1, sys_scanned=1)

        scan_job = ScanJob.objects.filter(pk=scan_job.id).first()
        serializer = ScanJobSerializer(scan_job)
        json_scan = serializer.data
        json_scan = expand_scanjob(json_scan)

        self.assertEqual(json_scan.get('systems_count'), 2)
        self.assertEqual(json_scan.get('systems_failed'), 1)
        self.assertEqual(json_scan.get('systems_scanned'), 1)
Exemple #21
0
    def test_expand_sys_conn_result(self):
        """Test view expand_sys_conn_result."""
        # pylint: disable=no-member
        _, scan_task = create_scan_job(
            self.source, ScanTask.SCAN_TYPE_CONNECT)

        sys_result = SystemConnectionResult(name='Foo',
                                            credential=self.cred,
                                            status=SystemConnectionResult
                                            .SUCCESS)
        sys_result.save()
        conn_result = scan_task.connection_result
        conn_result.systems.add(sys_result)
        conn_result.save()

        result = expand_sys_conn_result(conn_result)
        self.assertEqual(result[0]['credential']['name'], 'cred1')
Exemple #22
0
    def test_delete_scan_cascade(self, start_scan):
        """Delete a scan and its related data."""
        # pylint: disable=no-member
        scan_job, scan_task = create_scan_job(
            self.source, ScanTask.SCAN_TYPE_INSPECT)

        scan = scan_job.scan
        scan_id = scan.id

        self.create_job_expect_201(scan_id)

        # Create a connection system result
        sys_result = SystemConnectionResult(name='Foo',
                                            credential=self.cred,
                                            status=SystemConnectionResult
                                            .SUCCESS)
        sys_result.save()
        conn_result = scan_task.prerequisites.first().connection_result
        conn_result.systems.add(sys_result)
        conn_result.save()

        # Create an inspection system result
        sys_result = SystemInspectionResult(name='Foo',
                                            status=SystemConnectionResult
                                            .SUCCESS)
        sys_result.save()

        fact = RawFact(name='fact_key', value='"fact_value"')
        fact.save()
        sys_result.facts.add(fact)
        sys_result.save()

        inspect_result = scan_task.inspection_result
        inspect_result.systems.add(sys_result)
        inspect_result.save()
        scan_job.save()

        job_count = len(scan.jobs.all())
        self.assertNotEqual(job_count, 0)
        url = reverse('scan-detail', args=(scan_id,))
        response = self.client.delete(url, format='json')
        self.assertEqual(response.status_code,
                         status.HTTP_204_NO_CONTENT)
        job_count = len(scan.jobs.all())
        self.assertEqual(job_count, 0)
Exemple #23
0
    def test_start_task(self):
        """Test start pending task."""
        scan_job, _ = create_scan_job(
            self.source, scan_type=ScanTask.SCAN_TYPE_CONNECT)

        # Job in created state
        tasks = scan_job.tasks.all()

        # Queue job to run
        scan_job.queue()
        self.assertEqual(scan_job.status, ScanTask.PENDING)

        # Queue should have created scan tasks
        tasks = scan_job.tasks.all()
        self.assertEqual(len(tasks), 1)

        # Start job
        scan_job.start()
    def test_404_if_not_fingerprint_job(self):
        """Test report job status only returns merge jobs."""
        source = Source(name='source1',
                        hosts=json.dumps(['1.2.3.4']),
                        source_type='network',
                        port=22)
        source.save()
        scan_job, _ = create_scan_job(source,
                                      scan_type=ScanTask.SCAN_TYPE_INSPECT)

        url = '/api/v1/reports/merge/jobs/{}/'.format(scan_job.id)
        get_response = self.client.get(url)
        self.assertEqual(get_response.status_code, status.HTTP_404_NOT_FOUND)

        scan_job.scan_type = ScanTask.SCAN_TYPE_FINGERPRINT
        scan_job.save()
        url = '/api/v1/reports/merge/jobs/{}/'.format(scan_job.id)
        get_response = self.client.get(url)
        self.assertEqual(get_response.status_code, status.HTTP_200_OK)
Exemple #25
0
    def setUp(self):
        """Create test case setup."""
        self.cred = Credential(name='cred1',
                               username='******',
                               password='******',
                               become_password=None,
                               ssh_keyfile=None)
        self.cred.save()

        options = SourceOptions(disable_ssl=True)
        options.save()

        self.source = Source(name='source1', port=22, hosts='["1.2.3.4"]')
        self.source.options = options
        self.source.save()
        self.source.credentials.add(self.cred)

        self.scan_job, self.scan_task = create_scan_job(
            self.source, scan_type=ScanTask.SCAN_TYPE_INSPECT)
Exemple #26
0
    def test_expand_conn_results(self):
        """Test view expand_conn_results."""
        # pylint: disable=no-member
        scan_job, scan_task = create_scan_job(
            self.source, ScanTask.SCAN_TYPE_CONNECT)

        sys_result = SystemConnectionResult(name='Foo',
                                            credential=self.cred,
                                            status=SystemConnectionResult
                                            .SUCCESS)
        sys_result.save()
        conn_result = scan_task.connection_result
        conn_result.systems.add(sys_result)
        conn_result.save()

        conn_results_json = {'task_results': [{}]}
        expand_conn_results(scan_job.connection_results, conn_results_json)
        self.assertEqual(
            conn_results_json['task_results'][0]['systems'][0]['name'], 'Foo')
Exemple #27
0
    def test_get_extra_vars_missing_disable_product(self):
        """Tests the get_extra_vars with extended search None."""
        disabled = DisabledOptionalProductsOptions()
        disabled.save()
        scan_options = ScanOptions(
            disabled_optional_products=disabled)
        scan_options.save()
        scan_job, _ = create_scan_job(self.source,
                                      ScanTask.SCAN_TYPE_INSPECT,
                                      scan_options=scan_options)
        extra_vars = scan_job.options.get_extra_vars()

        expected_vars = {'jboss_eap': True,
                         'jboss_fuse': True,
                         'jboss_brms': True,
                         'jboss_eap_ext': False,
                         'jboss_fuse_ext': False,
                         'jboss_brms_ext': False}
        self.assertEqual(extra_vars, expected_vars)
Exemple #28
0
    def test_get_extra_vars_missing_extended_search(self):
        """Tests the get_extra_vars with disabled products None."""
        extended = ExtendedProductSearchOptions()
        extended.save()
        scan_options = ScanOptions(
            enabled_extended_product_search=extended)
        scan_options.save()
        scan_job, _ = create_scan_job(self.source,
                                      ScanTask.SCAN_TYPE_INSPECT,
                                      scan_options=scan_options)
        extra_vars = scan_job.options.get_extra_vars()

        expected_vars = {'jboss_eap': True,
                         'jboss_fuse': True,
                         'jboss_brms': True,
                         'jboss_eap_ext': False,
                         'jboss_fuse_ext': False,
                         'jboss_brms_ext': False}
        self.assertEqual(extra_vars, expected_vars)
Exemple #29
0
    def setUp(self):
        """Create test case setup."""
        self.cred = Credential(name='cred1',
                               username='******',
                               password='******',
                               become_password=None,
                               ssh_keyfile=None)
        self.cred.save()

        self.source = Source(name='source1', port=22, hosts='["1.2.3.4"]')

        self.source.save()
        self.source.credentials.add(self.cred)

        self.scan_job, self.scan_task = create_scan_job(
            self.source, ScanTask.SCAN_TYPE_CONNECT)

        # Create runner
        self.runner = ConnectTaskRunner(scan_job=self.scan_job,
                                        scan_task=self.scan_task)
Exemple #30
0
    def test_hosts_facts(self, mock_pool):
        """Test the hosts_facts method."""
        scan_options = ScanOptions(max_concurrency=10)
        scan_options.save()
        scan_job, scan_task = create_scan_job(self.source,
                                              ScanTask.SCAN_TYPE_INSPECT,
                                              scan_name='test_62',
                                              scan_options=scan_options)
        scan_task.update_stats('TEST_SAT.', sys_scanned=0)
        api = SatelliteSixV2(scan_job, scan_task)
        job_conn_result = JobConnectionResult()
        job_conn_result.save()
        connection_results = TaskConnectionResult(
            job_connection_result=job_conn_result)
        connection_results.save()
        api.connect_scan_task.connection_result = connection_results
        api.connect_scan_task.connection_result.save()

        sys_result = SystemConnectionResult(
            name='sys1_1',
            status=SystemInspectionResult.SUCCESS,
            task_connection_result=api.connect_scan_task.connection_result)
        sys_result.save()
        api.connect_scan_task.save()
        hosts_url = 'https://{sat_host}:{port}/api/v2/hosts'
        with requests_mock.Mocker() as mocker:
            url = construct_url(url=hosts_url, sat_host='1.2.3.4')
            jsonresult = {
                'total': 1,
                'subtotal': 1,
                'page': 1,
                'per_page': 100,
                'results': [{
                    'id': 10,
                    'name': 'sys10'
                }]
            }  # noqa
            mocker.get(url, status_code=200, json=jsonresult)
            api.hosts_facts(Value('i', ScanJob.JOB_RUN))
            inspect_result = scan_task.inspection_result
            self.assertEqual(len(inspect_result.systems.all()), 1)