|
|
@ -5,6 +5,7 @@ package integration |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
|
|
|
|
"strings" |
|
|
|
"testing" |
|
|
|
"testing" |
|
|
|
|
|
|
|
|
|
|
|
auth_model "code.gitea.io/gitea/models/auth" |
|
|
|
auth_model "code.gitea.io/gitea/models/auth" |
|
|
@ -98,41 +99,12 @@ func TestRenameReservedUsername(t *testing.T) { |
|
|
|
reservedUsernames := []string{ |
|
|
|
reservedUsernames := []string{ |
|
|
|
// ".", "..", ".well-known", // The names are not only reserved but also invalid
|
|
|
|
// ".", "..", ".well-known", // The names are not only reserved but also invalid
|
|
|
|
"api", |
|
|
|
"api", |
|
|
|
"assets", |
|
|
|
"name.keys", |
|
|
|
"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", |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
session := loginUser(t, "user2") |
|
|
|
session := loginUser(t, "user2") |
|
|
|
|
|
|
|
locale := translation.NewLocale("en-US") |
|
|
|
for _, reservedUsername := range reservedUsernames { |
|
|
|
for _, reservedUsername := range reservedUsernames { |
|
|
|
t.Logf("Testing username %s", reservedUsername) |
|
|
|
|
|
|
|
req := NewRequestWithValues(t, "POST", "/user/settings", map[string]string{ |
|
|
|
req := NewRequestWithValues(t, "POST", "/user/settings", map[string]string{ |
|
|
|
"_csrf": GetUserCSRFToken(t, session), |
|
|
|
"_csrf": GetUserCSRFToken(t, session), |
|
|
|
"name": reservedUsername, |
|
|
|
"name": reservedUsername, |
|
|
@ -144,11 +116,12 @@ func TestRenameReservedUsername(t *testing.T) { |
|
|
|
req = NewRequest(t, "GET", test.RedirectURL(resp)) |
|
|
|
req = NewRequest(t, "GET", test.RedirectURL(resp)) |
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK) |
|
|
|
resp = session.MakeRequest(t, req, http.StatusOK) |
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body) |
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body) |
|
|
|
assert.Contains(t, |
|
|
|
actualMsg := strings.TrimSpace(htmlDoc.doc.Find(".ui.negative.message").Text()) |
|
|
|
htmlDoc.doc.Find(".ui.negative.message").Text(), |
|
|
|
expectedMsg := locale.TrString("user.form.name_reserved", reservedUsername) |
|
|
|
translation.NewLocale("en-US").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}) |
|
|
|
unittest.AssertNotExistsBean(t, &user_model.User{Name: reservedUsername}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|