forked from aboutcode-org/dejacode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: ziadhany <ziadhany2016@gmail.com>
- Loading branch information
Showing
5 changed files
with
130 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# | ||
# Copyright (c) nexB Inc. and others. All rights reserved. | ||
# DejaCode is a trademark of nexB Inc. | ||
# SPDX-License-Identifier: AGPL-3.0-only | ||
# See https://github.com/nexB/dejacode for support or download. | ||
# See https://aboutcode.org for more information about AboutCode FOSS projects. | ||
# | ||
|
||
|
||
from unittest import mock | ||
|
||
from django.contrib.auth import get_user_model | ||
from django.test import TestCase | ||
|
||
from component_catalog.models import Package | ||
from dejacode_toolkit import vex | ||
from dje.models import Dataspace | ||
from dje.tests import create_superuser | ||
from dje.tests import create_user | ||
from product_portfolio.models import Product | ||
from product_portfolio.models import ProductPackage | ||
from product_portfolio.models import ProductPackageVEX | ||
|
||
User = get_user_model() | ||
|
||
|
||
class VEXTestCase(TestCase): | ||
def setUp(self): | ||
self.nexb_dataspace = Dataspace.objects.create(name="nexB") | ||
self.nexb_user = User.objects.create_superuser( | ||
"nexb_user", "test@test.com", "t3st", self.nexb_dataspace | ||
) | ||
self.basic_user = create_user("basic_user", self.nexb_dataspace) | ||
self.product1 = Product.objects.create( | ||
name="Product1 With Space", version="1.0", dataspace=self.nexb_dataspace | ||
) | ||
self.package1 = Package.objects.create(filename="package1", dataspace=self.nexb_dataspace) | ||
|
||
self.productpacakge1 = ProductPackage.objects.create( | ||
product=self.product1, package=self.package1, dataspace=self.nexb_dataspace | ||
) | ||
|
||
def test_create_auto_vex1(self): | ||
vulnerabilities = [ | ||
{ | ||
"affected_by_vulnerabilities": [ | ||
{ | ||
"url": "http://public.vulnerablecode.io/api/vulnerabilities/121332", | ||
"vulnerability_id": "VCID-111c-u9bh-aaac", | ||
} | ||
] | ||
}, | ||
{ | ||
"affected_by_vulnerabilities": [ | ||
{ | ||
"url": "https://public.vulnerablecode.io/api/vulnerabilities/121331", | ||
"vulnerability_id": "VCID-uxf9-7c97-aaaj", | ||
} | ||
] | ||
}, | ||
] | ||
assert ProductPackageVEX.objects.count() == 0 | ||
vex.create_auto_vex(self.package1, vulnerabilities) | ||
assert ProductPackageVEX.objects.count() == 2 | ||
|
||
# run create_auto_vex agian and make sure that the databse ignore errors | ||
vex.create_auto_vex(self.package1, vulnerabilities) | ||
assert ProductPackageVEX.objects.count() == 2 | ||
|
||
def test_create_auto_vex2(self): | ||
# duplicated vulnerability | ||
vulnerabilities = [ | ||
{ | ||
"affected_by_vulnerabilities": [ | ||
{ | ||
"url": "http://public.vulnerablecode.io/api/vulnerabilities/121332", | ||
"vulnerability_id": "VCID-111c-u9bh-aaac", | ||
} | ||
] | ||
}, | ||
{ | ||
"affected_by_vulnerabilities": [ | ||
{ | ||
"url": "http://public.vulnerablecode.io/api/vulnerabilities/121332", | ||
"vulnerability_id": "VCID-111c-u9bh-aaac", | ||
} | ||
] | ||
}, | ||
] | ||
assert ProductPackageVEX.objects.count() == 0 | ||
vex.create_auto_vex(self.package1, vulnerabilities) | ||
assert ProductPackageVEX.objects.count() == 1 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters