@@ -10,11 +10,13 @@ import (
1010 organization_model "code.gitea.io/gitea/models/organization"
1111 "code.gitea.io/gitea/models/unittest"
1212 user_model "code.gitea.io/gitea/models/user"
13+ "code.gitea.io/gitea/modules/setting"
1314
15+ "github.com/gobwas/glob"
1416 "github.com/stretchr/testify/assert"
1517)
1618
17- func TestAddOrSetPrimaryEmailAddress (t * testing.T ) {
19+ func TestAdminAddOrSetPrimaryEmailAddress (t * testing.T ) {
1820 assert .NoError (t , unittest .PrepareTestDatabase ())
1921
2022 user := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : 27 })
@@ -28,7 +30,7 @@ func TestAddOrSetPrimaryEmailAddress(t *testing.T) {
2830 assert .NotEqual (t , "new-primary@example.com" , primary .Email )
2931 assert .Equal (t , user .Email , primary .Email )
3032
31- assert .NoError (t , AddOrSetPrimaryEmailAddress (db .DefaultContext , user , "new-primary@example.com" ))
33+ assert .NoError (t , AdminAddOrSetPrimaryEmailAddress (db .DefaultContext , user , "new-primary@example.com" ))
3234
3335 primary , err = user_model .GetPrimaryEmailAddressOfUser (db .DefaultContext , user .ID )
3436 assert .NoError (t , err )
@@ -39,7 +41,19 @@ func TestAddOrSetPrimaryEmailAddress(t *testing.T) {
3941 assert .NoError (t , err )
4042 assert .Len (t , emails , 2 )
4143
42- assert .NoError (t , AddOrSetPrimaryEmailAddress (db .DefaultContext , user , "user27@example.com" ))
44+ setting .Service .EmailDomainAllowList = []glob.Glob {glob .MustCompile ("example.org" )}
45+ defer func () {
46+ setting .Service .EmailDomainAllowList = []glob.Glob {}
47+ }()
48+
49+ assert .NoError (t , AdminAddOrSetPrimaryEmailAddress (db .DefaultContext , user , "new-primary2@example2.com" ))
50+
51+ primary , err = user_model .GetPrimaryEmailAddressOfUser (db .DefaultContext , user .ID )
52+ assert .NoError (t , err )
53+ assert .Equal (t , "new-primary2@example2.com" , primary .Email )
54+ assert .Equal (t , user .Email , primary .Email )
55+
56+ assert .NoError (t , AdminAddOrSetPrimaryEmailAddress (db .DefaultContext , user , "user27@example.com" ))
4357
4458 primary , err = user_model .GetPrimaryEmailAddressOfUser (db .DefaultContext , user .ID )
4559 assert .NoError (t , err )
@@ -48,7 +62,7 @@ func TestAddOrSetPrimaryEmailAddress(t *testing.T) {
4862
4963 emails , err = user_model .GetEmailAddresses (db .DefaultContext , user .ID )
5064 assert .NoError (t , err )
51- assert .Len (t , emails , 2 )
65+ assert .Len (t , emails , 3 )
5266}
5367
5468func TestReplacePrimaryEmailAddress (t * testing.T ) {
0 commit comments