From 4d7067c28e749d396e74c2471f102d85b40651cc Mon Sep 17 00:00:00 2001 From: tbrunain Date: Sun, 7 Jun 2020 11:01:25 +0200 Subject: [PATCH 1/2] fix: Add a check on username in importUser --- api/keystore/service.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/api/keystore/service.go b/api/keystore/service.go index 5575083..16aca06 100644 --- a/api/keystore/service.go +++ b/api/keystore/service.go @@ -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) } From fca752f3c868b85950e96374faddf90894ac4955 Mon Sep 17 00:00:00 2001 From: tbrunain Date: Sun, 7 Jun 2020 11:09:42 +0200 Subject: [PATCH 2/2] fix: Add test for empty username case --- api/keystore/service_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/api/keystore/service_test.go b/api/keystore/service_test.go index b4c805d..9ec5cfa 100644 --- a/api/keystore/service_test.go +++ b/api/keystore/service_test.go @@ -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{