diff options
author | Zettat123 <zettat123@gmail.com> | 2024-03-05 13:55:47 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-05 05:55:47 +0000 |
commit | 4fd9c56ed09b31e2f6164a5f534a31c6624d0478 (patch) | |
tree | b567b91deed03bb221498fc08270a5d456dae780 /tests | |
parent | 7e8c1c5ba18e1ac8861f429b825163b8210fd178 (diff) | |
download | gitea-4fd9c56ed09b31e2f6164a5f534a31c6624d0478.tar.gz gitea-4fd9c56ed09b31e2f6164a5f534a31c6624d0478.zip |
Skip email domain check when admin users adds user manually (#29522)
Fix #27457
Administrators should be able to manually create any user even if the
user's email address is not in `EMAIL_DOMAIN_ALLOWLIST`.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/api_admin_test.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/integration/api_admin_test.go b/tests/integration/api_admin_test.go index 0748a75ba4..53bdd11afd 100644 --- a/tests/integration/api_admin_test.go +++ b/tests/integration/api_admin_test.go @@ -14,9 +14,11 @@ import ( "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/json" + "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/tests" + "github.com/gobwas/glob" "github.com/stretchr/testify/assert" ) @@ -333,3 +335,27 @@ func TestAPICron(t *testing.T) { } }) } + +func TestAPICreateUser_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) + + req := NewRequestWithValues(t, "POST", "/api/v1/admin/users", map[string]string{ + "email": "allowedUser1@example1.org", + "login_name": "allowedUser1", + "username": "allowedUser1", + "password": "allowedUser1_pass", + "must_change_password": "true", + }).AddTokenAuth(token) + MakeRequest(t, req, http.StatusCreated) + + req = NewRequest(t, "DELETE", "/api/v1/admin/users/allowedUser1").AddTokenAuth(token) + MakeRequest(t, req, http.StatusNoContent) +} |