Skip to content
New issue

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

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

Already on GitHub? # to your account

Add error handling for missing API key #47

Merged
merged 5 commits into from
Feb 27, 2025
Merged

Add error handling for missing API key #47

merged 5 commits into from
Feb 27, 2025

Conversation

wneessen
Copy link
Owner

This PR introduces a new error, ErrMethodRequiresAPIKey, and the requiresAPIKey method to ensure that methods requiring an API key cannot proceed without one. This enhances input validation and prevents misuse of API-dependent methods.

Introduce a new error, ErrMethodRequiresAPIKey, and the requiresAPIKey function to ensure that methods requiring an API key cannot proceed without one. This enhances input validation and prevents misuse of API-dependent methods.
Added a check for API key validity across multiple HIBP API methods, including `BreachedAccount`, `SubscribedDomains`, `BreachedDomain`, and `Subscription.Status`. This ensures that requests are only made with a valid API key, improving error handling and alignment with API requirements.
This change ensures the API key is included when initializing the HTTP client in tests for various API endpoints. It improves test coverage for scenarios requiring authenticated requests, enhancing consistency and reliability in validation.
This test ensures that the subscription status request fails when no API key is provided. It validates that the correct error, `ErrMethodRequiresAPIKey`, is returned in such cases.
This commit adds test cases to ensure API key requirements are enforced for specific breach API methods. The new tests validate failure scenarios for "breached account," "subscribed domains," and "breached domain" endpoints when no API key is provided. These improvements strengthen the reliability of API key handling.
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.50%. Comparing base (1fed88e) to head (f774bda).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #47      +/-   ##
==========================================
+ Coverage   97.40%   97.50%   +0.09%     
==========================================
  Files           6        6              
  Lines         463      480      +17     
==========================================
+ Hits          451      468      +17     
  Misses          8        8              
  Partials        4        4              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@wneessen wneessen merged commit b5b4fef into main Feb 27, 2025
11 checks passed
@wneessen wneessen deleted the add-apikey-error branch February 27, 2025 12:42
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants