-
-
Notifications
You must be signed in to change notification settings - Fork 371
refactor: fix duplicate keychecker #2339
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
Conversation
4b5a895 to
27dc00a
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #2339 +/- ##
==========================================
- Coverage 61.65% 61.61% -0.05%
==========================================
Files 68 68
Lines 9720 9681 -39
==========================================
- Hits 5993 5965 -28
+ Misses 3727 3716 -11 ☔ View full report in Codecov by Sentry. |
ce20c93 to
0cca7b3
Compare
aea699c to
6bb4fd6
Compare
a57cf79 to
2a9f0bd
Compare
24c040e to
f8942b8
Compare
- refactor KeyChecker to be more approachable - only 1 sql query needed even if you use `get_key_type` - rename `WalletType` to `KeyType` wallet type was misleading fix test sorting
f8942b8 to
f4ad2cc
Compare
tests/api/test_api.py
Outdated
| }, | ||
| ) | ||
| assert response.status_code == 404 | ||
| assert response.status_code == 401 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- add assertion for delete with invoice key:
response = await client.delete(
"/api/v1/wallet",
headers={
"X-Api-Key": result["inkey"],
"Content-type": "application/json",
},
)
lnbits/decorators.py
Outdated
| key_value = ( | ||
| self._api_key | ||
| if self._api_key | ||
| else request.headers.get("X-API-KEY") or request.query_params["api-key"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit inconsistent:
- if
request.query_paramsis missing then an exception is raised andHTTP 400 (BAD_REQUEST)is returned - but if
request.query_paramsisNoneor""then anHTTP 401 (UNAUTHORIZED)is returned
| else request.headers.get("X-API-KEY") or request.query_params["api-key"] | |
| else request.headers.get("X-API-KEY") or request.query_paramsget("api-key") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as a consequence the catch block should catch a generic Exception and return an Internal Server Error
tests/api/test_api.py
Outdated
| async def test_put_empty_request_expected_admin_keys(client): | ||
| response = await client.put("/api/v1/wallet/newwallet") | ||
| assert response.status_code == 401 | ||
| assert response.status_code == 400 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert as a consequence of https://github.com/lnbits/lnbits/pull/2339/files#r1598398184
tests/api/test_api.py
Outdated
| async def test_post_empty_request_expected_invoice_keys(client): | ||
| response = await client.post("/api/v1/payments") | ||
| assert response.status_code == 401 | ||
| assert response.status_code == 400 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert as a consequence of https://github.com/lnbits/lnbits/pull/2339/files#r1598398184
get_key_typeWalletTypetoKeyTypewallet type was misleading