Exemplo n.º 1
0
 def test_reimport_by_product_name_exists_engagement_name_not_exists_auto_create(
         self, mock):
     with assertImportModelsCreated(self,
                                    tests=1,
                                    engagements=1,
                                    products=0,
                                    product_types=0,
                                    endpoints=0):
         import0 = self.reimport_scan_with_params(
             None,
             NPM_AUDIT_NO_VULN_FILENAME,
             scan_type=NPM_AUDIT_SCAN_TYPE,
             product_name=PRODUCT_NAME_DEFAULT,
             engagement=None,
             engagement_name=ENGAGEMENT_NAME_NEW,
             auto_create_context=True)
         test_id = import0['test']
         self.assertEqual(get_object_or_none(Test, id=test_id).title, None)
         self.assertEqual(
             get_object_or_none(Engagement,
                                id=import0['engagement_id']).name,
             ENGAGEMENT_NAME_NEW)
         self.assertEqual(import0['product_id'], self.engagement.product.id)
         self.assertEqual(import0['product_type_id'],
                          self.engagement.product.prod_type.id)
     # the new engagement should inherit the jira settings from the product
     # the jira settings are retrieved before an engagement is auto created
     mock.assert_called_with(self.product)
Exemplo n.º 2
0
    def test_reimport_by_product_type_not_exists_product_name_not_exists_engagement_name_auto_create(
            self, mock):
        with assertImportModelsCreated(self,
                                       tests=1,
                                       engagements=1,
                                       products=1,
                                       product_types=1,
                                       endpoints=0):
            import0 = self.reimport_scan_with_params(
                None,
                NPM_AUDIT_NO_VULN_FILENAME,
                scan_type=NPM_AUDIT_SCAN_TYPE,
                product_name=PRODUCT_NAME_NEW,
                engagement=None,
                engagement_name=ENGAGEMENT_NAME_NEW,
                product_type_name=PRODUCT_TYPE_NAME_NEW,
                auto_create_context=True)
            test_id = import0['test']
            self.assertEqual(get_object_or_none(Test, id=test_id).title, None)
            self.assertEqual(
                get_object_or_none(Engagement,
                                   id=import0['engagement_id']).name,
                ENGAGEMENT_NAME_NEW)
            self.assertEqual(
                get_object_or_none(Product, id=import0['product_id']).name,
                PRODUCT_NAME_NEW)
            self.assertEqual(
                get_object_or_none(Product,
                                   id=import0['product_id']).prod_type.name,
                PRODUCT_TYPE_NAME_NEW)

        mock.assert_not_called()
Exemplo n.º 3
0
 def test_reimport_by_product_name_exists_engagement_name_exists_scan_type_not_exsists_test_title_not_exists_auto_create(
         self, mock):
     with assertImportModelsCreated(self,
                                    tests=1,
                                    engagements=0,
                                    products=0,
                                    product_types=0,
                                    endpoints=1):
         import0 = self.reimport_scan_with_params(
             None,
             ACUNETIX_AUDIT_ONE_VULN_FILENAME,
             scan_type='Acunetix Scan',
             product_name=PRODUCT_NAME_DEFAULT,
             engagement=None,
             engagement_name=ENGAGEMENT_NAME_DEFAULT,
             test_title='bogus title',
             auto_create_context=True)
         test_id = import0['test']
         self.assertEqual(
             get_object_or_none(Test, id=test_id).scan_type,
             'Acunetix Scan')
         self.assertEqual(
             get_object_or_none(Test, id=test_id).title, 'bogus title')
         self.assertEqual(import0['engagement_id'], self.engagement.id)
     # the new test should inherit the jira settings from the engagement
     # the jira settings are retrieved before an test is auto created
     mock.assert_called_with(self.engagement)
