You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2022/07/11 09:03:33 UTC

[servicecomb-service-center] branch master updated: Bug fix: allow blank account/role name (#1311)

This is an automated email from the ASF dual-hosted git repository.

littlecui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-service-center.git


The following commit(s) were added to refs/heads/master by this push:
     new 89ac493e Bug fix: allow blank account/role name (#1311)
89ac493e is described below

commit 89ac493ecf91b24ee200343a7901957176b8ef68
Author: little-cui <su...@qq.com>
AuthorDate: Mon Jul 11 17:03:29 2022 +0800

    Bug fix: allow blank account/role name (#1311)
---
 server/service/validator/rbac_validator.go      |  4 ++--
 server/service/validator/rbac_validator_test.go | 14 ++++++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/server/service/validator/rbac_validator.go b/server/service/validator/rbac_validator.go
index 5db6aef2..425beb4d 100644
--- a/server/service/validator/rbac_validator.go
+++ b/server/service/validator/rbac_validator.go
@@ -30,7 +30,7 @@ var changePWDValidator = &validate.Validator{}
 var accountLoginValidator = &validate.Validator{}
 
 func init() {
-	createAccountValidator.AddRule("Name", &validate.Rule{Max: 64, Regexp: nameRegex})
+	createAccountValidator.AddRule("Name", &validate.Rule{Min: 1, Max: 64, Regexp: nameRegex})
 	createAccountValidator.AddRule("Roles", &validate.Rule{Min: 1, Max: 5, Regexp: nameRegex})
 	createAccountValidator.AddRule("Password", &validate.Rule{Regexp: &validate.PasswordChecker{}})
 	createAccountValidator.AddRule("Status", &validate.Rule{Regexp: accountStatusRegex})
@@ -38,7 +38,7 @@ func init() {
 	updateAccountValidator.AddRule("Roles", createAccountValidator.GetRule("Roles"))
 	updateAccountValidator.AddRule("Status", createAccountValidator.GetRule("Status"))
 
-	createRoleValidator.AddRule("Name", &validate.Rule{Max: 64, Regexp: nameRegex})
+	createRoleValidator.AddRule("Name", &validate.Rule{Min: 1, Max: 64, Regexp: nameRegex})
 
 	changePWDValidator.AddRule("Password", &validate.Rule{Regexp: &validate.PasswordChecker{}})
 	changePWDValidator.AddRule("Name", &validate.Rule{Regexp: nameRegex})
diff --git a/server/service/validator/rbac_validator_test.go b/server/service/validator/rbac_validator_test.go
index 80c4fa93..98fe55ac 100644
--- a/server/service/validator/rbac_validator_test.go
+++ b/server/service/validator/rbac_validator_test.go
@@ -43,6 +43,14 @@ func TestValidateCreateAccount(t *testing.T) {
 			}},
 			wantErr: false,
 		},
+		{name: "given blank account name",
+			args: args{a: &rbac.Account{
+				Name:     "",
+				Password: "Pwd0000_1",
+				Roles:    []string{"admin", "developer"},
+			}},
+			wantErr: true,
+		},
 		{name: "given invalid account name",
 			args: args{a: &rbac.Account{
 				Name:     "tester*",
@@ -129,6 +137,12 @@ func TestValidateCreateRole(t *testing.T) {
 		args    args
 		wantErr bool
 	}{
+		{name: "given blank role name",
+			args: args{a: &rbac.Role{
+				Name: "",
+			}},
+			wantErr: true,
+		},
 		{name: "given invalid role name",
 			args: args{a: &rbac.Role{
 				Name: "tester*a",