MF - 1590 - Fix fetching list of users with a zero limit (#1594)

* Add max and min limit size

Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com>

* Format

Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com>

* Format

Signed-off-by: 0x6f736f646f <blackd0t@protonmail.com>

Co-authored-by: Dušan Borovčanin <dusan.borovcanin@mainflux.com>
This commit is contained in:
b1ackd0t 2022-05-09 23:23:19 +03:00 committed by GitHub
parent c8f841f8f3
commit d30e6bad3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -27,6 +27,9 @@ var (
// ErrNameSize indicates that name size exceeds the max.
ErrNameSize = errors.New("invalid name size")
// ErrEmailSize indicates that email size exceeds the max.
ErrEmailSize = errors.New("invalid email size")
// ErrLimitSize indicates that an invalid limit.
ErrLimitSize = errors.New("invalid limit size")

View File

@ -8,6 +8,11 @@ import (
"github.com/mainflux/mainflux/users"
)
const (
maxLimitSize = 100
maxEmailSize = 1024
)
type userReq struct {
user users.User
}
@ -49,6 +54,15 @@ func (req listUsersReq) validate() error {
if req.token == "" {
return apiutil.ErrBearerToken
}
if req.limit > maxLimitSize || req.limit < 1 {
return apiutil.ErrLimitSize
}
if len(req.email) > maxEmailSize {
return apiutil.ErrEmailSize
}
return nil
}