Integration test for PolicyNameContainsSpace (#1940)
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user