You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains 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
Handle potential errors from storage.TokenID to prevent undefined behavior
Consider handling the case where err is not nil after the call to storage.TokenID(key). This would improve error handling and avoid proceeding with an undefined keyID.
Why: This suggestion improves error handling by ensuring that the function does not proceed with an undefined keyID, which could lead to unpredictable behavior. This is a crucial fix for stability.
10
Possible bug
Ensure a meaningful status code is returned when an error occurs
The condition if err != nil should be followed by a return statement that includes a default or meaningful status code if statusCode is not set, to avoid returning an uninitialized statusCode.
if err != nil {
+ if statusCode == 0 {+ statusCode = http.StatusInternalServerError // or another appropriate default code+ }
return err, statusCode
}
Suggestion importance[1-10]: 9
Why: This suggestion addresses a potential bug where an uninitialized status code might be returned, ensuring that a meaningful status code is always provided. This is important for robust error handling.
9
Best practice
Adjust the order of return values from validateSignature to follow Go's convention
The function validateSignature should return values in the order (statusCode, err) to follow Go's convention of returning the error as the last value. This will also require updating the handling of the returned values.
Why: This suggestion follows Go's convention of returning the error as the last value, which improves code readability and consistency. It is a best practice but not a critical fix.
8
Maintainability
Refactor the nested conditionals to improve code readability and maintainability
Refactor the nested conditionals for better readability and maintainability. Flatten the structure by handling error cases first and returning early.
Why: This suggestion improves code readability and maintainability by flattening nested conditionals. While it enhances the code structure, it is not as critical as fixing functional issues.
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.
User description
Description
Fix sonarcloud reported issue where err is returned when it is nil
Related Issue
https://tyktech.atlassian.net/browse/TT-11762
Motivation and Context
How This Has Been Tested
Screenshots (if appropriate)
Types of changes
Checklist
PR Type
Bug fix
Description
validateSignature
method within theProcessRequest
function ingateway/mw_auth_key.go
.Changes walkthrough 📝
mw_auth_key.go
Fix nil error check in `validateSignature` method
gateway/mw_auth_key.go
validateSignature
.