From 11d86c3b44d058c1f23494b940e208f6dbcb5a09 Mon Sep 17 00:00:00 2001 From: McFlat Date: Wed, 17 Oct 2018 11:01:04 -0500 Subject: [PATCH 1/2] make username, display_name and video_channel_name min length 1 and max length 50; (fixes #1263); ! still some bug on the frontend complains but if you remove the disabled property it creates the account just fine; allow for usernames to start with a number; fix test, since username can be 1 char now make test check empty; fix test, Should fail with a too long username; fix test, Should fail with a too small username; fix regular expression for username and videoChannel; change username, videoChannel to be lowercase and fix message; --- .../user-validators.service.ts | 20 +++++++++---------- .../video-channel-validators.service.ts | 20 +++++++++---------- server/initializers/constants.ts | 6 +++--- server/tests/api/check-params/users.ts | 8 ++++---- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/client/src/app/shared/forms/form-validators/user-validators.service.ts b/client/src/app/shared/forms/form-validators/user-validators.service.ts index 1fd1cdf68ed..0fbf7fe128a 100644 --- a/client/src/app/shared/forms/form-validators/user-validators.service.ts +++ b/client/src/app/shared/forms/form-validators/user-validators.service.ts @@ -23,15 +23,15 @@ export class UserValidatorsService { this.USER_USERNAME = { VALIDATORS: [ Validators.required, - Validators.minLength(3), - Validators.maxLength(20), - Validators.pattern(/^[a-z0-9._]+$/) + Validators.minLength(1), + Validators.maxLength(50), + Validators.pattern(/^[a-z0-9][a-z0-9-._]*$/) ], MESSAGES: { 'required': this.i18n('Username is required.'), - 'minlength': this.i18n('Username must be at least 3 characters long.'), - 'maxlength': this.i18n('Username cannot be more than 20 characters long.'), - 'pattern': this.i18n('Username should be only lowercase alphanumeric characters.') + 'minlength': this.i18n('Username must be at least 1 character long.'), + 'maxlength': this.i18n('Username cannot be more than 50 characters long.'), + 'pattern': this.i18n('Username should be lowercase alphanumeric; dots, dashes and underscores are allowed.') } } @@ -88,13 +88,13 @@ export class UserValidatorsService { this.USER_DISPLAY_NAME = { VALIDATORS: [ Validators.required, - Validators.minLength(3), - Validators.maxLength(120) + Validators.minLength(1), + Validators.maxLength(50) ], MESSAGES: { 'required': this.i18n('Display name is required.'), - 'minlength': this.i18n('Display name must be at least 3 characters long.'), - 'maxlength': this.i18n('Display name cannot be more than 120 characters long.') + 'minlength': this.i18n('Display name must be at least 1 characters long.'), + 'maxlength': this.i18n('Display name cannot be more than 50 characters long.') } } diff --git a/client/src/app/shared/forms/form-validators/video-channel-validators.service.ts b/client/src/app/shared/forms/form-validators/video-channel-validators.service.ts index 1ce3a0dcace..bf53adf0ad1 100644 --- a/client/src/app/shared/forms/form-validators/video-channel-validators.service.ts +++ b/client/src/app/shared/forms/form-validators/video-channel-validators.service.ts @@ -14,28 +14,28 @@ export class VideoChannelValidatorsService { this.VIDEO_CHANNEL_NAME = { VALIDATORS: [ Validators.required, - Validators.minLength(3), - Validators.maxLength(20), - Validators.pattern(/^[a-z0-9._]+$/) + Validators.minLength(1), + Validators.maxLength(50), + Validators.pattern(/^[a-z0-9][a-z0-9-._]*$/) ], MESSAGES: { 'required': this.i18n('Name is required.'), - 'minlength': this.i18n('Name must be at least 3 characters long.'), - 'maxlength': this.i18n('Name cannot be more than 20 characters long.'), - 'pattern': this.i18n('Name should be only lowercase alphanumeric characters.') + 'minlength': this.i18n('Name must be at least 1 characters long.'), + 'maxlength': this.i18n('Name cannot be more than 50 characters long.'), + 'pattern': this.i18n('Name should be lowercase alphanumeric; dots, dashes and underscores are allowed.') } } this.VIDEO_CHANNEL_DISPLAY_NAME = { VALIDATORS: [ Validators.required, - Validators.minLength(3), - Validators.maxLength(120) + Validators.minLength(1), + Validators.maxLength(50) ], MESSAGES: { 'required': i18n('Display name is required.'), - 'minlength': i18n('Display name must be at least 3 characters long.'), - 'maxlength': i18n('Display name cannot be more than 120 characters long.') + 'minlength': i18n('Display name must be at least 1 characters long.'), + 'maxlength': i18n('Display name cannot be more than 50 characters long.') } } diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index e08fd75cd85..2c5b0af74ee 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -291,9 +291,9 @@ const CONFIG = { const CONSTRAINTS_FIELDS = { USERS: { - NAME: { min: 3, max: 120 }, // Length + NAME: { min: 1, max: 50 }, // Length DESCRIPTION: { min: 3, max: 250 }, // Length - USERNAME: { min: 3, max: 20 }, // Length + USERNAME: { min: 1, max: 50 }, // Length PASSWORD: { min: 6, max: 255 }, // Length VIDEO_QUOTA: { min: -1 }, VIDEO_QUOTA_DAILY: { min: -1 }, @@ -307,7 +307,7 @@ const CONSTRAINTS_FIELDS = { REASON: { min: 2, max: 300 } // Length }, VIDEO_CHANNELS: { - NAME: { min: 3, max: 120 }, // Length + NAME: { min: 1, max: 50 }, // Length DESCRIPTION: { min: 3, max: 500 }, // Length SUPPORT: { min: 3, max: 500 }, // Length URL: { min: 3, max: 2000 } // Length diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index cbfa0c137cd..e0f0965f5e0 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -99,13 +99,13 @@ describe('Test users API validators', function () { } it('Should fail with a too small username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: 'fi' }) + const fields = immutableAssign(baseCorrectParams, { username: '' }) await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) it('Should fail with a too long username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: 'my_super_username_which_is_very_long' }) + const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(11) }) await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) }) @@ -541,13 +541,13 @@ describe('Test users API validators', function () { } it('Should fail with a too small username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: 'ji' }) + const fields = immutableAssign(baseCorrectParams, { username: '' }) await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) }) it('Should fail with a too long username', async function () { - const fields = immutableAssign(baseCorrectParams, { username: 'my_super_username_which_is_very_long' }) + const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(11) }) await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) }) From 286949d9e2f6df7146c1dc7e71f4307401abe1f3 Mon Sep 17 00:00:00 2001 From: McFlat Date: Fri, 19 Oct 2018 07:35:13 -0500 Subject: [PATCH 2/2] change 1 characters to 1 character --- .../shared/forms/form-validators/user-validators.service.ts | 2 +- .../forms/form-validators/video-channel-validators.service.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/src/app/shared/forms/form-validators/user-validators.service.ts b/client/src/app/shared/forms/form-validators/user-validators.service.ts index 1770ab13fcd..66543657a38 100644 --- a/client/src/app/shared/forms/form-validators/user-validators.service.ts +++ b/client/src/app/shared/forms/form-validators/user-validators.service.ts @@ -93,7 +93,7 @@ export class UserValidatorsService { ], MESSAGES: { 'required': this.i18n('Display name is required.'), - 'minlength': this.i18n('Display name must be at least 1 characters long.'), + 'minlength': this.i18n('Display name must be at least 1 character long.'), 'maxlength': this.i18n('Display name cannot be more than 50 characters long.') } } diff --git a/client/src/app/shared/forms/form-validators/video-channel-validators.service.ts b/client/src/app/shared/forms/form-validators/video-channel-validators.service.ts index 807f8be913c..7df4f6adfe0 100644 --- a/client/src/app/shared/forms/form-validators/video-channel-validators.service.ts +++ b/client/src/app/shared/forms/form-validators/video-channel-validators.service.ts @@ -20,7 +20,7 @@ export class VideoChannelValidatorsService { ], MESSAGES: { 'required': this.i18n('Name is required.'), - 'minlength': this.i18n('Name must be at least 1 characters long.'), + 'minlength': this.i18n('Name must be at least 1 character long.'), 'maxlength': this.i18n('Name cannot be more than 50 characters long.'), 'pattern': this.i18n('Name should be lowercase alphanumeric; dots, dashes and underscores are allowed.') } @@ -34,7 +34,7 @@ export class VideoChannelValidatorsService { ], MESSAGES: { 'required': i18n('Display name is required.'), - 'minlength': i18n('Display name must be at least 1 characters long.'), + 'minlength': i18n('Display name must be at least 1 character long.'), 'maxlength': i18n('Display name cannot be more than 50 characters long.') } }