Skip to content

fix: TestOutputEngine.test_output_json2 is failing due to missing cve_severity table #4903

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

Open
JigyasuRajput opened this issue Mar 5, 2025 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@JigyasuRajput
Copy link
Contributor

Description:
The test TestOutputEngine.test_output_json2 is failing with a sqlite3.OperationalError indicating that the cve_severity table does not exist in the database. First noticed here

Steps to Reproduce:

  1. Set up the environment and install dependencies.
  2. Run the test suite using the command:
    pytest test/test_output_engine.py
  3. Observe the failure in TestOutputEngine.test_output_json2.

Expected Behavior:
The test should pass, and the output_json2 function should successfully retrieve the count of CVE entries from the cve_severity table.

Actual Behavior:
The test fails with the following error:

sqlite3.OperationalError: no such table: cve_severity

Error Log:

================================================= FAILURES =================================================
____________________________________ TestOutputEngine.test_output_json2 ____________________________________
self = <test.test_output_engine.TestOutputEngine testMethod=test_output_json2>

    def test_output_json2(self):
        """Test formatting output as JSON2"""
>       output_json2(
            self.MOCK_OUTPUT,
            None,
            datetime.today(),
            self.mock_file,
            0,
            self.MOCK_ORGANIZED_PARAMETERS,
            metrics=True,
        )

test/test_output_engine.py:1074:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
cve_bin_tool/output_engine/json_output.py:116: in output_json2
    "total_entries": db_entries_count(),
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def db_entries_count():
        """
        Retrieves the count of CVE entries from the database grouped by data source.

        Returns:
            dict: A dictionary containing the count of CVE entries for each data source.
        """
        instance = CVEDB()
        cursor = instance.db_open_and_get_cursor()
        cve_entries_check = "SELECT data_source, COUNT(*) as number FROM cve_severity GROUP BY data_source ORDER BY number DESC"
>       cursor.execute(cve_entries_check)
E       sqlite3.OperationalError: no such table: cve_severity

cve_bin_tool/output_engine/json_output.py:54: OperationalError

Additional Context:
This issue might be related to the database initialization or migration process. It would be helpful to check if the database schema is up-to-date and if all necessary migrations have been applied or the test might be missing a fixture or setup step to create the required table.

Environment:

  • Python Version: 3.11.0rc1
  • Operating System: Linux
  • Dependencies: pytest-8.3.4
@22f1001635
Copy link
Contributor

Hi @JigyasuRajput @terriko , I've opened a PR that resolves TestOutputEngine.test_output_json2 failures caused by missing expected database entries. The fix ensures db_entries_count() always includes required keys and logs errors instead of silently failing. Additionally, generate.py now handles VEX generation failures are now under try except for better feedback. The changes improve test reliability and error traceability. Please take a look and let me know if some changes are needed #4905

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants