Integration test for PolicyNameContainsSpace (#1940)

This commit is contained in:
jinapurapu
2022-05-02 15:35:01 -07:00
committed by GitHub
parent 34adc5451d
commit 427b9b4892
3 changed files with 34 additions and 5 deletions

View File

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

View File

@@ -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 (
<Fragment>

View File

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