test(admin): assert admin auth is actually required, not just mocked#78
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdmin test suites for the events and profile contracts now verify that privileged entrypoints reject missing authorization and require the correct admin or pending-target identity, including timelocked operations and reputation slashing. ChangesAdmin authorization regression guards
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@Sendi0011 Solid work the mechanism is verified correct and matches the issue's deliverable.
|
setup() uses env.mock_all_auths(), which approves any address's require_auth() call unconditionally. Existing admin-suite tests only asserted on resulting state, so a deleted require_admin() call would not fail CI. Add negative tests per privileged entrypoint using env.mock_auths(&[]) so a missing auth check surfaces as a passing call instead of an error, turning the test red. Closes boundlessfi#73
…n_slash accept_admin does not call require_admin() in either contract -- it authorizes against the pending target address instead. Add a negative test (empty mock set) proving that call fails without any auth, and a positive test proving the auth demanded is specifically the pending target's via env.auths(), for both boundless-events and boundless-profile. Also add admin_slash_demands_admins_auth_specifically to reputation.rs, complementing the existing admin_slash_rejects_non_admin_caller (from boundlessfi#60) by proving the auth demanded on a normal call is specifically the admin's, not just any address mock_all_auths() happens to approve.
eb57b6d to
ed7174b
Compare
Gm @0xdevcollins, thanks for the review! I've pushed changes for all three points: For For
Did the same for both events and profile since the logic is identical in both. And commits should be signed now — set up SSH signing and rebased to sign everything on the branch. Ran |
Resolved snapshot file conflicts by accepting upstream deletion (snapshots are gitignored per repo convention). Upstream changes: - chore: stop tracking test snapshots; regenerate locally instead (boundlessfi#84) - test(admin): assert admin auth is actually required, not just mocked (boundlessfi#78) - fix(events): harden cancellation liveness (boundlessfi#82)

Summary
Closes #73
setup()in bothcontracts/events/src/tests/common.rsandcontracts/profile/src/tests/common.rscallsenv.mock_all_auths(),which approves any address's
require_auth()unconditionally. Theexisting admin-suite tests (
admin.rsin both crates) only assert onresulting contract state, never on which address was asked to
authorize. That means deleting
require_admin()from a privilegedentrypoint (
apply_upgrade,set_fee_account,pause/unpause,migrate,set_admin, etc.) would not fail CI — the call wouldsucceed identically with or without the check.
Fix
Added a negative test per
require_admin()-gated entrypoint in bothcontracts/events/src/tests/admin.rsandcontracts/profile/src/tests/admin.rs. Each test callsctx.env.mock_auths(&[])(empty auth set) immediately before invokingthe entrypoint via its
try_*client method, then asserts the callreturns
Err. Ifrequire_admin()is ever removed, the call stopsrequesting authorization, the empty mock set is never violated, and
the call succeeds — turning the test red.
This mirrors the existing auth-rejection pattern already used
elsewhere in the codebase (
profile/src/tests/reputation.rs,profile/src/tests/earnings.rs), rather than introducing a newconvention.
Entrypoints covered
events:
pause,unpause,set_admin,set_fee_bps,set_fee_account,set_profile_contract,propose_upgrade,apply_upgrade,cancel_pending_upgrade,migrateprofile:
pause,unpause,set_admin,set_events_contract,propose_events_contract,accept_events_contract,cancel_pending_events_contract,propose_upgrade,apply_upgrade,cancel_pending_upgrade,migrateTesting
cargo test -p boundless-events admin::— all passcargo test -p boundless-profile admin::— all passcargo test --workspace— full suite greenrequire_admin(env)?;frompause()incontracts/events/src/admin.rsand confirmedpause_reverts_without_admin_authfailed as expected, then reverted.Screenshot
Notes
setup()in bothcommon.rsfiles is left untouched(
mock_all_auths()is still required for the existing happy-pathtests); the new tests locally override the mock via
mock_auths(&[])only for the call under test.Summary by CodeRabbit
accept_adminenforces authorization specifically from the pending target address.admin_slash_reputationdemands the admin’s authorization as recorded in the execution context.