satellite/console: fixed small email validation issues

Moved invalid email testing to separate test.
Made all the emails used to have .test domain.
Added links to regex resources.

Change-Id: I26920ba7360064528256a6aeaea947bbe56ef618
This commit is contained in:
Vitalii 2022-03-30 17:23:13 +03:00 committed by Ivan Fraixedes
parent e93bbf693d
commit 9b695525c6
4 changed files with 54 additions and 46 deletions

View File

@ -186,7 +186,7 @@ func (a *Auth) Register(w http.ResponseWriter, r *http.Request) {
// trim leading and trailing spaces of email address. // trim leading and trailing spaces of email address.
registerData.Email = strings.TrimSpace(registerData.Email) registerData.Email = strings.TrimSpace(registerData.Email)
isValidEmail := validateEmail(registerData.Email) isValidEmail := ValidateEmail(registerData.Email)
if !isValidEmail { if !isValidEmail {
a.serveJSONError(w, console.ErrValidation.Wrap(errs.New("Invalid email."))) a.serveJSONError(w, console.ErrValidation.Wrap(errs.New("Invalid email.")))
return return
@ -340,8 +340,8 @@ func (a *Auth) Register(w http.ResponseWriter, r *http.Request) {
} }
} }
// validateEmail validates email to have correct form and syntax. // ValidateEmail validates email to have correct form and syntax.
func validateEmail(email string) bool { func ValidateEmail(email string) bool {
// This regular expression was built according to RFC 5322 and then extended to include international characters. // This regular expression was built according to RFC 5322 and then extended to include international characters.
re := regexp.MustCompile(`^(?:[a-z0-9\p{L}!#$%&'*+/=?^_{|}~\x60-]+(?:\.[a-z0-9\p{L}!#$%&'*+/=?^_{|}~\x60-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9\p{L}](?:[a-z0-9\p{L}-]*[a-z0-9\p{L}])?\.)+[a-z0-9\p{L}](?:[a-z\p{L}]*[a-z\p{L}])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9\p{L}-]*[a-z0-9\p{L}]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$`) re := regexp.MustCompile(`^(?:[a-z0-9\p{L}!#$%&'*+/=?^_{|}~\x60-]+(?:\.[a-z0-9\p{L}!#$%&'*+/=?^_{|}~\x60-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9\p{L}](?:[a-z0-9\p{L}-]*[a-z0-9\p{L}])?\.)+[a-z0-9\p{L}](?:[a-z\p{L}]*[a-z\p{L}])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9\p{L}-]*[a-z0-9\p{L}]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$`)
match := re.MatchString(email) match := re.MatchString(email)

View File

@ -72,7 +72,7 @@ func TestAuth_Register(t *testing.T) {
}{ }{
FullName: "testuser" + strconv.Itoa(i), FullName: "testuser" + strconv.Itoa(i),
ShortName: "test", ShortName: "test",
Email: "user@test" + strconv.Itoa(i) + ".com", Email: "user@test" + strconv.Itoa(i) + ".test",
Partner: test.Partner, Partner: test.Partner,
Password: "abc123", Password: "abc123",
IsProfessional: true, IsProfessional: true,
@ -798,3 +798,41 @@ func TestAuth_Register_NameSpecialChars(t *testing.T) {
require.Equal(t, filteredName, user.ShortName) require.Equal(t, filteredName, user.ShortName)
}) })
} }
func TestEmailValidation(t *testing.T) {
invalidEmailAddresses := []string{
"test@t@t.test",
"test",
"test@!t.test",
"test@#test.test",
"test@$t.test",
"t%t.test",
"test@^test.test",
"test@&test.test",
"test@*test.test",
"test@(test.test",
"test@)test.test",
"test@=test.test",
"test@[test.test",
"test@]test.test",
"test@{test.test",
"test@}test.test",
"test@/test.test",
"test@\\test.test",
"test@|test.test",
"test@:test.test",
"test@;test.test",
"test@,test.test",
"test@\"test.test",
"test@'test.test",
"test@<test.test",
"test@>test.test",
"test@_test.test",
"test@?test.test",
}
for _, e := range invalidEmailAddresses {
result := consoleapi.ValidateEmail(e)
require.False(t, result)
}
}

