mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Prevent User.Timezone field to overflow DB column capacity (#17220)
This commit is contained in:
@@ -1693,6 +1693,16 @@ func TestPatchUser(t *testing.T) {
|
||||
user := th.CreateUser()
|
||||
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.Password = model.NewString("testpassword")
|
||||
patch.Nickname = model.NewString("Joram Wilander")
|
||||
|
||||
@@ -8398,6 +8398,10 @@
|
||||
"id": "model.user.is_valid.locale.app_error",
|
||||
"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",
|
||||
"translation": "Invalid nickname."
|
||||
|
||||
@@ -56,6 +56,7 @@ const (
|
||||
USER_NAME_MIN_LENGTH = 1
|
||||
USER_PASSWORD_MAX_LENGTH = 72
|
||||
USER_LOCALE_MAX_LENGTH = 5
|
||||
USER_TIMEZONE_MAX_RUNES = 256
|
||||
)
|
||||
|
||||
//msgp:tuple User
|
||||
@@ -312,6 +313,14 @@ func (u *User) IsValid() *AppError {
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user