Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: user name cannot be empty #23933

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions tenant/storage_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ func (s *Store) CreateUser(ctx context.Context, tx kv.Tx, u *influxdb.User) erro
u.ID = s.IDGen.ID()
}

if u.Name == "" {
return ErrNameisEmpty
}

encodedID, err := u.ID.Encode()
if err != nil {
return InvalidUserIDError(err)
Expand Down
34 changes: 34 additions & 0 deletions testing/user_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,40 @@ func CreateUser(
},
},
},
{
name: "name cannot be empty",
fields: UserFields{
IDGenerator: &mock.IDGenerator{
IDFn: func() platform.ID {
return MustIDBase16(userOneID)
},
},
Users: []*influxdb.User{
{
ID: MustIDBase16(userOneID),
Name: "user1",
Status: influxdb.Active,
},
},
},
args: args{
user: &influxdb.User{},
},
wants: wants{
users: []*influxdb.User{
{
ID: MustIDBase16(userOneID),
Name: "user1",
Status: influxdb.Active,
},
},
err: &errors.Error{
Code: errors.EInvalid,
Op: influxdb.OpCreateUser,
Msg: "name is empty",
},
},
},
}

for _, tt := range tests {
Expand Down