-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add default user for old endpoints #1665
Conversation
WalkthroughThe changes across the codebase involve the integration of Ethereum cryptographic functions, adjustments to user account management, and modifications to logging practices. A new import for Ethereum's crypto package is added to generate key pairs for user accounts, and a default user is set up and managed within the system. Logging levels are shifted from error to informational in certain handlers, and test scenarios are updated to reflect new conditions. Additionally, there's a focus on preventing the exposure of the default user's ID. Changes
TipsChat with CodeRabbit Bot (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 3
Configuration used: CodeRabbit UI
Files selected for processing (1)
- tools/walletextension/container/walletextension_container.go (2 hunks)
Additional comments: 2
tools/walletextension/container/walletextension_container.go (2)
7-14:
The addition of thecrypto
package is consistent with the changes described in the summary.57-57:
Ensure that the generated key pair is securely handled and that the private key is not exposed or logged.
// add default user to the database (temporary fix before removing wallet extension endpoints) | ||
accountPrivateKey, err := crypto.GenerateKey() | ||
if err != nil { | ||
logger.Error("Unable to generate hey pair for default user", log.ErrKey, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in the log message.
- logger.Error("Unable to generate hey pair for default user", log.ErrKey, err)
+ logger.Error("Unable to generate key pair for default user", log.ErrKey, err)
Commitable suggestion
❗ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
logger.Error("Unable to generate hey pair for default user", log.ErrKey, err) | |
logger.Error("Unable to generate key pair for default user", log.ErrKey, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zkokelj Great, if there's anything else that needs attention, feel free to let me know!
err = databaseStorage.AddUser([]byte(wecommon.DefaultUser), crypto.FromECDSA(accountPrivateKey)) | ||
if err != nil { | ||
logger.Error("Unable to save default user to the database", log.ErrKey, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error from databaseStorage.AddUser
is not handled; it should exit or return the error instead of just logging it.
- logger.Error("Unable to save default user to the database", log.ErrKey, err)
+ return fmt.Errorf("unable to save default user to the database: %w", err)
Commitable suggestion
❗ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
err = databaseStorage.AddUser([]byte(wecommon.DefaultUser), crypto.FromECDSA(accountPrivateKey)) | |
if err != nil { | |
logger.Error("Unable to save default user to the database", log.ErrKey, err) | |
err = databaseStorage.AddUser([]byte(wecommon.DefaultUser), crypto.FromECDSA(accountPrivateKey)) | |
if err != nil { | |
return fmt.Errorf("unable to save default user to the database: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zkokelj Great, if the fix has been applied as suggested, it should now properly handle the error when saving the default user to the database. If there's anything else that needs attention, feel free to let me know!
(\__/)
(•ㅅ•)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 2
Configuration used: CodeRabbit UI
Files selected for processing (1)
- tools/walletextension/container/walletextension_container.go (2 hunks)
Additional comments: 2
tools/walletextension/container/walletextension_container.go (2)
7-14:
The addition of the "github.com/ethereum/go-ethereum/crypto" package is appropriate for generating cryptographic key pairs as described in the summary.61-65:
The error handling fordatabaseStorage.AddUser
now correctly exits the program if an error occurs, which aligns with the previous review comments.
…rror to info when user is not found
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 3
Configuration used: CodeRabbit UI
Files selected for processing (4)
- tools/walletextension/api/routes.go (3 hunks)
- tools/walletextension/container/walletextension_container.go (2 hunks)
- tools/walletextension/test/wallet_extension_test.go (1 hunks)
- tools/walletextension/wallet_extension.go (2 hunks)
Files skipped from review due to trivial changes (2)
- tools/walletextension/api/routes.go
- tools/walletextension/test/wallet_extension_test.go
Additional comments: 2
tools/walletextension/wallet_extension.go (2)
9-13:
The import statement foraccountmanager
is correctly added.340-354:
The logic to prevent exposing the default user's userID externally is correctly implemented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left a comment around error handling
// add default user to the database (temporary fix before removing wallet extension endpoints) | ||
accountPrivateKey, err := crypto.GenerateKey() | ||
if err != nil { | ||
logger.Error("Unable to generate key pair for default user", log.ErrKey, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for all these error handlings in the constructor, I think the gateway should panic.
There is no point continuing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (1)
- tools/walletextension/container/walletextension_container.go (2 hunks)
Additional comments: 1
tools/walletextension/container/walletextension_container.go (1)
- 79-99: The TODO comments indicate that the code related to the default user is a temporary fix and should be removed in the future. Ensure that the removal of this code is tracked and managed properly to avoid regressions or the unintentional removal of necessary functionality.
// add default user to the database (temporary fix before removing wallet extension endpoints) | ||
accountPrivateKey, err := crypto.GenerateKey() | ||
if err != nil { | ||
logger.Error("Unable to generate key pair for default user", log.ErrKey, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of os.Exit(1)
is consistent with the error handling strategy in the constructor, effectively halting the program on critical errors. However, consider using panic
to provide a stack trace for better debugging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Why this change is needed
Following test was failing after latest changes: TestCannotInvokeSensitiveMethodsWithoutViewingKey
To get it working as expected we need to add a default user that is used with old endpoints and if userID was not found.
What changes were made as part of this PR
Added default userID to the database at startup
PR checks pre-merging
Please indicate below by ticking the checkbox that you have read and performed the required
PR checks