This document details the functionality added by the latest patch to the parsers in the project. The patch introduces and tests various parsers for different programming languages and ensures they correctly identify and handle specific file types.
The addition of these parsers enhances the capability of the project to handle a variety of file types associated with different programming languages. The comprehensive test ensures that these parsers are correctly mapped and function as expected.
The following parsers have been added to the project:
- DartParser
- GoParser
- JavaParser
- JavascriptParser
- PerlParser
- PhpParser
- PythonParser
- PythonRequirementsParser
- RParser
- RubyParser
- RustParser
- SwiftParser
- BanditParser
A new test class TestParsers has been introduced to verify that the expected file types are correctly mapped to their respective parsers. The test ensures that the actual valid files match the expected valid files.
- test_parser_match_filenames_results_in_correct_valid_files: This test compares the EXPECTED_VALID_FILES dictionary with the actual_valid_files dictionary imported from cve_bin_tool.parsers.parse. If there is any discrepancy between the two, the test will fail, indicating that the loaded file types do not match the expected registered file types.
To utilize these parsers, ensure that your project includes the following imports:
from cve_bin_tool.parsers.dart import DartParser
from cve_bin_tool.parsers.go import GoParser
from cve_bin_tool.parsers.java import JavaParser
from cve_bin_tool.parsers.javascript import JavascriptParser
from cve_bin_tool.parsers.perl import PerlParser
from cve_bin_tool.parsers.php import PhpParser
from cve_bin_tool.parsers.python import PythonParser, PythonRequirementsParser
from cve_bin_tool.parsers.r import RParser
from cve_bin_tool.parsers.ruby import RubyParser
from cve_bin_tool.parsers.rust import RustParser
from cve_bin_tool.parsers.swift import SwiftParser
from cve_bin_tool.parsers.bandit import BanditParser
To implement a new parser plugin, such as a Bandit parser, follow these steps:
First, create the parser class. This class should be located in the appropriate directory within your project. For example, you might place it in cve_bin_tool/parsers/bandit.py.
.. includefile:: cve_bin_tool/parsers/static_analysis_bandit.py
Next, configure the setup.py
file boilerplate.
# setup.py
import sys
import site
import setuptools
# See https://github.com/pypa/pip/issues/7953
site.ENABLE_USER_SITE = "--user" in sys.argv[1:]
setuptools.setup(use_scm_version=True)
Next, configure the setup.cfg
file to include your new parser as an entry point. This allows the parser to be dynamically discovered and used by the project.
# setup.cfg
[metadata]
name = cve-bin-tool-parser-static-analysis-bandit
version = 1.0.0
description = CVE Binary Tool Parser Plugin: Static Analysis: Bandit
[options]
packages = find:
entry_points = file: entry_points.txt
setup_requires =
setuptools_scm[toml]>=3.4.3
You may also need to configure an entry_points.txt
file if your project uses it to manage entry points.
# entry_points.txt
[cve_bin_tool.parsers]
bandit = cve_bin_tool.parsers.bandit:BanditParser
You need to activate your virtualenv before installing if you set one up.
$ python -m pip install -e .
In this example we implemented the BanditParser
which is a static
analysis tool for Python files. We'll test that it loads by scanning
a .py
file.
$ cve-bin-tool --log debug setup.py