示例#1
0
    def test_loop_relations_for_two(self):

        set_duplicate(self.finding_a, self.finding_b)
        self.finding_b.duplicate = True
        self.finding_b.duplicate_finding = self.finding_a

        super(Finding, self.finding_a).save()
        super(Finding, self.finding_b).save()

        fix_loop_duplicates()

        candidates = Finding.objects.filter(duplicate_finding__isnull=False, original_finding__isnull=False).count()
        self.assertEqual(candidates, 0)

        # Get latest status
        self.finding_a = Finding.objects.get(id=self.finding_a.id)
        self.finding_b = Finding.objects.get(id=self.finding_b.id)

        if self.finding_a.duplicate_finding:
            self.assertTrue(self.finding_a.duplicate)
            self.assertEqual(self.finding_a.original_finding.count(), 0)
        else:
            self.assertFalse(self.finding_a.duplicate)
            self.assertEqual(self.finding_a.original_finding.count(), 1)

        if self.finding_b.duplicate_finding:
            self.assertTrue(self.finding_b.duplicate)
            self.assertEqual(self.finding_b.original_finding.count(), 0)
        else:
            self.assertFalse(self.finding_b.duplicate)
            self.assertEqual(self.finding_b.original_finding.count(), 1)
示例#2
0
    def test_out_of_scope_reopen(self):
        self.finding_c.active = False
        self.finding_c.verified = False
        set_duplicate(self.finding_d, self.finding_c)
        self.finding_d.duplicate = True
        self.finding_d.duplicate_finding = self.finding_c

        super(Finding, self.finding_c).save()
        super(Finding, self.finding_d).save()

        fix_loop_duplicates()

        candidates = Finding.objects.filter(
            duplicate_finding__isnull=False,
            original_finding__isnull=False).count()
        self.assertEqual(candidates, 0)

        # Get latest status
        self.finding_c = Finding.objects.get(id=self.finding_c.id)
        self.finding_d = Finding.objects.get(id=self.finding_d.id)

        self.assertTrue(self.finding_c.out_of_scope)
        self.assertFalse(self.finding_c.is_Mitigated)
        self.assertFalse(self.finding_c.active)
        self.assertFalse(self.finding_c.verified)

        self.assertFalse(self.finding_d.out_of_scope)
        self.assertFalse(self.finding_d.is_Mitigated)
        self.assertFalse(self.finding_d.active)
        self.assertFalse(self.finding_d.verified)
示例#3
0
    def test_false_positive_reopen(self):
        self.finding_a.active = False
        self.finding_a.verified = False  # in the gui, a FP can not be true
        set_duplicate(self.finding_b, self.finding_a)
        self.finding_b.duplicate = True
        self.finding_b.duplicate_finding = self.finding_a

        super(Finding, self.finding_a).save()
        super(Finding, self.finding_b).save()

        fix_loop_duplicates()

        candidates = Finding.objects.filter(
            duplicate_finding__isnull=False,
            original_finding__isnull=False).count()
        self.assertEqual(candidates, 0)

        # Get latest status
        self.finding_a = Finding.objects.get(id=self.finding_a.id)
        self.finding_b = Finding.objects.get(id=self.finding_b.id)

        self.assertTrue(self.finding_a.false_p)
        self.assertTrue(self.finding_a.is_Mitigated)
        self.assertFalse(self.finding_a.active)
        self.assertFalse(self.finding_a.verified)

        self.assertFalse(self.finding_b.false_p)
        self.assertFalse(self.finding_b.is_Mitigated)
        self.assertFalse(self.finding_b.active)
        self.assertFalse(self.finding_b.verified)
示例#4
0
 def test_loop_relations_for_one(self):
     self.finding_b.duplicate = True
     self.finding_b.duplicate_finding = self.finding_b
     super(Finding, self.finding_b).save()
     candidates = Finding.objects.filter(duplicate_finding__isnull=False, original_finding__isnull=False).count()
     self.assertEqual(candidates, 1)
     fix_loop_duplicates()
     candidates = Finding.objects.filter(duplicate_finding__isnull=False, original_finding__isnull=False).count()
     self.assertEqual(candidates, 0)
