fix(contract): add access control to set_risk_tier (closes #50)#85
Open
akordavid373 wants to merge 1 commit into
Open
fix(contract): add access control to set_risk_tier (closes #50)#85akordavid373 wants to merge 1 commit into
akordavid373 wants to merge 1 commit into
Conversation
…un#50) - Add initialize(admin) to set a trusted admin address once - set_risk_tier now requires caller == admin OR caller == user - Add get_admin() helper - Add testutils dev-dependency for test utilities - Update all tests to use setup() helper with mock_all_auths - Add 3 new auth tests: admin can set any user, user can set own, stranger cannot overwrite another user's score - 22/22 tests pass, clippy clean, fmt clean Signed-off-by: david akor <akordavid373@gmail.com>
|
@akordavid373 is attempting to deploy a commit to the mericcintosun Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #50 —
set_risk_tierhad no authorization check, allowing any address to overwrite any user's risk score.Changes
risk_score/src/lib.rsinitialize(admin: Address)— stores the admin address in instance storage once; panics if called againget_admin()— returns the stored admin addressset_risk_tiersignature to(env, caller, user, score, tier, chosen_tier)caller.require_auth()enforces on-chain signature verificationcaller == admin || caller == user; panics with"Unauthorized"otherwiseinitializevia asetup()helper withmock_all_authsrisk_score/Cargo.toml[dev-dependencies]withsoroban-sdk = { version = "22.0.8", features = ["testutils"] }Tests
3 new auth-specific tests:
test_admin_can_set_any_user_tiertest_user_can_set_own_tiertest_stranger_cannot_set_other_user_tierUnauthorized22/22 tests pass.
cargo clippyandcargo fmtclean.