|
6 | 6 | # See https://github.com/aboutcode-org/vulnerablecode for support or download. |
7 | 7 | # See https://aboutcode.org for more information about nexB OSS projects. |
8 | 8 | # |
| 9 | + |
| 10 | + |
| 11 | +from unittest import TestCase |
| 12 | + |
| 13 | +from vulnerabilities.importer import ReferenceV2 |
| 14 | +from vulnerabilities.models import AdvisoryReference |
| 15 | +from vulnerabilities.pipes.openssl import get_commit_patch |
| 16 | +from vulnerabilities.pipes.openssl import get_reference |
| 17 | +from vulnerabilities.pipes.openssl import parse_affected_fixed |
| 18 | +from vulnerabilities.tests.pipelines import TestLogger |
| 19 | + |
| 20 | + |
| 21 | +class TestPipeOpenSSL(TestCase): |
| 22 | + def setUp(self): |
| 23 | + self.logger = TestLogger() |
| 24 | + |
| 25 | + def test_vulnerability_pipes_openssl_get_reference(self): |
| 26 | + refrence_name = "OpenSSL Advisory" |
| 27 | + tag = "vendor-advisory" |
| 28 | + refrence_url = "https://www.openssl.org/news/secadv/20221213.txt" |
| 29 | + result = get_reference( |
| 30 | + reference_name=refrence_name, |
| 31 | + tag=tag, |
| 32 | + reference_url=refrence_url, |
| 33 | + ) |
| 34 | + expected = ReferenceV2( |
| 35 | + reference_id=refrence_name, |
| 36 | + reference_type=AdvisoryReference.ADVISORY, |
| 37 | + url=refrence_url, |
| 38 | + ) |
| 39 | + |
| 40 | + self.assertEqual(result, expected) |
| 41 | + |
| 42 | + def test_vulnerability_pipes_openssl_get_commit_patch(self): |
| 43 | + url = "https://git.openssl.org/gitweb/?p=openssl.git;a=commitdiff;h=cca1cd9a3447dd067503e4a85ebd1679ee78a48e" |
| 44 | + result_patch = get_commit_patch(url=url, logger=self.logger.write) |
| 45 | + expected_vcs = "https://github.com/openssl/openssl/" |
| 46 | + expected_hash = "cca1cd9a3447dd067503e4a85ebd1679ee78a48e" |
| 47 | + |
| 48 | + self.assertEqual(result_patch.vcs_url, expected_vcs) |
| 49 | + self.assertEqual(result_patch.commit_hash, expected_hash) |
| 50 | + |
| 51 | + def test_vulnerability_pipes_openssl_get_commit_patch_unsupported(self): |
| 52 | + url = "https://someunsupported.url/commit/93l232slfsll3l23l2" |
| 53 | + get_commit_patch(url=url, logger=self.logger.write) |
| 54 | + |
| 55 | + self.assertIn("Unsupported commit url", self.logger.getvalue()) |
| 56 | + |
| 57 | + def test_vulnerability_pipes_openssl_parse_affected_fixed_lessthan(self): |
| 58 | + affected = { |
| 59 | + "lessThan": "0.9.7a", |
| 60 | + "status": "affected", |
| 61 | + "version": "0.9.7", |
| 62 | + "versionType": "custom", |
| 63 | + } |
| 64 | + |
| 65 | + result_affected, result_fixed = parse_affected_fixed(affected) |
| 66 | + result_affected = [str(const) for const in result_affected] |
| 67 | + expected_affected = [">=0.9.7", "<0.9.7a"] |
| 68 | + expected_fixed = "0.9.7a" |
| 69 | + |
| 70 | + self.assertCountEqual(result_affected, expected_affected) |
| 71 | + self.assertEqual(result_fixed, expected_fixed) |
| 72 | + |
| 73 | + def test_vulnerability_pipes_openssl_parse_affected_fixed_lessthanorequal(self): |
| 74 | + affected = { |
| 75 | + "lessThanOrEqual": "3.0.7", |
| 76 | + "status": "affected", |
| 77 | + "version": "3.0.0", |
| 78 | + "versionType": "semver", |
| 79 | + } |
| 80 | + |
| 81 | + result_affected, result_fixed = parse_affected_fixed(affected) |
| 82 | + result_affected = [str(const) for const in result_affected] |
| 83 | + expected_affected = [">=3.0.0", "<=3.0.7"] |
| 84 | + expected_fixed = None |
| 85 | + |
| 86 | + self.assertCountEqual(result_affected, expected_affected) |
| 87 | + self.assertEqual(result_fixed, expected_fixed) |
0 commit comments