示例#5
0
    def test_loop_relations_for_four(self):
        self.finding_d = Finding.objects.get(id=4)
        self.finding_d.pk = None
        self.finding_d.duplicate = False
        self.finding_d.duplicate_finding = None
        self.finding_d.save()

        set_duplicate(self.finding_a, self.finding_b)
        self.finding_b.duplicate = True
        self.finding_b.duplicate_finding = self.finding_c
        self.finding_c.duplicate = True
        self.finding_c.duplicate_finding = self.finding_d
        self.finding_d.duplicate = True
        self.finding_d.duplicate_finding = self.finding_a

        super(Finding, self.finding_a).save()
        super(Finding, self.finding_b).save()
        super(Finding, self.finding_c).save()
        super(Finding, self.finding_d).save()

        fix_loop_duplicates()

        # Get latest status
        self.finding_a = Finding.objects.get(id=self.finding_a.id)
        self.finding_b = Finding.objects.get(id=self.finding_b.id)
        self.finding_c = Finding.objects.get(id=self.finding_c.id)
        self.finding_d = Finding.objects.get(id=self.finding_d.id)

        if self.finding_a.duplicate_finding:
            self.assertTrue(self.finding_a.duplicate)
            self.assertEqual(self.finding_a.original_finding.count(), 0)
        else:
            self.assertFalse(self.finding_a.duplicate)
            self.assertEqual(self.finding_a.original_finding.count(), 3)

        if self.finding_b.duplicate_finding:
            self.assertTrue(self.finding_b.duplicate)
            self.assertEqual(self.finding_b.original_finding.count(), 0)
        else:
            self.assertFalse(self.finding_b.duplicate)
            self.assertEqual(self.finding_b.original_finding.count(), 3)

        if self.finding_c.duplicate_finding:
            self.assertTrue(self.finding_c.duplicate)
            self.assertEqual(self.finding_c.original_finding.count(), 0)
        else:
            self.assertFalse(self.finding_c.duplicate)
            self.assertEqual(self.finding_c.original_finding.count(), 3)

        if self.finding_d.duplicate_finding:
            self.assertTrue(self.finding_d.duplicate)
            self.assertEqual(self.finding_d.original_finding.count(), 0)
        else:
            self.assertFalse(self.finding_d.duplicate)
            self.assertEqual(self.finding_d.original_finding.count(), 3)
示例#6
0
    def test_list_relations_for_three_reverse(self):
        set_duplicate(self.finding_c, self.finding_b)
        self.finding_b.duplicate = True
        self.finding_b.duplicate_finding = self.finding_a

        super(Finding, self.finding_a).save()
        super(Finding, self.finding_b).save()
        super(Finding, self.finding_c).save()

        fix_loop_duplicates()

        self.finding_a = Finding.objects.get(id=self.finding_a.id)
        self.finding_b = Finding.objects.get(id=self.finding_b.id)
        self.finding_c = Finding.objects.get(id=self.finding_c.id)

        self.assertTrue(self.finding_b.duplicate)
        self.assertTrue(self.finding_c.duplicate)
        self.assertFalse(self.finding_a.duplicate)
        self.assertEqual(self.finding_b.duplicate_finding.id, self.finding_a.id)
        self.assertEqual(self.finding_c.duplicate_finding.id, self.finding_a.id)
        self.assertEqual(self.finding_a.duplicate_finding, None)
        self.assertEqual(self.finding_c.duplicate_finding_set().count(), 2)
        self.assertEqual(self.finding_b.duplicate_finding_set().count(), 2)
示例#7
0
def fix_loop_task(*args, **kwargs):
    logger.info("Executing Loop Duplicate Fix Job")
    fix_loop_duplicates()
示例#8
0
 def handle(self, *args, **options):
     fix_loop_duplicates()