View File

@ -67,47 +67,15 @@ func TestSignup_Content(t *testing.T) {
page.MustElement("[aria-roledescription=password] input").MustInput(password) page.MustElement("[aria-roledescription=password] input").MustInput(password)
page.MustElement("[aria-roledescription=retype-password] input").MustInput(password) page.MustElement("[aria-roledescription=retype-password] input").MustInput(password)
page.MustElement(".checkmark").MustClick() page.MustElement(".checkmark").MustClick()
invalidEmailAddress := "t@t@t.test"
page.MustElement("[aria-roledescription=email] input").MustInput(invalidEmailAddress)
page.Keyboard.MustPress(input.Enter)
waitVueTick(page)
invalidEmailAddresses := []string{ invalidEmailMessage := page.MustElement("[aria-roledescription=email] [aria-roledescription=error-text]").MustText()
"t@t@t.t", require.Contains(t, invalidEmailMessage, "Invalid Email")
"test",
"t@!t.t1",
"t@#t.t",
"t@$t.t",
"t%t.t",
"t@^t.t",
"t@&t.t",
"t@*t.t",
"t@(t.t",
"t@)t.t",
"t@=t.t",
"t@[t.t",
"t@]t.t",
"t@{t.t",
"t@}t.t",
"t@/t.t",
"t@\\t.t",
"t@|t.t",
"t@:t.t",
"t@;t.t",
"t@,t.t",
"t@\"t.t",
"t@'t.t",
"t@<t.t",
"t@>t.t",
"t@_t.t",
"t@?t.t",
}
for _, e := range invalidEmailAddresses {
page.MustElement("[aria-roledescription=email] input").MustInput(e)
page.Keyboard.MustPress(input.Enter)
waitVueTick(page)
invalidEmailMessage := page.MustElement("[aria-roledescription=email] [aria-roledescription=error-text]").MustText() page.MustElement("[aria-roledescription=email] input").MustSelectAllText().MustInput("")
require.Contains(t, invalidEmailMessage, "Invalid Email")
page.MustElement("[aria-roledescription=email] input").MustSelectAllText().MustInput("")
}
// User signup with no email or password // User signup with no email or password
page.MustElement("[aria-roledescription=password] input").MustSelectAllText().MustInput("") page.MustElement("[aria-roledescription=password] input").MustSelectAllText().MustInput("")
@ -121,8 +89,8 @@ func TestSignup_Content(t *testing.T) {
require.Contains(t, invalidPasswordMessage, "Invalid Password") require.Contains(t, invalidPasswordMessage, "Invalid Password")
validEmailAddresses := []string{ validEmailAddresses := []string{
"тест@тест.тест ", "тест@тест.test ",
" अजअज@अज.अज", " अजअज@अज.test",
" test@email.test ", " test@email.test ",
} }
for i, e := range validEmailAddresses { for i, e := range validEmailAddresses {

View File

@ -552,7 +552,9 @@ export default class RegisterArea extends Vue {
*/ */
private isEmailValid(): boolean { private isEmailValid(): boolean {
// This regular expression fulfills our needs to validate international emails. // This regular expression fulfills our needs to validate international emails.
// It was built according to RFC 5322 and then extended to include international characters. // It was built according to RFC 5322 and then extended to include international characters using these resources
// https://emailregex.com/
// https://awik.io/international-email-address-validation-javascript/
// eslint-disable-next-line no-misleading-character-class // eslint-disable-next-line no-misleading-character-class
const regex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9\u0080-\u00FF\u0100-\u017F\u0180-\u024F\u0250-\u02AF\u0300-\u036F\u0370-\u03FF\u0400-\u04FF\u0500-\u052F\u0530-\u058F\u0590-\u05FF\u0600-\u06FF\u0700-\u074F\u0750-\u077F\u0780-\u07BF\u07C0-\u07FF\u0900-\u097F\u0980-\u09FF\u0A00-\u0A7F\u0A80-\u0AFF\u0B00-\u0B7F\u0B80-\u0BFF\u0C00-\u0C7F\u0C80-\u0CFF\u0D00-\u0D7F\u0D80-\u0DFF\u0E00-\u0E7F\u0E80-\u0EFF\u0F00-\u0FFF\u1000-\u109F\u10A0-\u10FF\u1100-\u11FF\u1200-\u137F\u1380-\u139F\u13A0-\u13FF\u1400-\u167F\u1680-\u169F\u16A0-\u16FF\u1700-\u171F\u1720-\u173F\u1740-\u175F\u1760-\u177F\u1780-\u17FF\u1800-\u18AF\u1900-\u194F\u1950-\u197F\u1980-\u19DF\u19E0-\u19FF\u1A00-\u1A1F\u1B00-\u1B7F\u1D00-\u1D7F\u1D80-\u1DBF\u1DC0-\u1DFF\u1E00-\u1EFF\u1F00-\u1FFF\u20D0-\u20FF\u2100-\u214F\u2C00-\u2C5F\u2C60-\u2C7F\u2C80-\u2CFF\u2D00-\u2D2F\u2D30-\u2D7F\u2D80-\u2DDF\u2F00-\u2FDF\u2FF0-\u2FFF\u3040-\u309F\u30A0-\u30FF\u3100-\u312F\u3130-\u318F\u3190-\u319F\u31C0-\u31EF\u31F0-\u31FF\u3200-\u32FF\u3300-\u33FF\u3400-\u4DBF\u4DC0-\u4DFF\u4E00-\u9FFF\uA000-\uA48F\uA490-\uA4CF\uA700-\uA71F\uA800-\uA82F\uA840-\uA87F\uAC00-\uD7AF\uF900-\uFAFF]+\.)+[a-zA-Z\u0080-\u00FF\u0100-\u017F\u0180-\u024F\u0250-\u02AF\u0300-\u036F\u0370-\u03FF\u0400-\u04FF\u0500-\u052F\u0530-\u058F\u0590-\u05FF\u0600-\u06FF\u0700-\u074F\u0750-\u077F\u0780-\u07BF\u07C0-\u07FF\u0900-\u097F\u0980-\u09FF\u0A00-\u0A7F\u0A80-\u0AFF\u0B00-\u0B7F\u0B80-\u0BFF\u0C00-\u0C7F\u0C80-\u0CFF\u0D00-\u0D7F\u0D80-\u0DFF\u0E00-\u0E7F\u0E80-\u0EFF\u0F00-\u0FFF\u1000-\u109F\u10A0-\u10FF\u1100-\u11FF\u1200-\u137F\u1380-\u139F\u13A0-\u13FF\u1400-\u167F\u1680-\u169F\u16A0-\u16FF\u1700-\u171F\u1720-\u173F\u1740-\u175F\u1760-\u177F\u1780-\u17FF\u1800-\u18AF\u1900-\u194F\u1950-\u197F\u1980-\u19DF\u19E0-\u19FF\u1A00-\u1A1F\u1B00-\u1B7F\u1D00-\u1D7F\u1D80-\u1DBF\u1DC0-\u1DFF\u1E00-\u1EFF\u1F00-\u1FFF\u20D0-\u20FF\u2100-\u214F\u2C00-\u2C5F\u2C60-\u2C7F\u2C80-\u2CFF\u2D00-\u2D2F\u2D30-\u2D7F\u2D80-\u2DDF\u2F00-\u2FDF\u2FF0-\u2FFF\u3040-\u309F\u30A0-\u30FF\u3100-\u312F\u3130-\u318F\u3190-\u319F\u31C0-\u31EF\u31F0-\u31FF\u3200-\u32FF\u3300-\u33FF\u3400-\u4DBF\u4DC0-\u4DFF\u4E00-\u9FFF\uA000-\uA48F\uA490-\uA4CF\uA700-\uA71F\uA800-\uA82F\uA840-\uA87F\uAC00-\uD7AF\uF900-\uFAFF]{2,}))$/; const regex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9\u0080-\u00FF\u0100-\u017F\u0180-\u024F\u0250-\u02AF\u0300-\u036F\u0370-\u03FF\u0400-\u04FF\u0500-\u052F\u0530-\u058F\u0590-\u05FF\u0600-\u06FF\u0700-\u074F\u0750-\u077F\u0780-\u07BF\u07C0-\u07FF\u0900-\u097F\u0980-\u09FF\u0A00-\u0A7F\u0A80-\u0AFF\u0B00-\u0B7F\u0B80-\u0BFF\u0C00-\u0C7F\u0C80-\u0CFF\u0D00-\u0D7F\u0D80-\u0DFF\u0E00-\u0E7F\u0E80-\u0EFF\u0F00-\u0FFF\u1000-\u109F\u10A0-\u10FF\u1100-\u11FF\u1200-\u137F\u1380-\u139F\u13A0-\u13FF\u1400-\u167F\u1680-\u169F\u16A0-\u16FF\u1700-\u171F\u1720-\u173F\u1740-\u175F\u1760-\u177F\u1780-\u17FF\u1800-\u18AF\u1900-\u194F\u1950-\u197F\u1980-\u19DF\u19E0-\u19FF\u1A00-\u1A1F\u1B00-\u1B7F\u1D00-\u1D7F\u1D80-\u1DBF\u1DC0-\u1DFF\u1E00-\u1EFF\u1F00-\u1FFF\u20D0-\u20FF\u2100-\u214F\u2C00-\u2C5F\u2C60-\u2C7F\u2C80-\u2CFF\u2D00-\u2D2F\u2D30-\u2D7F\u2D80-\u2DDF\u2F00-\u2FDF\u2FF0-\u2FFF\u3040-\u309F\u30A0-\u30FF\u3100-\u312F\u3130-\u318F\u3190-\u319F\u31C0-\u31EF\u31F0-\u31FF\u3200-\u32FF\u3300-\u33FF\u3400-\u4DBF\u4DC0-\u4DFF\u4E00-\u9FFF\uA000-\uA48F\uA490-\uA4CF\uA700-\uA71F\uA800-\uA82F\uA840-\uA87F\uAC00-\uD7AF\uF900-\uFAFF]+\.)+[a-zA-Z\u0080-\u00FF\u0100-\u017F\u0180-\u024F\u0250-\u02AF\u0300-\u036F\u0370-\u03FF\u0400-\u04FF\u0500-\u052F\u0530-\u058F\u0590-\u05FF\u0600-\u06FF\u0700-\u074F\u0750-\u077F\u0780-\u07BF\u07C0-\u07FF\u0900-\u097F\u0980-\u09FF\u0A00-\u0A7F\u0A80-\u0AFF\u0B00-\u0B7F\u0B80-\u0BFF\u0C00-\u0C7F\u0C80-\u0CFF\u0D00-\u0D7F\u0D80-\u0DFF\u0E00-\u0E7F\u0E80-\u0EFF\u0F00-\u0FFF\u1000-\u109F\u10A0-\u10FF\u1100-\u11FF\u1200-\u137F\u1380-\u139F\u13A0-\u13FF\u1400-\u167F\u1680-\u169F\u16A0-\u16FF\u1700-\u171F\u1720-\u173F\u1740-\u175F\u1760-\u177F\u1780-\u17FF\u1800-\u18AF\u1900-\u194F\u1950-\u197F\u1980-\u19DF\u19E0-\u19FF\u1A00-\u1A1F\u1B00-\u1B7F\u1D00-\u1D7F\u1D80-\u1DBF\u1DC0-\u1DFF\u1E00-\u1EFF\u1F00-\u1FFF\u20D0-\u20FF\u2100-\u214F\u2C00-\u2C5F\u2C60-\u2C7F\u2C80-\u2CFF\u2D00-\u2D2F\u2D30-\u2D7F\u2D80-\u2DDF\u2F00-\u2FDF\u2FF0-\u2FFF\u3040-\u309F\u30A0-\u30FF\u3100-\u312F\u3130-\u318F\u3190-\u319F\u31C0-\u31EF\u31F0-\u31FF\u3200-\u32FF\u3300-\u33FF\u3400-\u4DBF\u4DC0-\u4DFF\u4E00-\u9FFF\uA000-\uA48F\uA490-\uA4CF\uA700-\uA71F\uA800-\uA82F\uA840-\uA87F\uAC00-\uD7AF\uF900-\uFAFF]{2,}))$/;
return regex.test(this.user.email); return regex.test(this.user.email);