Closed buger closed 1 month ago
β±οΈ Estimated effort to review [1-5] | 2 |
π§ͺ Relevant tests | Yes |
π Security concerns | No |
β‘ Key issues to review |
Possible Bug: The method deleteRawKeysWithAllowanceScope does not handle the case where keyName is empty or null. This could potentially lead to the deletion of incorrect keys or no operation being performed when it is actually needed. |
Error Handling: The method deleteRawKeysWithAllowanceScope returns silently if store or session is nil. It might be beneficial to log these events or handle them more explicitly to aid in debugging and maintainability. |
API Changes
no api changes detected
Category | Suggestion | Score |
Enhancement |
Handle potential errors from
___
**To enhance the robustness of the | 9 |
Add unit tests for
___
**Add a unit test to verify that | 8 | |
Possible issue |
Add validation for
___
**Consider checking if | 8 |
Maintainability |
Refactor raw key deletion logic into a separate method to improve code organization___ **Refactor the loop indeleteRawKeysWithAllowanceScope to a separate method to improve readability and maintainability. This method could handle the construction and deletion of the raw key.** [gateway/auth_manager.go [90-95]](https://github.com/TykTechnologies/tyk/pull/6375/files#diff-311e18b071d244ed1615c0019215b633278679df373288b3451bcc5cf7c52c4eR90-R95) ```diff for _, acl := range session.AccessRights { + handleAllowanceScopeDeletion(acl, store, keyName) +} + +func handleAllowanceScopeDeletion(acl user.AccessDefinition, store storage.Handler, keyName string) { if acl.AllowanceScope == "" { - continue + return } rawKey := QuotaKeyPrefix + acl.AllowanceScope + "-" + keyName - store.DeleteRawKey(rawKey) + if !store.DeleteRawKey(rawKey) { + log.Errorf("Failed to delete raw key: %s", rawKey) + } } ``` Suggestion importance[1-10]: 7Why: Refactoring the loop into a separate method improves readability and maintainability, though it is more of a code organization enhancement rather than a critical fix. | 7 |
Failed conditions
C Reliability Rating on New Code (required β₯ A)
See analysis details on SonarCloud
Catch issues before they fail your Quality Gate with our IDE extension
SonarLint
User description
fix unnecessary call to DeleteRawKey if no allowance scope is defined (#6373)
User description
This PR fixes an issue where
DeleteRawKey
is called multiple times for AllowanceScopes that are non-existent.Types of changes
PR Type
Bug fix, Tests
Description
deleteRawKeysWithAllowanceScope
inDefaultSessionManager
to handle deletion of raw keys with allowance scopes.ResetQuota
to use the new method for better handling of raw key deletions.Changes walkthrough π
auth_manager.go
Add method to handle raw key deletion with allowance scopes
gateway/auth_manager.go
deleteRawKeysWithAllowanceScope
to handle deletionof raw keys with allowance scopes.
ResetQuota
to use the new method.auth_manager_test.go
Add unit tests for deleteRawKeysWithAllowanceScope method
gateway/auth_manager_test.go
deleteRawKeysWithAllowanceScope
method.countingStorageHandler
to count delete operations.and sessions with/without allowance scopes.
PR Type
Bug fix, Tests
Description
deleteRawKeysWithAllowanceScope
inDefaultSessionManager
to handle deletion of raw keys with allowance scopes.ResetQuota
to use the new method for better handling of raw key deletions.Changes walkthrough π
auth_manager.go
Add method for raw key deletion with allowance scopes
gateway/auth_manager.go
deleteRawKeysWithAllowanceScope
method to handle raw keydeletions with allowance scopes.
ResetQuota
to use the new method.auth_manager_test.go
Add unit tests for raw key deletion method
gateway/auth_manager_test.go
deleteRawKeysWithAllowanceScope
.countingStorageHandler
for test purposes.