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 <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino 2022-04-01 09:47:54 +02:00
parent 55f8171dd1
commit 3521bacc4a
No known key found for this signature in database
GPG key ID: 2F1FB59433D5A8CB
2 changed files with 7 additions and 7 deletions

View file

@ -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)

View file

@ -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 {