Skip to content

fix: return NotAuthorized for bookmark auth failures - #735

Open
TheFaith-Code wants to merge 7 commits into
Iris-IV:mainfrom
TheFaith-Code:fix/bookmark-auth-regression-672
Open

fix: return NotAuthorized for bookmark auth failures#735
TheFaith-Code wants to merge 7 commits into
Iris-IV:mainfrom
TheFaith-Code:fix/bookmark-auth-regression-672

Conversation

@TheFaith-Code

Copy link
Copy Markdown

Summary

Fixes the bookmark authorization regression for saved-campaign removal by ensuring an auth mismatch returns NotAuthorized instead of bubbling up as a host panic.

What changed

  • Updated bookmark save/remove handling to map unauthorized require_auth() failures to the contract's Error::NotAuthorized.
  • Added a regression test covering removal of a bookmark for a different user, confirming the expected authorization failure.
  • Cleaned up the contract module wiring so the Rust contract builds correctly again.

Why

Previously, bookmark removal could fail with a host auth panic when the supplied address did not have the required authorization. This made the behavior inconsistent with the contract’s intended error model and made the regression hard to test.

Verification

  • cargo fmt --check
  • cargo test --features testutils

Closes #672

@drips-wave

drips-wave Bot commented Aug 2, 2026

Copy link
Copy Markdown

@TheFaith-Code Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

update_campaign and update_campaign_description publish the metadata
updated event with a (old_title, old_description, new_title,
new_description) 4-tuple, but two tests still unpacked it as a 2-tuple,
causing UnexpectedSize. Align the assertions with the emitted shape.
require_auth failures are escalated to a panic by the SDK. A panic
escaping a contract call hits the generated extern "C" entrypoint
(nounwind), so the host's catch_unwind can never intercept it and the
process aborts. Catch it inside the contract body below that boundary,
gated on the testutils feature so wasm/production builds keep the
standard panic behavior and still compile without std.

@davidmaronio davidmaronio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thanks for digging into this, the writeup shows real investigation into the panic path and the regression test for removing someone else's bookmark is a scenario we genuinely didn't cover. a few things need to change before this can land though:

  1. src/bookmarks.rs:20-35: the catch_unwind path only exists under cfg(feature = "testutils"), so production wasm still traps with a host auth error and never returns Error::NotAuthorized. that means issue #672 isn't actually fixed on-chain, and the test now asserts behavior the deployed contract doesn't have. please drop require_auth_or_not_authorized entirely and keep plain user.require_auth() in the contract.
  2. src/tests/test_bookmarks.rs:123-125: you can write this regression test with no contract change. without mock_all_auths, client.try_remove_saved_campaign(&contributor2, &campaign_id) returns an invoke/host auth error you can assert on directly. that keeps test and production semantics identical.
  3. src/bookmarks.rs:25-28: even if we kept the wrapper, catch_unwind maps every panic to NotAuthorized, so any future unrelated panic in that closure becomes a fake auth error in tests.
  4. src/tests/test_bookmarks.rs:94-116: prefer setup_env + create_campaign over hand-building a Campaign struct with set_campaign, so the test doesn't silently drift when the struct gains fields.

happy to re-review once the contract-side wrapper is removed and the test asserts the host auth failure instead.

…h error in tests

- Drop  wrapper from , keeping standard  in contract methods.
- Update  in  to use  and  instead of manual  struct construction.
- Assert host authorization failure directly with  and  to match production contract semantics.
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.

[Testing] Add test for save_campaign called twice with a require_auth mismatch between the two calls

2 participants