From 3521bacc4a0a5a0e2920ae422d5eb30953295381 Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Fri, 1 Apr 2022 09:47:54 +0200 Subject: [PATCH] web user templates: ensure we can save valid users users with no public key and password are now valid after the recent changes Signed-off-by: Nicola Murino --- httpd/httpd_test.go | 12 ++++++------ httpd/webadmin.go | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/httpd/httpd_test.go b/httpd/httpd_test.go index 391a53b0..e5e1906c 100644 --- a/httpd/httpd_test.go +++ b/httpd/httpd_test.go @@ -15410,9 +15410,9 @@ func TestUserTemplateMock(t *testing.T) { checkResponseCode(t, http.StatusBadRequest, rr) require.Contains(t, rr.Body.String(), "Error validating user") - form.Set("tpl_username", "user1") - form.Set("tpl_password", " ") - form.Set("tpl_public_keys", "") + form.Set("tpl_username", " ") + form.Set("tpl_password", "pwd") + form.Set("tpl_public_keys", testPubKey) b, contentType, _ = getMultipartFormData(form, "", "") req, _ = http.NewRequest(http.MethodPost, webTemplateUser, &b) setJWTCookieForReq(req, token) @@ -15427,9 +15427,9 @@ func TestUserTemplateMock(t *testing.T) { form.Add("tpl_username", "user2") form.Add("tpl_password", "password2") form.Add("tpl_public_keys", testPubKey) - form.Add("tpl_username", "user3") - form.Add("tpl_password", "") - form.Add("tpl_public_keys", "") + form.Add("tpl_username", "") + form.Add("tpl_password", "password3") + form.Add("tpl_public_keys", testPubKey) b, contentType, _ = getMultipartFormData(form, "", "") req, _ = http.NewRequest(http.MethodPost, webTemplateUser, &b) setJWTCookieForReq(req, token) diff --git a/httpd/webadmin.go b/httpd/webadmin.go index ca9f6810..e3d535bc 100644 --- a/httpd/webadmin.go +++ b/httpd/webadmin.go @@ -705,7 +705,7 @@ func getUsersForTemplate(r *http.Request) []userTemplateFields { if len(tplPublicKeys) > idx { publicKey = strings.TrimSpace(tplPublicKeys[idx]) } - if username == "" || (password == "" && publicKey == "") { + if username == "" { continue } if _, ok := users[username]; ok {