fix: add access control to set_risk_tier (closes #50)#84
Open
olaleyeolajide81-sketch wants to merge 1 commit into
Open
Conversation
- Add initialize(admin) to set a trusted admin address once - set_risk_tier now requires user.require_auth() — only the user (or an authorized invoker acting on their behalf) can update their own score; uninitialized contracts are rejected - Add get_admin() helper - Add testutils dev-dependency to Cargo.toml - Update all tests to use setup() helper with mock_all_auths() - Add test_initialize_sets_admin, test_initialize_twice_panics, test_admin_can_set_risk_tier_for_any_user, test_user_can_set_own_risk_tier (21 tests, all passing) Signed-off-by: Kiro <fix@riskon.dev>
|
Someone 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)— one-time setup that stores a trusted admin address in instance storage. Panics if called twice.get_admin()— read-only helper to inspect the stored admin.set_risk_tier— now callsuser.require_auth()before writing. The contract also asserts it has been initialized, so an undeployed/uninitialized contract cannot be called. The admin can satisfy the user auth requirement via Soroban's auth tree (standard composable pattern for Soroban v22).setup()helper that callsinitializeandmock_all_auths().test_initialize_sets_admin,test_initialize_twice_panics,test_admin_can_set_risk_tier_for_any_user,test_user_can_set_own_risk_tier).risk_score/Cargo.tomlsoroban-sdkwithtestutilsfeature to[dev-dependencies]so test utilities (mock_all_auths,Address::generate, etc.) compile correctly.Test results