mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-04-24 16:46:25 +00:00
Some checks failed
/ release (push) Waiting to run
testing / backend-checks (push) Has been skipped
testing / frontend-checks (push) Has been skipped
testing / test-unit (push) Has been skipped
testing / test-e2e (push) Has been skipped
testing / test-mysql (push) Has been skipped
testing / test-pgsql (push) Has been skipped
testing / test-sqlite (push) Has been skipped
testing / test-remote-cacher (redis) (push) Has been skipped
testing / test-remote-cacher (valkey) (push) Has been skipped
testing / test-remote-cacher (garnet) (push) Has been skipped
testing / test-remote-cacher (redict) (push) Has been skipped
testing / security-check (push) Has been skipped
Integration tests for the release process / release-simulation (push) Has been cancelled
Co-authored-by: Renovate Bot <forgejo-renovate-action@forgejo.org> Co-committed-by: Renovate Bot <forgejo-renovate-action@forgejo.org>
73 lines
2.7 KiB
Go
73 lines
2.7 KiB
Go
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
// Copyright 2024 The Forgejo Authors. All rights reserved
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package validation
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestEmailAddressValidate(t *testing.T) {
|
|
kases := map[string]error{
|
|
"abc@gmail.com": nil,
|
|
"132@hotmail.com": nil,
|
|
"1-3-2@test.org": nil,
|
|
"1.3.2@test.org": nil,
|
|
"a_123@test.org.cn": nil,
|
|
`first.last@iana.org`: nil,
|
|
`first!last@iana.org`: nil,
|
|
`first#last@iana.org`: nil,
|
|
`first$last@iana.org`: nil,
|
|
`first%last@iana.org`: nil,
|
|
`first&last@iana.org`: nil,
|
|
`first'last@iana.org`: nil,
|
|
`first*last@iana.org`: nil,
|
|
`first+last@iana.org`: nil,
|
|
`first/last@iana.org`: nil,
|
|
`first=last@iana.org`: nil,
|
|
`first?last@iana.org`: nil,
|
|
`first^last@iana.org`: nil,
|
|
"first`last@iana.org": nil,
|
|
`first{last@iana.org`: nil,
|
|
`first|last@iana.org`: nil,
|
|
`first}last@iana.org`: nil,
|
|
`first~last@iana.org`: nil,
|
|
`first;last@iana.org`: ErrEmailCharIsNotSupported{`first;last@iana.org`},
|
|
".233@qq.com": ErrEmailInvalid{".233@qq.com"},
|
|
"!233@qq.com": nil,
|
|
"#233@qq.com": nil,
|
|
"$233@qq.com": nil,
|
|
"%233@qq.com": nil,
|
|
"&233@qq.com": nil,
|
|
"'233@qq.com": nil,
|
|
"*233@qq.com": nil,
|
|
"+233@qq.com": nil,
|
|
"-233@qq.com": ErrEmailInvalid{"-233@qq.com"},
|
|
"/233@qq.com": nil,
|
|
"=233@qq.com": nil,
|
|
"?233@qq.com": nil,
|
|
"^233@qq.com": nil,
|
|
"_233@qq.com": nil,
|
|
"`233@qq.com": nil,
|
|
"{233@qq.com": nil,
|
|
"|233@qq.com": nil,
|
|
"}233@qq.com": nil,
|
|
"~233@qq.com": nil,
|
|
";233@qq.com": ErrEmailCharIsNotSupported{";233@qq.com"},
|
|
"Foo <foo@bar.com>": ErrEmailCharIsNotSupported{"Foo <foo@bar.com>"},
|
|
string([]byte{0xE2, 0x84, 0xAA}): ErrEmailCharIsNotSupported{string([]byte{0xE2, 0x84, 0xAA})},
|
|
}
|
|
for kase, err := range kases {
|
|
t.Run(kase, func(t *testing.T) {
|
|
assert.Equal(t, err, ValidateEmail(kase))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestEmailDomainAllowList(t *testing.T) {
|
|
res := IsEmailDomainAllowed("someuser@localhost.localdomain")
|
|
assert.True(t, res)
|
|
}
|