mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-10-30 22:11:07 +00:00 
			
		
		
		
	The current email restrictions were put in place because of a security issue with sendmail (https://github.com/go-gitea/gitea/pull/17688). Remove this restriction and instead ensure that this security issue cannot happen with sendmail. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7829 Reviewed-by: Ellen Εμιλία Άννα Zscheile <fogti@noreply.codeberg.org> Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: famfo <famfo@famfo.xyz> Co-committed-by: famfo <famfo@famfo.xyz>
		
			
				
	
	
		
			74 lines
		
	
	
	
		
			2.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			74 lines
		
	
	
	
		
			2.6 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`:            ErrEmailInvalid{`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":                    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":                    nil,
 | |
| 		"\"~@ \"@famfo.xyz":              nil,
 | |
| 		"Foo <foo@bar.com>":              ErrEmailInvalid{"Foo <foo@bar.com>"},
 | |
| 		";233@qq.com":                    ErrEmailInvalid{";233@qq.com"},
 | |
| 		string([]byte{0xE2, 0x84, 0xAA}): ErrEmailInvalid{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)
 | |
| }
 |