aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorZettat123 <zettat123@gmail.com>2024-03-06 00:51:56 +0800
committerGitHub <noreply@github.com>2024-03-05 16:51:56 +0000
commit136dd99e86eea9c8bfe61b972a12b395655171e8 (patch)
tree5987172b3e492eef0f5c3ab26ddae165d37f67dc /tests
parentebff37ae09e99126668cbee5804d45f069a42081 (diff)
downloadgitea-136dd99e86eea9c8bfe61b972a12b395655171e8.tar.gz
gitea-136dd99e86eea9c8bfe61b972a12b395655171e8.zip
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`
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/api_admin_test.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/integration/api_admin_test.go b/tests/integration/api_admin_test.go
index 53bdd11afd..8a330a68e2 100644
--- a/tests/integration/api_admin_test.go
+++ b/tests/integration/api_admin_test.go
@@ -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)
+}