Conversation
Reviewer's GuideThis PR integrates bcrypt-based password hashing into the User model’s update and save workflows, updates the test suite to inject dummy Supabase configuration and refine mocks, and adds targeted unit tests to verify the new hashing logic. Sequence Diagram: Password Hashing in
|
| Change | Details | Files |
|---|---|---|
| Implement conditional password hashing in User model methods |
|
server/models/User.js |
| Enhance test environment setup with dummy Supabase config and refined mocks |
|
tests/server/routes/index.test.jstests/wir-transactions.test.js |
| Add unit tests for password hashing logic in User model |
|
tests/server/models/user-password.test.js |
Tips and commands
Interacting with Sourcery
- Trigger a new review: Comment
@sourcery-ai reviewon the pull request. - Continue discussions: Reply directly to Sourcery's review comments.
- Generate a GitHub issue from a review comment: Ask Sourcery to create an
issue from a review comment by replying to it. You can also reply to a
review comment with@sourcery-ai issueto create an issue from it. - Generate a pull request title: Write
@sourcery-aianywhere in the pull
request title to generate a title at any time. You can also comment
@sourcery-ai titleon the pull request to (re-)generate the title at any time. - Generate a pull request summary: Write
@sourcery-ai summaryanywhere in
the pull request body to generate a PR summary at any time exactly where you
want it. You can also comment@sourcery-ai summaryon the pull request to
(re-)generate the summary at any time. - Generate reviewer's guide: Comment
@sourcery-ai guideon the pull
request to (re-)generate the reviewer's guide at any time. - Resolve all Sourcery comments: Comment
@sourcery-ai resolveon the
pull request to resolve all Sourcery comments. Useful if you've already
addressed all the comments and don't want to see them anymore. - Dismiss all Sourcery reviews: Comment
@sourcery-ai dismisson the pull
request to dismiss all existing Sourcery reviews. Especially useful if you
want to start fresh with a new review - don't forget to comment
@sourcery-ai reviewto trigger a new review!
Customizing Your Experience
Access your dashboard to:
- Enable or disable review features such as the Sourcery-generated pull request
summary, the reviewer's guide, and others. - Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.
Getting Help
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
| const userData = { | ||
| username: this.username, |
There was a problem hiding this comment.
The method save does not show the conversion of user data keys from camelCase to snake_case before updating the database. If the database schema expects snake_case (as seen in other parts of the code), this inconsistency can lead to bugs or data not being saved correctly. Ensure that data keys are consistently formatted before any database operations to prevent potential issues.
| expect(supabaseAdmin.update).toHaveBeenCalledWith(expect.objectContaining({ password: 'hashed_pw2' })); | ||
| }); |
There was a problem hiding this comment.
The test uses expect.objectContaining to check if the password field in the object passed to supabaseAdmin.update contains the expected hashed password. While this is useful for partial matching, it might be beneficial to assert the entire object structure to ensure that no unexpected fields are being updated or that all necessary fields are included in the update. This would enhance the robustness of the test by verifying the complete payload.
Recommended Solution:
Consider using a more specific assertion to check the entire object structure, especially if the structure is known and critical. For example:
expect(supabaseAdmin.update).toHaveBeenCalledWith({ id: 'user2', password: 'hashed_pw2' });| process.env.SUPABASE_URL = process.env.SUPABASE_URL || 'http://localhost'; | ||
| process.env.SUPABASE_KEY = process.env.SUPABASE_KEY || 'key'; | ||
| process.env.SUPABASE_SERVICE_KEY = process.env.SUPABASE_SERVICE_KEY || 'service'; |
There was a problem hiding this comment.
Security Issue: Hardcoded Sensitive Keys
The environment variables for Supabase (SUPABASE_URL, SUPABASE_KEY, SUPABASE_SERVICE_KEY) are being set with hardcoded fallback values directly in the test file. This practice can lead to security risks if sensitive keys are exposed in the codebase.
Recommendation:
- Use a secure method to manage environment variables, such as loading them from a
.envfile or a secure vault, especially for sensitive keys. Ensure that no sensitive information is hardcoded in the codebase.
| process.env.SUPABASE_URL = process.env.SUPABASE_URL || 'http://localhost'; | ||
| process.env.SUPABASE_KEY = process.env.SUPABASE_KEY || 'key'; | ||
| process.env.SUPABASE_SERVICE_KEY = process.env.SUPABASE_SERVICE_KEY || 'service'; |
There was a problem hiding this comment.
Hardcoding default values for sensitive keys (SUPABASE_KEY, SUPABASE_SERVICE_KEY) directly in the test file poses a security risk. It's recommended to manage these keys securely, for example, by using environment-specific configuration files or secret management tools that do not expose these keys in the codebase. This approach helps prevent accidental exposure and misuse of sensitive keys.
| process.env.SUPABASE_URL = process.env.SUPABASE_URL || 'http://localhost'; | ||
| process.env.SUPABASE_KEY = process.env.SUPABASE_KEY || 'key'; | ||
| process.env.SUPABASE_SERVICE_KEY = process.env.SUPABASE_SERVICE_KEY || 'service'; |
There was a problem hiding this comment.
Direct manipulation of environment variables within the test file (SUPABASE_URL, SUPABASE_KEY, SUPABASE_SERVICE_KEY) can lead to difficulties in managing changes in the environment configuration. Consider using a centralized configuration management approach, such as a dedicated configuration module or file that handles all environment settings. This would improve the maintainability and scalability of the test environment setup.
There was a problem hiding this comment.
Hey @numbpill3d - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| */ | ||
| async save() { | ||
| try { | ||
| if (this.password) { |
There was a problem hiding this comment.
issue (bug_risk): Hashing all passwords on save may cause double-hashing
Currently, the save method re-hashes the password every time, even if it hasn't changed. This can result in double-hashing and lock users out. Only hash the password if it was modified.
Summary
findByIdAndUpdateandsaveItemmodel path inindexroute testsTesting
npm test(fails: fetch failed due to missing Supabase credentials)https://chatgpt.com/codex/tasks/task_e_68450e3887f4832fbb35c49f86c2aac9
Summary by Sourcery
Ensure that user passwords are securely hashed before being stored or updated in the database and bolster test coverage around this logic.
New Features:
Tests: