feat: Add option to change log levels of username already exists message
Pull Request
- Report security issues confidentially.
- Any contribution is under this license.
- Link this pull request to an issue.
Issue
Fixes: https://github.com/parse-community/parse-server/issues/9329
- [x] Add tests
- [ ] Add changes to documentation (guides, repository pages, code comments)
- [ ] Add security check
- [ ] Add new Parse Error codes to Parse JS SDK
Summary by CodeRabbit
-
New Features
- Added a new log-level setting signupUsernameTaken to control how sign-up failures for an already-existing username are logged (default: 'error'); documentation updated.
-
Tests
- Added tests that verify logging behavior for duplicate-username signups under different log-level configurations (e.g., 'warn' and 'silent').
โ๏ธ Tip: You can customize this high-level summary in your review settings.
๐ Thanks for opening this pull request!
๐ Walkthrough
Walkthrough
Adds a new log-level option signupUsernameTaken (env PARSE_SERVER_LOG_LEVELS_SIGNUP_USERNAME_TAKEN, default 'info') to LogLevels, updates error-handling middleware to honor it for Parse.Error.USERNAME_TAKEN, adds docs/types/definitions entries, and adds tests validating 'warn' and 'silent' behaviors.
Changes
| Cohort / File(s) | Summary |
|---|---|
Tests spec/ParseUser.spec.js |
Adds two tests that attempt duplicate-username signups and assert logger calls for signupUsernameTaken when configured as 'warn' and 'silent', and verify the signup still throws USERNAME_TAKEN. |
Options definitions & docs src/Options/Definitions.js, src/Options/docs.js, src/Options/index.js |
Introduces signupUsernameTaken in exported LogLevels with env PARSE_SERVER_LOG_LEVELS_SIGNUP_USERNAME_TAKEN, help text, and default 'info'; adds corresponding documentation and index typing/comment. |
Middleware src/middlewares.js |
In handleParseErrors, reads req.config?.logLevels?.signupUsernameTaken (default 'info') and logs Parse.Error.USERNAME_TAKEN using that level; treats 'silent' as no-op and falls back to log.error if the configured level method is missing. |
Type declarations types/Options/index.d.ts |
Adds signupUsernameTaken?: string to the LogLevels interface. |
Estimated code review effort
๐ฏ 3 (Moderate) | โฑ๏ธ ~20โ30 minutes
- Pay attention to:
src/middlewares.jsโ correct default ('info'), handling of'silent', and fallback when the logger method for the configured level is absent.- Consistency of env var name, help text, and default across
Definitions.js,docs.js,index.js, andtypes/Options/index.d.ts. spec/ParseUser.spec.jsโ ensure logger spies/assertions match the intended call counts and that the test still asserts theUSERNAME_TAKENerror is raised.
Pre-merge checks and finishing touches
โ Failed checks (1 warning, 1 inconclusive)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | โ ๏ธ Warning | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
| Description check | โ Inconclusive | The description includes the required issue link (#9329) and indicates tests were added, but does not describe the implementation approach or changes made. | Add an 'Approach' section describing how the signupUsernameTaken log level option was implemented and integrated into the codebase. |
โ Passed checks (3 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | โ Passed | The title accurately summarizes the main change: adding an option to control log levels for username-taken signup failures. |
| Linked Issues check | โ Passed | The PR successfully implements the requested feature: adds a signupUsernameTaken log level option (defaulting to 'info') that controls logging behavior for duplicate username signup attempts, with tests validating 'warn' and 'silent' configurations. |
| Out of Scope Changes check | โ Passed | All changes directly support the core objective of issue #9329: adding configuration and logging for username-taken events. No unrelated modifications detected. |
โจ Finishing touches
- [ ] ๐ Generate docstrings
๐งช Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
:white_check_mark: Snyk checks have passed. No issues have been found so far.
| Status | Scanner | Total (0) | ||||
|---|---|---|---|---|---|---|
| :white_check_mark: | Open Source Security | 0 | 0 | 0 | 0 | 0 issues |
:computer: Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 92.58%. Comparing base (6b9f896) to head (0422864).
:warning: Report is 4 commits behind head on alpha.
Additional details and impacted files
@@ Coverage Diff @@
## alpha #9962 +/- ##
=======================================
Coverage 92.58% 92.58%
=======================================
Files 191 191
Lines 15544 15549 +5
Branches 177 177
=======================================
+ Hits 14391 14396 +5
Misses 1141 1141
Partials 12 12
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
I think we can also the default level for this to info. It's not really an error or warning.
LogEvents is still all over the code
Do you mean this object ?
This is because in the issue you mentionned this kind of object:
Do you want I delete the object and pass directly the option ?
I see where you got this from. May have been a typo. logLevels does the same for Cloud Function and trigger events:
logLevels: {
env: 'PARSE_SERVER_LOG_LEVELS',
help: '(Optional) Overrides the log levels used internally by Parse Server to log events.',
action: parsers.objectParser,
type: 'LogLevels',
default: {},
},
Let's add there, unless you can think of a reason not to? They are grouped by prefix, cloudFunction..., trigger..., so maybe add a prefix like signup... since this is a sign-up event and name it signupUsernameTaken, which is the same wording as ParseError.USERNAME_TAKEN = 202, so we have a nice mapping.
Yes, I fixed the option file
Before merging, let me check if Parse Server 9 release can be done before that.