diff --git a/integration/policy_test.go b/integration/policy_test.go index 7c77e3ac1..0cbb2d5cd 100644 --- a/integration/policy_test.go +++ b/integration/policy_test.go @@ -153,6 +153,31 @@ func Test_AddPolicyAPI(t *testing.T) { expectedStatus: 500, expectedError: nil, }, + { + name: "Create Policy - Space in Name", + args: args{ + api: "/policies", + name: "space test", + policy: swag.String(` + { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "s3:GetBucketLocation", + "s3:GetObject" + ], + "Resource": [ + "arn:aws:s3:::*" + ] + } + ] +}`), + }, + expectedStatus: 400, + expectedError: nil, + }, } for _, tt := range tests { diff --git a/portal-ui/src/screens/Console/Policies/AddPolicyScreen.tsx b/portal-ui/src/screens/Console/Policies/AddPolicyScreen.tsx index 1517bcd85..67c634615 100644 --- a/portal-ui/src/screens/Console/Policies/AddPolicyScreen.tsx +++ b/portal-ui/src/screens/Console/Policies/AddPolicyScreen.tsx @@ -99,12 +99,12 @@ const AddPolicyScreen = ({ }; const validatePolicyname = (policyName: string) => { - if (policyName.indexOf(' ') !== -1){ - return "Policy name cannot contain spaces" - } else return "" - } + if (policyName.indexOf(" ") !== -1) { + return "Policy name cannot contain spaces"; + } else return ""; + }; - const validSave = (policyName.trim() !== "" ) && (policyName.indexOf(' ') === -1); + const validSave = policyName.trim() !== "" && policyName.indexOf(" ") === -1; return ( diff --git a/restapi/errors.go b/restapi/errors.go index bf99f2ec3..2b8639370 100644 --- a/restapi/errors.go +++ b/restapi/errors.go @@ -118,6 +118,10 @@ func ErrorWithContext(ctx context.Context, err ...interface{}) *models.Error { errorCode = 400 errorMessage = ErrPolicyBodyNotInRequest.Error() } + if errors.Is(err1, ErrPolicyNameContainsSpace) { + errorCode = 400 + errorMessage = ErrPolicyNameContainsSpace.Error() + } // console invalid session errors if errors.Is(err1, ErrInvalidSession) { errorCode = 401