|
|
|
@ -5,6 +5,7 @@ package integration |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"net/http" |
|
|
|
|
"strings" |
|
|
|
|
"testing" |
|
|
|
|
|
|
|
|
|
auth_model "code.gitea.io/gitea/models/auth" |
|
|
|
@ -98,41 +99,12 @@ func TestRenameReservedUsername(t *testing.T) { |
|
|
|
|
reservedUsernames := []string{ |
|
|
|
|
// ".", "..", ".well-known", // The names are not only reserved but also invalid
|
|
|
|
|
"api", |
|
|
|
|
"assets", |
|
|
|
|
"attachments", |
|
|
|
|
"avatar", |
|
|
|
|
"avatars", |
|
|
|
|
"captcha", |
|
|
|
|
"commits", |
|
|
|
|
"debug", |
|
|
|
|
"error", |
|
|
|
|
"explore", |
|
|
|
|
"favicon.ico", |
|
|
|
|
"ghost", |
|
|
|
|
"issues", |
|
|
|
|
"login", |
|
|
|
|
"manifest.json", |
|
|
|
|
"metrics", |
|
|
|
|
"milestones", |
|
|
|
|
"new", |
|
|
|
|
"notifications", |
|
|
|
|
"org", |
|
|
|
|
"pulls", |
|
|
|
|
"raw", |
|
|
|
|
"repo", |
|
|
|
|
"repo-avatars", |
|
|
|
|
"robots.txt", |
|
|
|
|
"search", |
|
|
|
|
"serviceworker.js", |
|
|
|
|
"ssh_info", |
|
|
|
|
"swagger.v1.json", |
|
|
|
|
"user", |
|
|
|
|
"v2", |
|
|
|
|
"name.keys", |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
session := loginUser(t, "user2") |
|
|
|
|
locale := translation.NewLocale("en-US") |
|
|
|
|
for _, reservedUsername := range reservedUsernames { |
|
|
|
|
t.Logf("Testing username %s", reservedUsername) |
|
|
|
|
req := NewRequestWithValues(t, "POST", "/user/settings", map[string]string{ |
|
|
|
|
"_csrf": GetUserCSRFToken(t, session), |
|
|
|
|
"name": reservedUsername, |
|
|
|
@ -144,11 +116,12 @@ func TestRenameReservedUsername(t *testing.T) { |
|
|
|
|
req = NewRequest(t, "GET", test.RedirectURL(resp)) |
|
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK) |
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body) |
|
|
|
|
assert.Contains(t, |
|
|
|
|
htmlDoc.doc.Find(".ui.negative.message").Text(), |
|
|
|
|
translation.NewLocale("en-US").TrString("user.form.name_reserved", reservedUsername), |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
actualMsg := strings.TrimSpace(htmlDoc.doc.Find(".ui.negative.message").Text()) |
|
|
|
|
expectedMsg := locale.TrString("user.form.name_reserved", reservedUsername) |
|
|
|
|
if strings.Contains(reservedUsername, ".") { |
|
|
|
|
expectedMsg = locale.TrString("user.form.name_pattern_not_allowed", reservedUsername) |
|
|
|
|
} |
|
|
|
|
assert.Equal(t, expectedMsg, actualMsg) |
|
|
|
|
unittest.AssertNotExistsBean(t, &user_model.User{Name: reservedUsername}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|