Merge pull request #224 from tbrunain/fix/import_user_empty_username_check

fix: Add a check on username in importUser

Thanks for pointing this out!
This commit is contained in:
Stephen Buttolph 2020-06-07 15:27:29 -04:00 committed by GitHub
commit 49730eaac0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -266,6 +266,10 @@ func (ks *Keystore) ImportUser(r *http.Request, args *ImportUserArgs, reply *Imp
ks.log.Verbo("ImportUser called for %s", args.Username)
if args.Username == "" {
return errEmptyUsername
}
if usr, err := ks.getUser(args.Username); err == nil || usr != nil {
return fmt.Errorf("user already exists: %s", args.Username)
}

View File

@ -266,6 +266,17 @@ func TestServiceExportImport(t *testing.T) {
}
}
{
reply := ImportUserReply{}
if err := newKS.ImportUser(nil, &ImportUserArgs{
Username: "",
Password: "strongPassword",
User: exportReply.User,
}, &reply); err == nil {
t.Fatal("Should have errored due to empty username")
}
}
{
reply := ImportUserReply{}
if err := newKS.ImportUser(nil, &ImportUserArgs{