diff --git a/test/api/v3/integration/user/auth/POST-register_local.test.js b/test/api/v3/integration/user/auth/POST-register_local.test.js index 258cdc5de3..046009d997 100644 --- a/test/api/v3/integration/user/auth/POST-register_local.test.js +++ b/test/api/v3/integration/user/auth/POST-register_local.test.js @@ -37,6 +37,22 @@ describe('POST /user/auth/local/register', () => { expect(user.newUser).to.eql(true); }); + it('remove spaces from username', async () => { + let username = ' usernamewithspaces '; + let email = 'test@example.com'; + let password = 'password'; + + let user = await api.post('/user/auth/local/register', { + username, + email, + password, + confirmPassword: password, + }); + + expect(user.auth.local.username).to.eql(username.trim()); + expect(user.profile.name).to.eql(username.trim()); + }); + context('provides default tags and tasks', async () => { it('for a generic API consumer', async () => { let username = generateRandomUserName(); diff --git a/website/server/controllers/api-v3/auth.js b/website/server/controllers/api-v3/auth.js index db91e6ae3e..4a52e90d01 100644 --- a/website/server/controllers/api-v3/auth.js +++ b/website/server/controllers/api-v3/auth.js @@ -115,6 +115,7 @@ api.registerLocal = { // Get the lowercase version of username to check that we do not have duplicates // So we can search for it in the database and then reject the choosen username if 1 or more results are found email = email.toLowerCase(); + username = username.trim(); let lowerCaseUsername = username.toLowerCase(); // Search for duplicates using lowercase version of username