-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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`.
- Loading branch information
Showing
5 changed files
with
93 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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": "[email protected]", | ||
"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) | ||
} |