Skip to content

api: apps access tests on a real wallet DB; fix addr_list for apps (#1764) - #2162

Open
vsnation wants to merge 1 commit into
BeamMW:masterfrom
vsnation:fix/1764-apps-api-tests
Open

vsnation wants to merge 1 commit into
BeamMW:masterfrom
vsnation:fix/1764-apps-api-tests

Conversation

@vsnation

Copy link
Copy Markdown

Fix: tests that apps can only see and change their own txs and addresses, run against a real wallet DB (#1764). The tests found a bug in addr_list for apps, which is fixed here too.

Why: the API tests only checked that some methods are blocked for apps. The per-app filtering (checkTxAccessRights, address categories) had no tests, because they don't use a DB. The new tests found that addr_list compared the address category with the app name, while addresses are tagged with the app id. Every other check uses the id; the typo dates from f7dcfab (v6.1 API). So an app's addr_list never returned the addresses it created.

How to see the bug (master): apply only the test file and run it:

git apply --include='wallet/unittests/*' <this PR's patch>
cmake --build build --target wallet_api_test && (cd build/wallet/unittests && ./wallet_api_test); echo $?
# master: 3 failed checks in TestAppsAddressAccess (app A's addr_list is empty), exit 255

Improvement

addr_list own:true called by app A, which created addrA master this PR
result [] [addrA] (and not app B's or untagged addresses)

Tests (a V6Api subclass over a real SQLite WalletDB; no node, no ports):

  • TestAppsTxAccess: txs tagged A, B and untagged. tx_list: normal client sees all, app A only A, app B only B, an unknown app none. tx_status / tx_cancel / tx_delete on a foreign tx answer like an unknown tx, and nothing is deleted.
  • TestAppsPaymentProofAccess: export_payment_proof on a foreign tx gives the same error as a missing tx.
  • TestAppsAddressAccess: addr_list per app; create_address by an app is tagged with its id; edit_address / delete_address on foreign addresses are refused.

Testing: wallet_api_test passes. Negative controls: master's addr_list gives 3 failures; making checkTxAccessRights always allow gives 17 failures. CRLF line endings are kept. Fork CI (running): https://github.com/vsnation/beam/actions/runs/

Fixes #1764

…eamMW#1764)

Add wallet_api_test cases that run the real V6Api handlers against a
real WalletDB with txs and addresses tagged for app A, app B and none:
- tx_list / tx_status / tx_cancel / tx_delete / export_payment_proof:
  an app sees and acts only on its own txs, a normal client on all
- addr_list / create_address / edit_address / delete_address: an app
  sees and changes only the addresses it created

They found a bug: addr_list compared the address category with the app
*name*, but addresses are tagged with the app *id* (every other check
uses the id; typo from f7dcfab). So an app's addr_list never returned
the addresses it created. Compare with getAppId().
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.

apps api - tests improvement

1 participant