@@ -257,6 +257,41 @@ def test_config_str(self):
257257 config = Config .objects .get (uuid = config5 ['uuid' ])
258258 self .assertEqual (str (config ), "{}-{}" .format (config5 ['app' ], config5 ['uuid' ][:7 ]))
259259
260+ @mock .patch ('requests.post' , mock_status_ok )
261+ def test_valid_config_keys (self ):
262+ """Test that valid config keys are accepted.
263+ """
264+ keys = ("FOO" , "_foo" , "f001" , "FOO_BAR_BAZ_" )
265+ url = '/v1/apps'
266+ response = self .client .post (url , HTTP_AUTHORIZATION = 'token {}' .format (self .token ))
267+ self .assertEqual (response .status_code , 201 )
268+ app_id = response .data ['id' ]
269+ url = '/v1/apps/{app_id}/config' .format (** locals ())
270+ for k in keys :
271+ body = {'values' : json .dumps ({k : "testvalue" })}
272+ resp = self .client .post (
273+ url , json .dumps (body ), content_type = 'application/json' ,
274+ HTTP_AUTHORIZATION = 'token {}' .format (self .token ))
275+ self .assertEqual (resp .status_code , 201 )
276+ self .assertIn (k , resp .data ['values' ])
277+
278+ @mock .patch ('requests.post' , mock_status_ok )
279+ def test_invalid_config_keys (self ):
280+ """Test that invalid config keys are rejected.
281+ """
282+ keys = ("123" , "../../foo" , "FOO/" , "FOO-BAR" )
283+ url = '/v1/apps'
284+ response = self .client .post (url , HTTP_AUTHORIZATION = 'token {}' .format (self .token ))
285+ self .assertEqual (response .status_code , 201 )
286+ app_id = response .data ['id' ]
287+ url = '/v1/apps/{app_id}/config' .format (** locals ())
288+ for k in keys :
289+ body = {'values' : json .dumps ({k : "testvalue" })}
290+ resp = self .client .post (
291+ url , json .dumps (body ), content_type = 'application/json' ,
292+ HTTP_AUTHORIZATION = 'token {}' .format (self .token ))
293+ self .assertEqual (resp .status_code , 400 )
294+
260295 @mock .patch ('requests.post' , mock_status_ok )
261296 def test_admin_can_create_config_on_other_apps (self ):
262297 """If a non-admin creates an app, an administrator should be able to set config
0 commit comments