Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests using real files #107

Closed
terriko opened this issue Mar 20, 2019 · 4 comments
Closed

Add tests using real files #107

terriko opened this issue Mar 20, 2019 · 4 comments
Labels
good first issue Good for newcomers hacktoberfest good issue for hacktoberfest participation

Comments

@terriko
Copy link
Contributor

terriko commented Mar 20, 2019

To make the basic test suite run quickly, we use "faked" binary files to test the CVE mappings. However, we want to be able to test real files to test that the signatures work on real-world data.

In #99, I've added a _file_test function (to match the existing _binary_test) that takes a url, and package name and a version, and downloads the file, runs the scanner against it, and makes sure it is the file that you've specified. But we need more tests!

  • Existing tests are in test/
  • You can see the scanner tests in 'tests/test_scanner.py'
  • To add a new test, find an appropriate publicly available file (linux distribution packages and public releases of the packages itself are ideal)
  • Make sure to hide it behind the LONG_TESTS flag so we aren't doing huge number of downloads for every test suite run
    @unittest.skipUnless(os.getenv('LONG_TESTS') == '1', 'Skipping long tests')
    def test_rpm_curl_7_32_0(self):
        """
        test to see if we detect a real copy of curl 7.32.0
        """
        self._file_test(
            'https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/20/Everything/x86_64/os/Packages/c/',
            'curl-7.32.0-3.fc20.x86_64.rpm',
            'curl',
            '7.32.0')

I'd like to have at least one test for every checker, and it would be nice to have some different sources for each as well. For example, for packages available in common Linux distributions, we might want to have one from fedora, one from debian, and one direct from upstream to show that we detect all those versions.

@terriko terriko added good first issue Good for newcomers gsoc Tasks related to our participation in Google Summer of Code labels Mar 20, 2019
@terriko
Copy link
Contributor Author

terriko commented Mar 20, 2019

(Adding the gsoc tag since this is a good easy PR for prospective GSoC students)

@terriko
Copy link
Contributor Author

terriko commented Mar 21, 2019

Note that when you test this, you'll need to enable LONG_TESTS as follows:

LONG_TESTS=1 python -m unittest test.test_scanner.TestScanner.test_rpm_curl_7_32_0

@terriko
Copy link
Contributor Author

terriko commented May 31, 2019

All of the checkers currently have at least one file test as of #125. We have confirmed that some signatures work on some packages but not others, so if you're looking to add new tests of this type, I recommend trying to make sure you get ones in different formats or from different distributions. For example, if there's already a .rpm from fedora, try adding a .deb from debian or a .tar.gz from the developer.

@terriko terriko removed the gsoc Tasks related to our participation in Google Summer of Code label Sep 9, 2019
@terriko terriko added the hacktoberfest good issue for hacktoberfest participation label Oct 15, 2019
@terriko terriko removed the hacktoberfest good issue for hacktoberfest participation label Jan 8, 2020
@terriko terriko added the hacktoberfest good issue for hacktoberfest participation label Sep 30, 2020
@terriko
Copy link
Contributor Author

terriko commented Sep 30, 2020

This needs to be updated with the new test setup

@terriko terriko closed this as completed Sep 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers hacktoberfest good issue for hacktoberfest participation
Projects
None yet
Development

No branches or pull requests

1 participant