fix(auth): 注册唯一性检查识别 Gmail 邮箱别名
合并 #681:注册唯一性检查识别 Gmail 邮箱别名
This commit is contained in:
1 parent
a71e03b131
commit
19841cb9c5
12 files changed
+316
-8
No files matched your search
@@ -0,0 +1,16 @@
|
||||
// Package emailidentity defines mailbox equivalence for uniqueness checks.
|
||||
package emailidentity
|
||||
|
||||
import "strings"
|
||||
|
||||
// Canonical preserves provider-specific local parts except for Gmail aliases.
|
||||
// It is not an account lookup key: existing accounts may share a mailbox.
|
||||
func Canonical(value string) string {
|
||||
value = strings.ToLower(strings.TrimSpace(value))
|
||||
local, domain, ok := strings.Cut(value, "@")
|
||||
if !ok || (domain != "gmail.com" && domain != "googlemail.com") {
|
||||
return value
|
||||
}
|
||||
local, _, _ = strings.Cut(local, "+")
|
||||
return strings.ReplaceAll(local, ".", "") + "@gmail.com"
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package emailidentity
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestCanonicalMailbox(t *testing.T) {
|
||||
for input, want := range map[string]string{
|
||||
" A.B+x@GMAIL.COM ": "ab@gmail.com",
|
||||
"a.b+x@googlemail.com": "ab@gmail.com",
|
||||
"A.B+x@example.com": "a.b+x@example.com",
|
||||
"a.b+x@gmail.example.com": "a.b+x@gmail.example.com",
|
||||
"a.b+x@sub.gmail.com": "a.b+x@sub.gmail.com",
|
||||
"": "",
|
||||
} {
|
||||
if got := Canonical(input); got != want {
|
||||
t.Errorf("Canonical(%q)=%q want %q", input, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user