Skip to content

Conversation

@pombredanne
Copy link
Member

This PR adds nginx importer and improver tests

Along the way there are several other adjustments and refinements that have been applied

#643
Signed-off-by: Philippe Ombredanne pombredanne@nexb.com

Also move doctest to tests/

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
The fact this is a namedtuple is an implementation detail that should
not be relied upon.

* Add new evolve_purl() helper function to help with this

Reference: package-url/packageurl-python#82
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
This makes these easier to reference and reuse in tests

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
There are useful utilities to handle test data.

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
* Refactor code for testability
* Move complex doctest to plain test code
* Ensure that there is Reference for a CVE
* Use object (NginxAdvisory namedtuple) rather than plain tuple of
  values when passing results around

Reference: #643
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
The fact this is a namedtuple is an implementation detail that should
not be relied upon.

* Add new evolve_purl() helper function to help with this

Reference: package-url/packageurl-python#82
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
By convention we put fields first, meta and then methods.

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
* Make it easier to test importer with a fetch() method.
  This way a test mock object can subclass NginxImporter.fetch
  to avoid making network calls.

* Add database test using an isolated transaction that tests a dump
  of the created advisories against an expected JSON

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
As part of testing nginx, it was easier to complete the migration of
all existing package version fetchers.

* Rename package_managers_2.py to package_managers.py
* Complete migration and add tests for all classes using mocks as needed
* Move test files in a common directory. Remove unused ones.
* Change semantics to yield PackageVreiosn and never cache by default.
  In practice for long running operations, caching is a problem and not
  a solution as it may hold to stale, our of date data.
* Create new helper to quety GitHub graphql API

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
avgs is not super meaningful, archlinux is better

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
* A logging statement was not formatted correctly.
* Also prefix with _ an unused variable

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
As part of the importers migrations, adjust to use new class names
for not-yet migrated importers.

This is mostly harmless as the code has not been migrated yet, but at
least most code now uses the proper new class names where possible.

Reference: #597
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
* Use new helper function for GH graphql API calls
* Use lower case logger
* Use severity_systems constants rather than a mapping lookup

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
* Do not use asyncio. Use the new simpler GitHubTagsAPI
* Extract fetching tags in a fetch_nginx_version_from_git_tags() method
* Add and improve importer and improver tests

Reference: #643
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
* Add AdvisoryData.to_dict() methods as convenience for testing
* Split NginxBasicImprover.get_inferences() in tow functions to ease
  testing

Reference: #643
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
To regen expected files, set VULNERABLECODE_REGEN_TEST_FIXTURES to any
value

Reference: https://github.com/nexB/vulnerablecode/blob/a7545e7e6fa94d3a3f6382bfab42f90a72bce7d7/vulnerabilities/tests/util_tests.py#L36
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Otherwise having a mapping with hardcode keys can drift in the future.

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Use as a license the same as the overall license for the project, as
this is the only statement that exists there.

Reference: #614
Reported-by: Hritik Vijay <hritikxx8@gmail.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
@pombredanne
Copy link
Member Author

pombredanne commented Apr 12, 2022

We reviewed these changes extensively in weekly call today. I would like to merge this ASAP unless there is an objection

@pombredanne
Copy link
Member Author

Actually the nginx improver is a problem:

Import:31

vulnerabilities.improvers.default.DefaultImprover several times"
In [13]: f"{Vulnerability.objects.count()}, {Package.objects.count()}"
Out[13]: '31, 78'

vulnerabilities.importers.nginx.NginxBasicImprover once:
In [30]: f"{Vulnerability.objects.count()}, {Package.objects.count()}"
Out[30]: '31, 662'

Reported-by: Tushar Goel <tushar.goel.dav@gmail.com>
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
avgs is not super meaningful, archlinux is better

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
isort should not sort migrations

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
* Use file-based test expectation for sanity. Otherwise updating test
  expectations to match code changes becomes a painful chore.

* TODO: the tests and data still need improvements for clarity and
  documentation

Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
@pombredanne
Copy link
Member Author

All green now .. merging !

Copy link
Contributor

@TG1999 TG1999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@pombredanne pombredanne merged commit eed065c into main Apr 15, 2022
@pombredanne pombredanne deleted the 643-nginx-tests branch April 15, 2022 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants