summaryrefslogtreecommitdiffstats
path: root/model/utils_test.go
diff options
context:
space:
mode:
authorHarrison Healey <harrisonmhealey@gmail.com>2018-08-01 15:18:14 -0400
committerGitHub <noreply@github.com>2018-08-01 15:18:14 -0400
commitc34b30a6e7fb707ae12e78a51e5bd776e5ca85ed (patch)
tree54a3a5d715fb0cf337c98a47efc4a75f7b23a791 /model/utils_test.go
parenta8cc646eede863e35eff3017f4472ec6f9ad01a4 (diff)
downloadchat-c34b30a6e7fb707ae12e78a51e5bd776e5ca85ed.tar.gz
chat-c34b30a6e7fb707ae12e78a51e5bd776e5ca85ed.tar.bz2
chat-c34b30a6e7fb707ae12e78a51e5bd776e5ca85ed.zip
MM-11521/MM-11522 Fix being able to create users with invalid emails through API (#9199)
* MM-11522 Fix being able to create users with invalid emails through API * Ensure store tests are using valid emails * Add missing license header * Remove invalid test case * Fix TestUpdateOAuthUserAttrs
Diffstat (limited to 'model/utils_test.go')
-rw-r--r--model/utils_test.go88
1 files changed, 81 insertions, 7 deletions
diff --git a/model/utils_test.go b/model/utils_test.go
index b7f5dc628..9797c7090 100644
--- a/model/utils_test.go
+++ b/model/utils_test.go
@@ -77,13 +77,87 @@ func TestMapJson(t *testing.T) {
}
}
-func TestValidEmail(t *testing.T) {
- if !IsValidEmail("corey+test@hulen.com") {
- t.Error("email should be valid")
- }
-
- if IsValidEmail("@corey+test@hulen.com") {
- t.Error("should be invalid")
+func TestIsValidEmail(t *testing.T) {
+ for _, testCase := range []struct {
+ Input string
+ Expected bool
+ }{
+ {
+ Input: "corey",
+ Expected: false,
+ },
+ {
+ Input: "corey@example.com",
+ Expected: true,
+ },
+ {
+ Input: "corey+test@example.com",
+ Expected: true,
+ },
+ {
+ Input: "@corey+test@example.com",
+ Expected: false,
+ },
+ {
+ Input: "firstname.lastname@example.com",
+ Expected: true,
+ },
+ {
+ Input: "firstname.lastname@subdomain.example.com",
+ Expected: true,
+ },
+ {
+ Input: "123454567@domain.com",
+ Expected: true,
+ },
+ {
+ Input: "email@domain-one.com",
+ Expected: true,
+ },
+ {
+ Input: "email@domain.co.jp",
+ Expected: true,
+ },
+ {
+ Input: "firstname-lastname@domain.com",
+ Expected: true,
+ },
+ {
+ Input: "@domain.com",
+ Expected: false,
+ },
+ {
+ Input: "Billy Bob <billy@example.com>",
+ Expected: false,
+ },
+ {
+ Input: "email.domain.com",
+ Expected: false,
+ },
+ {
+ Input: "email.@domain.com",
+ Expected: false,
+ },
+ {
+ Input: "email@domain@domain.com",
+ Expected: false,
+ },
+ {
+ Input: "(email@domain.com)",
+ Expected: false,
+ },
+ {
+ Input: "email@汤.中国",
+ Expected: true,
+ },
+ {
+ Input: "email1@domain.com, email2@domain.com",
+ Expected: false,
+ },
+ } {
+ t.Run(testCase.Input, func(t *testing.T) {
+ assert.Equal(t, testCase.Expected, IsValidEmail(testCase.Input))
+ })
}
}