Exemplo n.º 4
0
def get_target_test_if_exists(test_id=None,
                              test_title=None,
                              scan_type=None,
                              engagement=None):
    """
    Retrieves the target test to reimport. This can be as simple as looking up the test via the `test_id` parameter.
    If there is no `test_id` provided, we lookup the latest test inside the provided engagement that satisfies
    the provided scan_type and test_title.
    """
    if test_id:
        test = get_object_or_none(Test, pk=test_id)
        logger.debug('Using existing Test by id: %s', test_id)
        return test

    if not engagement:
        return None

    if test_title:
        return get_last_object_or_none(Test,
                                       engagement=engagement,
                                       title=test_title,
                                       scan_type=scan_type)

    return get_last_object_or_none(Test,
                                   engagement=engagement,
                                   scan_type=scan_type)
Exemplo n.º 5
0
 def test_reimport_by_product_name_exists_engagement_name_exists_scan_type_not_exsists_test_title_exists_auto_create(self, mock):
     with assertImportModelsCreated(self, tests=1, engagements=0, products=0, product_types=0, endpoints=1):
         import0 = self.reimport_scan_with_params(None, ACUNETIX_AUDIT_ONE_VULN_FILENAME, scan_type='Acunetix Scan', product_name=PRODUCT_NAME_DEFAULT,
             engagement=None, engagement_name=ENGAGEMENT_NAME_DEFAULT, test_title=TEST_TITLE_DEFAULT, auto_create_context=True)
         test_id = import0['test']
         self.assertEqual(get_object_or_none(Test, id=test_id).title, TEST_TITLE_DEFAULT)
         self.assertEqual(import0['engagement_id'], self.engagement.id)
     mock.assert_called_with(self.engagement)
Exemplo n.º 6
0
 def test_reimport_by_test_id(self):
     with assertImportModelsCreated(self, tests=0, engagements=0, products=0, product_types=0, endpoints=0):
         import0 = self.reimport_scan_with_params(self.test.id, NPM_AUDIT_NO_VULN_FILENAME, scan_type=NPM_AUDIT_SCAN_TYPE)
         test_id = import0['test']
         self.assertEqual(get_object_or_none(Test, id=test_id).title, TEST_TITLE_DEFAULT)
         self.assertEqual(test_id, self.test.id)
         self.assertEqual(import0['engagement_id'], self.test.engagement.id)
         self.assertEqual(import0['product_id'], self.test.engagement.product.id)
Exemplo n.º 7
0
 def test_import_by_engagement_id(self, mock):
     with assertImportModelsCreated(self, tests=1, engagements=0, products=0, product_types=0, endpoints=0):
         import0 = self.import_scan_with_params(NPM_AUDIT_NO_VULN_FILENAME, scan_type=NPM_AUDIT_SCAN_TYPE, engagement=self.engagement.id, test_title=TEST_TITLE_DEFAULT)
         test_id = import0['test']
         self.assertEqual(get_object_or_none(Test, id=test_id).title, TEST_TITLE_DEFAULT)
         self.assertEqual(import0['engagement_id'], self.engagement.id)
         self.assertEqual(import0['product_id'], self.engagement.product.id)
     mock.assert_called_with(self.engagement)
Exemplo n.º 8
0
def get_target_product_if_exists(product_name=None, product_type_name=None):
    if product_name:
        product = get_object_or_none(Product, name=product_name)
        if product:
            # product type name must match if provided
            if product_type_name:
                if product.prod_type.name == product_type_name:
                    return product
            else:
                return product

    return None
Exemplo n.º 9
0
def get_target_engagement_if_exists(engagement_id=None, engagement_name=None, product=None):
    if engagement_id:
        engagement = get_object_or_none(Engagement, pk=engagement_id)
        logger.debug('Using existing engagement by id: %s', engagement_id)
        return engagement

    if not product:
        # if there's no product, then for sure there's no engagement either
        return None

    # engagement name is not unique unfortunately
    engagement = get_last_object_or_none(Engagement, product=product, name=engagement_name)
    return engagement
Exemplo n.º 10
0
def get_target_product_by_id_if_exists(product_id=None):
    product = None
    if product_id:
        product = get_object_or_none(Product, pk=product_id)
        logger.debug('Using existing product by id: %s', product_id)
    return product
Exemplo n.º 11
0
def get_target_product_type_if_exists(product_type_name=None):
    if product_type_name:
        return get_object_or_none(Product_Type, name=product_type_name)
    else:
        return None