Skip to content

Commit 715bf82

Browse files
committed
Add tests for OSS-FUZZ
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent b56b3c1 commit 715bf82

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

vulnerabilities/tests/pipelines/test_curl_importer_v2.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#
22
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# VulnerableCode is a trademark of nexB Inc.
34
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/aboutcode-org/vulnerablecode for support or download.
7+
# See https://aboutcode.org for more information about nexB OSS projects.
48
#
59

610
from datetime import datetime

vulnerabilities/tests/pipelines/test_istio_importer_v2.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# VulnerableCode is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/aboutcode-org/vulnerablecode for support or download.
7+
# See https://aboutcode.org for more information about nexB OSS projects.
8+
#
9+
110
import tempfile
211
from pathlib import Path
312
from textwrap import dedent
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# VulnerableCode is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/aboutcode-org/vulnerablecode for support or download.
7+
# See https://aboutcode.org for more information about nexB OSS projects.
8+
#
9+
import pytest
10+
from unittest import mock
11+
12+
import yaml
13+
from vulnerabilities.pipelines.v2_importers.oss_fuzz import OSSFuzzImporterPipeline
14+
from vulnerabilities.importer import AdvisoryData
15+
16+
17+
@pytest.mark.django_db
18+
def test_collect_advisories_parses_yaml_correctly(tmp_path):
19+
advisory_path = tmp_path / "vulns" / "dummy_project"
20+
advisory_path.mkdir(parents=True)
21+
yaml_file = advisory_path / "CVE-2024-1234.yaml"
22+
23+
advisory_dict = {
24+
"id": "CVE-2024-1234",
25+
"summary": "Some summary here",
26+
"affected": [
27+
{
28+
"package": {"name": "some-lib"},
29+
"versions": ["1.0.0"]
30+
}
31+
]
32+
}
33+
yaml_file.write_text(yaml.dump(advisory_dict), encoding="utf-8")
34+
35+
pipeline = OSSFuzzImporterPipeline()
36+
pipeline.vcs_response = mock.Mock()
37+
pipeline.vcs_response.dest_dir = tmp_path
38+
39+
advisories = list(pipeline.collect_advisories())
40+
assert len(advisories) == 1
41+
assert advisories[0].advisory_id == "CVE-2024-1234"
42+
assert advisories[0].summary == "Some summary here"
43+
44+
45+
@pytest.mark.django_db
46+
def test_advisories_count(tmp_path):
47+
(tmp_path / "vulns" / "project").mkdir(parents=True)
48+
(tmp_path / "vulns" / "project" / "CVE-2023-0001.yaml").write_text("id: CVE-2023-0001")
49+
(tmp_path / "vulns" / "project" / "CVE-2023-0002.yaml").write_text("id: CVE-2023-0002")
50+
51+
pipeline = OSSFuzzImporterPipeline()
52+
pipeline.vcs_response = mock.Mock()
53+
pipeline.vcs_response.dest_dir = tmp_path
54+
55+
assert pipeline.advisories_count() == 2

0 commit comments

Comments
 (0)