Prevent User.Timezone field to overflow DB column capacity (#17220)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
58069ff7dc
Коммит
28df047d92
@@ -1693,6 +1693,16 @@ func TestPatchUser(t *testing.T) {
|
|||||||
user := th.CreateUser()
|
user := th.CreateUser()
|
||||||
th.Client.Login(user.Email, user.Password)
|
th.Client.Login(user.Email, user.Password)
|
||||||
|
|
||||||
|
t.Run("Timezone limit error", func(t *testing.T) {
|
||||||
|
patch := &model.UserPatch{}
|
||||||
|
patch.Timezone = model.StringMap{}
|
||||||
|
patch.Timezone["manualTimezone"] = string(make([]byte, model.USER_TIMEZONE_MAX_RUNES))
|
||||||
|
ruser, resp := th.Client.PatchUser(user.Id, patch)
|
||||||
|
CheckBadRequestStatus(t, resp)
|
||||||
|
require.Equal(t, "model.user.is_valid.timezone_limit.app_error", resp.Error.Id)
|
||||||
|
require.Nil(t, ruser)
|
||||||
|
})
|
||||||
|
|
||||||
patch := &model.UserPatch{}
|
patch := &model.UserPatch{}
|
||||||
patch.Password = model.NewString("testpassword")
|
patch.Password = model.NewString("testpassword")
|
||||||
patch.Nickname = model.NewString("Joram Wilander")
|
patch.Nickname = model.NewString("Joram Wilander")
|
||||||
|
|||||||
@@ -8398,6 +8398,10 @@
|
|||||||
"id": "model.user.is_valid.locale.app_error",
|
"id": "model.user.is_valid.locale.app_error",
|
||||||
"translation": "Invalid locale."
|
"translation": "Invalid locale."
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "model.user.is_valid.marshal.app_error",
|
||||||
|
"translation": "Failed to encode field to JSON"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "model.user.is_valid.nickname.app_error",
|
"id": "model.user.is_valid.nickname.app_error",
|
||||||
"translation": "Invalid nickname."
|
"translation": "Invalid nickname."
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ const (
|
|||||||
USER_NAME_MIN_LENGTH = 1
|
USER_NAME_MIN_LENGTH = 1
|
||||||
USER_PASSWORD_MAX_LENGTH = 72
|
USER_PASSWORD_MAX_LENGTH = 72
|
||||||
USER_LOCALE_MAX_LENGTH = 5
|
USER_LOCALE_MAX_LENGTH = 5
|
||||||
|
USER_TIMEZONE_MAX_RUNES = 256
|
||||||
)
|
)
|
||||||
|
|
||||||
//msgp:tuple User
|
//msgp:tuple User
|
||||||
@@ -312,6 +313,14 @@ func (u *User) IsValid() *AppError {
|
|||||||
return InvalidUserError("locale", u.Id)
|
return InvalidUserError("locale", u.Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(u.Timezone) > 0 {
|
||||||
|
if tzJSON, err := json.Marshal(u.Timezone); err != nil {
|
||||||
|
return NewAppError("User.IsValid", "model.user.is_valid.marshal.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
|
} else if utf8.RuneCount(tzJSON) > USER_TIMEZONE_MAX_RUNES {
|
||||||
|
return InvalidUserError("timezone_limit", u.Id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user