mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-04 05:18:25 +00:00 
			
		
		
		
	Skip email domain check when admins edit user emails (#29609)
Follow #29522 Administrators should be able to set a user's email address even if the email address is not in `EMAIL_DOMAIN_ALLOWLIST`
This commit is contained in:
		@@ -359,3 +359,32 @@ func TestAPICreateUser_NotAllowedEmailDomain(t *testing.T) {
 | 
			
		||||
	req = NewRequest(t, "DELETE", "/api/v1/admin/users/allowedUser1").AddTokenAuth(token)
 | 
			
		||||
	MakeRequest(t, req, http.StatusNoContent)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestAPIEditUser_NotAllowedEmailDomain(t *testing.T) {
 | 
			
		||||
	defer tests.PrepareTestEnv(t)()
 | 
			
		||||
 | 
			
		||||
	setting.Service.EmailDomainAllowList = []glob.Glob{glob.MustCompile("example.org")}
 | 
			
		||||
	defer func() {
 | 
			
		||||
		setting.Service.EmailDomainAllowList = []glob.Glob{}
 | 
			
		||||
	}()
 | 
			
		||||
 | 
			
		||||
	adminUsername := "user1"
 | 
			
		||||
	token := getUserToken(t, adminUsername, auth_model.AccessTokenScopeWriteAdmin)
 | 
			
		||||
	urlStr := fmt.Sprintf("/api/v1/admin/users/%s", "user2")
 | 
			
		||||
 | 
			
		||||
	newEmail := "user2@example1.com"
 | 
			
		||||
	req := NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{
 | 
			
		||||
		LoginName: "user2",
 | 
			
		||||
		SourceID:  0,
 | 
			
		||||
		Email:     &newEmail,
 | 
			
		||||
	}).AddTokenAuth(token)
 | 
			
		||||
	MakeRequest(t, req, http.StatusOK)
 | 
			
		||||
 | 
			
		||||
	originalEmail := "user2@example.com"
 | 
			
		||||
	req = NewRequestWithJSON(t, "PATCH", urlStr, api.EditUserOption{
 | 
			
		||||
		LoginName: "user2",
 | 
			
		||||
		SourceID:  0,
 | 
			
		||||
		Email:     &originalEmail,
 | 
			
		||||
	}).AddTokenAuth(token)
 | 
			
		||||
	MakeRequest(t, req, http.StatusOK)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user