forked from forgejo/forgejo
Allow blocking some email domains from registering an account (#14667)
Gitea allows to whitelist email domains so that only email addresses from certain domains are allowed to register an account, but does not currently allows to do the opposite: blacklisting email domains so that addresses from certain domains are *forbidden* to register an account. The idea has been briefly mentioned in the discussion about issue #6350, but never implemented. This PR does that. The rationale is that, in my experience of running a Gitea instance, *a single email domain* is responsible for *most* of the spam accounts, and for *all* of the spam accounts that manage to get past the email confirmation step. So on top of the other spam mitigation measures already available (email confirmation, CAPTCHA, etc.), having the option to block a particularly annoying domain would be helpful. close #13628
This commit is contained in:
parent
d475d53c41
commit
fc4a8c2980
7 changed files with 61 additions and 22 deletions
|
@ -12,17 +12,17 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRegisterForm_IsDomainWhiteList_Empty(t *testing.T) {
|
||||
func TestRegisterForm_IsDomainAllowed_Empty(t *testing.T) {
|
||||
_ = setting.Service
|
||||
|
||||
setting.Service.EmailDomainWhitelist = []string{}
|
||||
|
||||
form := RegisterForm{}
|
||||
|
||||
assert.True(t, form.IsEmailDomainWhitelisted())
|
||||
assert.True(t, form.IsEmailDomainAllowed())
|
||||
}
|
||||
|
||||
func TestRegisterForm_IsDomainWhiteList_InvalidEmail(t *testing.T) {
|
||||
func TestRegisterForm_IsDomainAllowed_InvalidEmail(t *testing.T) {
|
||||
_ = setting.Service
|
||||
|
||||
setting.Service.EmailDomainWhitelist = []string{"gitea.io"}
|
||||
|
@ -37,11 +37,11 @@ func TestRegisterForm_IsDomainWhiteList_InvalidEmail(t *testing.T) {
|
|||
for _, v := range tt {
|
||||
form := RegisterForm{Email: v.email}
|
||||
|
||||
assert.False(t, form.IsEmailDomainWhitelisted())
|
||||
assert.False(t, form.IsEmailDomainAllowed())
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegisterForm_IsDomainWhiteList_ValidEmail(t *testing.T) {
|
||||
func TestRegisterForm_IsDomainAllowed_WhitelistedEmail(t *testing.T) {
|
||||
_ = setting.Service
|
||||
|
||||
setting.Service.EmailDomainWhitelist = []string{"gitea.io"}
|
||||
|
@ -59,6 +59,28 @@ func TestRegisterForm_IsDomainWhiteList_ValidEmail(t *testing.T) {
|
|||
for _, v := range tt {
|
||||
form := RegisterForm{Email: v.email}
|
||||
|
||||
assert.Equal(t, v.valid, form.IsEmailDomainWhitelisted())
|
||||
assert.Equal(t, v.valid, form.IsEmailDomainAllowed())
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegisterForm_IsDomainAllowed_BlocklistedEmail(t *testing.T) {
|
||||
_ = setting.Service
|
||||
|
||||
setting.Service.EmailDomainWhitelist = []string{}
|
||||
setting.Service.EmailDomainBlocklist = []string{"gitea.io"}
|
||||
|
||||
tt := []struct {
|
||||
email string
|
||||
valid bool
|
||||
}{
|
||||
{"security@gitea.io", false},
|
||||
{"security@gitea.example", true},
|
||||
{"hdudhdd", true},
|
||||
}
|
||||
|
||||
for _, v := range tt {
|
||||
form := RegisterForm{Email: v.email}
|
||||
|
||||
assert.Equal(t, v.valid, form.IsEmailDomainAllowed())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue