Trimmed username spaces (#9793)

This commit is contained in:
Keith Holliday 2018-01-15 10:20:36 -07:00 committed by GitHub
parent 286566fc0c
commit 0ea91016f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View file

@ -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();

View file

@ -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