intel / cve-bin-tool

The CVE Binary Tool helps you determine if your system includes known vulnerabilities. You can scan binaries for over 200 common, vulnerable components (openssl, libpng, libxml2, expat and others), or if you know the components used, you can get a list of known vulnerabilities associated with an SBOM or a list of components and versions.
https://cve-bin-tool.readthedocs.io/en/latest/
GNU General Public License v3.0
1.24k stars 465 forks source link

test: regression tests for unset data #4441

Open terriko opened 2 months ago

terriko commented 2 months ago

The bug in #4438 happened because of an unset serial number, and a fix is in progress in #4440

What I'd like is some improved tests for unset data in output_engine so this doesn't happen again, so I want a test that tries to run output_engine/__init__.py with various values not set.

I have a feeling that any test that cycles through all the possible fields will right now find a few bugs, so we may want to start with just sbom_serial_number but design it so that we can have a parameter test with any given field unset so eventually all possible fields will be tested.

terriko commented 1 month ago

This may require some reading to make sure you understand how to use pytest and how to call the correct code, but I think it should be beginner-friendly so I'm tagging it as a "good first issue" and will put the new contributor tips below. I'm also tagging it for hacktoberfest. If you're interested in doing this as part of the contest, make sure you do it within their timeframe and follow their rules. (Most notably: don't create the PR before October 1 or it won't count)

Short tips for new contributors:

Claiming issues:

Malay-dev commented 1 month ago

Hey... I would like to work on this issue...

terriko commented 1 month ago

@Malay-dev Are you still working on this? Did you need some help?

Malay-dev commented 1 month ago

yep... I am still figuring out the pytest docs

def test_unset_sbom_serial_number(self):
        # Create a test case with sbom_serial_number unset
        test_data = {
            # Other required fields...
            "sbom_serial_number": None
        }

        # Attempt to run output_engine_init with the test data
        with self.assertRaises(Exception):  # Adjust the exception type as needed
            output_engine_init(**test_data)
Malay-dev commented 1 month ago

Hey @terriko Can you give some more guidance such as where I should make this test file and how can I test it after writing the test?