Skip to content
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

feat: Add customizable log level for 'username already exists' error #9336

Open
wants to merge 23 commits into
base: alpha
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c3e9106
feat: Add customizable log level for 'username already exists' error
KrishDave1 Oct 10, 2024
a54e2c6
feat: Made the suggested changes
KrishDave1 Oct 11, 2024
ae26647
fix: Added 2 log levels for Testing and followed new ParseServerConfi…
KrishDave1 Oct 12, 2024
8db9580
Merge branch 'alpha' into feat-branch
mtrezza Oct 12, 2024
da1785c
fix: Added a loop in test to remove redundant code
KrishDave1 Oct 12, 2024
1bedc3c
Merge branch 'feat-branch' of https://github.com/KrishDave1/parse-ser…
KrishDave1 Oct 12, 2024
63b4f9b
feat: Added the both the tests inside one testcase
KrishDave1 Oct 12, 2024
d582e56
Simplified the code further
KrishDave1 Oct 12, 2024
6c21038
refactor
mtrezza Oct 13, 2024
a557e78
consider default level
mtrezza Oct 13, 2024
0a5aa42
fix typo
mtrezza Oct 13, 2024
f537c2c
add warnjs
mtrezza Oct 13, 2024
8e4ac7c
Merge branch 'alpha' into feat-branch
mtrezza Oct 13, 2024
5ec7c82
Removed the extra logger from RestWrite.js
KrishDave1 Oct 15, 2024
a14f5f2
Merge branch 'alpha' into feat-branch
mtrezza Oct 15, 2024
386d2c1
fix: Usernames will always be unique for testing
KrishDave1 Oct 16, 2024
f028be7
Merge branch 'feat-branch' of https://github.com/KrishDave1/parse-ser…
KrishDave1 Oct 16, 2024
dff8140
Merge branch 'alpha' into feat-branch
mtrezza Oct 16, 2024
3587fb8
un-fdescribe
mtrezza Oct 16, 2024
9f3c82a
fit
mtrezza Oct 16, 2024
f1bc586
refactor
mtrezza Oct 16, 2024
2a03838
Check again for info
KrishDave1 Oct 16, 2024
3451ebf
Merge branch 'alpha' into feat-branch
mtrezza Oct 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions spec/ParseUser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4429,4 +4429,32 @@ describe('allowClientClassCreation option', () => {
// Need to set it back to true to avoid other test fails
defaultConfiguration.allowClientClassCreation = true;
});

it('should respect custom log level for username already exists error', async () => {
const logger = require('../lib/logger').logger;
const logSpy = spyOn(logger, 'warn').and.callThrough();
mtrezza marked this conversation as resolved.
Show resolved Hide resolved
mtrezza marked this conversation as resolved.
Show resolved Hide resolved

await reconfigureServer({
logEvents: {
usernameAlreadyExists: 'warn',
},
});

const user = new Parse.User();
user.setUsername('existingUser');
user.setPassword('password');
await user.signUp();

const duplicateUser = new Parse.User();
duplicateUser.setUsername('existingUser');
duplicateUser.setPassword('password');

try {
await duplicateUser.signUp();
} catch (error) {
expect(error.code).toBe(Parse.Error.USERNAME_TAKEN);
expect(logSpy).toHaveBeenCalled();
expect(logger.error).not.toHaveBeenCalled();
}
});
});
1 change: 1 addition & 0 deletions src/Options/docs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/Options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export interface ParseServerOptions {
verbose: ?boolean;
/* Sets the level for logs */
logLevel: ?string;
/* (Optional) Overrides the log levels used internally by Parse Server to log events.
/* Options for customizing log levels for specific events
mtrezza marked this conversation as resolved.
Show resolved Hide resolved
:DEFAULT: {} */
logLevels: ?LogLevels;
/* Maximum number of logs to keep. If not set, no logs will be removed. This can be a number of files or number of days. If using days, add 'd' as the suffix. (default: null) */
Expand Down Expand Up @@ -635,4 +635,10 @@ export interface LogLevels {
:DEFAULT: error
*/
cloudFunctionError: ?string;
/* Log level for the "username already exists" error when trying to sign up.
Possible values: 'info', 'error', 'verbose', or false to disable logging.
If not specified, the default behavior (logging as an error) will be used.
:DEFAULT: undefined
mtrezza marked this conversation as resolved.
Show resolved Hide resolved
*/
usernameAlreadyExists: 'silent' | 'error' | 'info' | 'verbose';
}
7 changes: 6 additions & 1 deletion src/RestWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -1557,10 +1557,15 @@ RestWrite.prototype.runDatabaseOperation = function () {

// Quick check, if we were able to infer the duplicated field name
if (error && error.userInfo && error.userInfo.duplicated_field === 'username') {
throw new Parse.Error(
//Instead of directly throwing the error, we will give error based on logEvent
mtrezza marked this conversation as resolved.
Show resolved Hide resolved
const usernameError = new Parse.Error(
Parse.Error.USERNAME_TAKEN,
'Account already exists for this username.'
);

return this.config.loggerController[this.config.logLevels.usernameAlreadyExists](
JSON.stringify(usernameError)
);
}

if (error && error.userInfo && error.userInfo.duplicated_field === 'email') {
Expand Down