Skip to content

feat(CVEs): Adds the API endpoint to check CVEs availability for given snap#5100

Merged
bartaz merged 5 commits intomainfrom
cve-availablility-api
Apr 18, 2025
Merged

feat(CVEs): Adds the API endpoint to check CVEs availability for given snap#5100
bartaz merged 5 commits intomainfrom
cve-availablility-api

Conversation

@bartaz
Copy link
Copy Markdown
Member

@bartaz bartaz commented Apr 16, 2025

Done

Adds an API endpoint to check if given snap has CVE data available.
If the user is allowed to see the CVE data (is Canonical publisher and has access to said snap), and there is CVE data available in the snap-cves repo, it should return true, otherwise it should error.

How to QA

Testing

  • This PR has tests
  • No testing required (explain why):

Issue / Card

Fixes WD-20926

@webteam-app
Copy link
Copy Markdown

@bartaz bartaz force-pushed the cve-availablility-api branch from 2dca3e8 to 9de46ac Compare April 16, 2025 13:20
@bartaz bartaz force-pushed the cve-availablility-api branch from 9de46ac to 2e953b4 Compare April 17, 2025 07:40
@bartaz bartaz force-pushed the cve-availablility-api branch 2 times, most recently from f8f2820 to da992a8 Compare April 18, 2025 07:28
@bartaz bartaz marked this pull request as ready for review April 18, 2025 07:44
@bartaz bartaz requested a review from Copilot April 18, 2025 07:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request adds a new API endpoint to check for the availability of CVE data for a given snap. Key changes include:

  • Adding a new URL rule for the CVE endpoint in the publisher snaps view.
  • Implementing access checks and CVE data handling in the cve_views module.
  • Introducing a new helper method in cve_helper and adding tests for these endpoints.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
webapp/publisher/snaps/views.py Added URL rule for the new CVE endpoint.
webapp/publisher/cve/cve_views.py Refactored CVE access control and implemented the has_cves endpoint.
webapp/publisher/cve/cve_helper.py Added a static method to check for CVE data availability.
tests/publisher/cve/test_has_cve_api.py Added endpoint tests, though test names reference "policies" instead of "cves".
tests/publisher/cve/test_has_cve.py Added tests for CVE data helper behavior and expected NotFound exception on 404 cases.
Comments suppressed due to low confidence (1)

tests/publisher/cve/test_has_cve_api.py:41

  • [nitpick] The test case name 'test_get_policies_for_canonical_user' is ambiguous for a CVE endpoint; renaming it to 'test_has_cves_for_canonical_user' would improve clarity regarding its intent.
def test_get_policies_for_canonical_user(

Comment thread webapp/publisher/cve/cve_helper.py Outdated
Copy link
Copy Markdown
Contributor

@M7mdisk M7mdisk left a comment

Choose a reason for hiding this comment

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

LGTM

Comment thread webapp/publisher/cve/cve_views.py Outdated
@bartaz bartaz requested a review from Copilot April 18, 2025 11:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request adds an API endpoint to verify if a snap has associated CVE data available, incorporating user access validation and proper error handling. Key changes include:

  • Adding a new URL rule in publisher/snaps/views.py to expose the endpoint.
  • Refactoring CVE access checks into a common helper function (can_user_access_cve_data) in cve_views.py and introducing the has_cve_data method in cve_helper.py.
  • Updating and adding tests to ensure proper behavior for canonical and non-canonical users.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
webapp/publisher/snaps/views.py Added URL rule for the new CVE data availability endpoint
webapp/publisher/cve/cve_views.py Moved access checks to a new helper function and refactored views
webapp/publisher/cve/cve_helper.py Introduced static method has_cve_data for verifying CVE data
tests/publisher/cve/test_has_cve_api.py Added tests for the new API endpoint
tests/publisher/cve/test_has_cve.py Added unit tests for the new CVE data checker method

@bartaz bartaz merged commit 757f031 into main Apr 18, 2025
11 checks passed
@bartaz bartaz deleted the cve-availablility-api branch April 18, 2025 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants