@@ -85,6 +85,7 @@ func TestPolicyAPI(t *testing.T) {
8585 ts := StartTest (func (cnf * config.Config ) {
8686 cnf .Policies .PolicyPath = "."
8787 cnf .Policies .PolicySource = "file"
88+ cnf .DisableCustomIdValidation = true
8889 })
8990
9091 defer ts .Close ()
@@ -176,17 +177,27 @@ func TestPolicyAPI(t *testing.T) {
176177 })
177178 })
178179
179- t .Run ("fails if ID contains invalid characters " , func (t * testing.T ) {
180+ t .Run ("GET does not fail if exitent policy has broken ID " , func (t * testing.T ) {
180181 invalidURLID := "invalid@id"
181182
183+ ts .CreatePolicy (func (p * user.Policy ) {
184+ p .ID = "invalid@id"
185+ })
186+
182187 _ , err := ts .Run (t , test.TestCase {
183188 Path : "/tyk/policies/" + invalidURLID ,
184189 Method : http .MethodGet ,
185190 AdminAuth : true ,
186- Code : http .StatusBadRequest ,
187- BodyMatch : errMsgInvalidPolicyID ,
191+ Code : http .StatusOK ,
188192 })
193+
189194 assert .NoError (t , err )
195+ })
196+
197+ t .Run ("fails create/update if ID contains invalid characters" , func (t * testing.T ) {
198+ ts .setTestScopeConfig (t , func (cnf * config.Config ) {
199+ cnf .DisableCustomIdValidation = false
200+ })
190201
191202 invalidBodyPol := user.Policy {
192203 ID : "invalid/id" ,
@@ -196,7 +207,7 @@ func TestPolicyAPI(t *testing.T) {
196207 AccessRights : make (map [string ]user.AccessDefinition ),
197208 }
198209
199- _ , err = ts .Run (t , test.TestCase {
210+ _ , err : = ts .Run (t , test.TestCase {
200211 Path : "/tyk/policies" ,
201212 Method : http .MethodPost ,
202213 AdminAuth : true ,
@@ -218,6 +229,42 @@ func TestPolicyAPI(t *testing.T) {
218229 })
219230 assert .NoError (t , err )
220231 })
232+
233+ t .Run ("does not fail on create/update if ID contains invalid characters and when DisableCustomIdValidation=true" , func (t * testing.T ) {
234+ ts .setTestScopeConfig (t , func (cnf * config.Config ) {
235+ cnf .DisableCustomIdValidation = true
236+ })
237+
238+ t .Cleanup (func () {
239+ _ = ts .Gw .removePersistentPolicyById ("invalid@id" ) //nolint:errcheck
240+ })
241+
242+ invalidBodyPol := user.Policy {
243+ ID : "invalid@id" ,
244+ Rate : 100 ,
245+ Per : 1 ,
246+ OrgID : "54de205930c55e15bd000001" ,
247+ AccessRights : make (map [string ]user.AccessDefinition ),
248+ }
249+
250+ _ , err := ts .Run (t , test.TestCase {
251+ Path : "/tyk/policies" ,
252+ Method : http .MethodPost ,
253+ AdminAuth : true ,
254+ Data : serializePolicy (t , invalidBodyPol ),
255+ Code : http .StatusOK ,
256+ })
257+ assert .NoError (t , err )
258+
259+ _ , err = ts .Run (t , test.TestCase {
260+ Path : "/tyk/policies/invalid@id" ,
261+ Method : http .MethodPut ,
262+ AdminAuth : true ,
263+ Data : serializePolicy (t , invalidBodyPol ),
264+ Code : http .StatusOK ,
265+ })
266+ assert .NoError (t , err )
267+ })
221268}
222269
223270func serializePolicy (t * testing.T , pol user.Policy ) string {
0 commit comments