Skip to content

Commit 427b9b4

Browse files
authored
Integration test for PolicyNameContainsSpace (#1940)
1 parent 34adc54 commit 427b9b4

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

integration/policy_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,31 @@ func Test_AddPolicyAPI(t *testing.T) {
153153
expectedStatus: 500,
154154
expectedError: nil,
155155
},
156+
{
157+
name: "Create Policy - Space in Name",
158+
args: args{
159+
api: "/policies",
160+
name: "space test",
161+
policy: swag.String(`
162+
{
163+
"Version": "2012-10-17",
164+
"Statement": [
165+
{
166+
"Effect": "Allow",
167+
"Action": [
168+
"s3:GetBucketLocation",
169+
"s3:GetObject"
170+
],
171+
"Resource": [
172+
"arn:aws:s3:::*"
173+
]
174+
}
175+
]
176+
}`),
177+
},
178+
expectedStatus: 400,
179+
expectedError: nil,
180+
},
156181
}
157182

158183
for _, tt := range tests {

portal-ui/src/screens/Console/Policies/AddPolicyScreen.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ const AddPolicyScreen = ({
9999
};
100100

101101
const validatePolicyname = (policyName: string) => {
102-
if (policyName.indexOf(' ') !== -1){
103-
return "Policy name cannot contain spaces"
104-
} else return ""
105-
}
102+
if (policyName.indexOf(" ") !== -1) {
103+
return "Policy name cannot contain spaces";
104+
} else return "";
105+
};
106106

107-
const validSave = (policyName.trim() !== "" ) && (policyName.indexOf(' ') === -1);
107+
const validSave = policyName.trim() !== "" && policyName.indexOf(" ") === -1;
108108

109109
return (
110110
<Fragment>

restapi/errors.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ func ErrorWithContext(ctx context.Context, err ...interface{}) *models.Error {
118118
errorCode = 400
119119
errorMessage = ErrPolicyBodyNotInRequest.Error()
120120
}
121+
if errors.Is(err1, ErrPolicyNameContainsSpace) {
122+
errorCode = 400
123+
errorMessage = ErrPolicyNameContainsSpace.Error()
124+
}
121125
// console invalid session errors
122126
if errors.Is(err1, ErrInvalidSession) {
123127
errorCode = 401

0 commit comments

Comments
 (0)