@@ -276,6 +276,25 @@ def test_invalid_config_keys(self, mock_requests):
276276 resp = self .client .post (url , body )
277277 self .assertEqual (resp .status_code , 400 )
278278
279+ def test_invalid_config_values (self , mock_requests ):
280+ """
281+ Test that invalid config values are rejected.
282+ Right now only PORT is checked
283+ """
284+ data = [
285+ {'field' : 'PORT' , 'value' : 'dog' },
286+ {'field' : 'PORT' , 'value' : 99999 }
287+ ]
288+ url = '/v2/apps'
289+ response = self .client .post (url )
290+ self .assertEqual (response .status_code , 201 , response .data )
291+ app_id = response .data ['id' ]
292+ url = '/v2/apps/{app_id}/config' .format (** locals ())
293+ for row in data :
294+ body = {'values' : json .dumps ({row ['field' ]: row ['value' ]})}
295+ resp = self .client .post (url , body )
296+ self .assertEqual (resp .status_code , 400 , response .data )
297+
279298 def test_admin_can_create_config_on_other_apps (self , mock_requests ):
280299 """If a non-admin creates an app, an administrator should be able to set config
281300 values for that app.
@@ -727,33 +746,77 @@ def test_healthchecks(self, mock_requests):
727746 """
728747 Test that healthchecks can be applied
729748 """
730- url = '/v2/apps'
731- response = self .client .post (url )
749+ response = self .client .post ('/v2/apps' )
732750 self .assertEqual (response .status_code , 201 , response .data )
733751 app_id = response .data ['id' ]
734752
735- # Set healthcheck URL to get defaults set
736- body = {'values' : json .dumps ({'HEALTHCHECK_INITIAL_DELAY' : '25' })}
753+ # Set a healthcheck option before URL is around (URL is required for full setting)
737754 resp = self .client .post (
738755 '/v2/apps/{app_id}/config' .format (** locals ()),
739- body
756+ { 'values' : json . dumps ({ 'HEALTHCHECK_INITIAL_DELAY' : '25' })}
740757 )
741- self .assertEqual (resp .status_code , 201 )
758+ self .assertEqual (resp .status_code , 201 , response . data )
742759 self .assertIn ('HEALTHCHECK_INITIAL_DELAY' , resp .data ['values' ])
743760 self .assertEqual (resp .data ['values' ]['HEALTHCHECK_INITIAL_DELAY' ], '25' )
744761
745762 # Set healthcheck URL to get defaults set
746- body = {'values' : json .dumps ({'HEALTHCHECK_URL' : '/health' })}
747763 resp = self .client .post (
748764 '/v2/apps/{app_id}/config' .format (** locals ()),
749- body
765+ { 'values' : json . dumps ({ 'HEALTHCHECK_URL' : '/health' })}
750766 )
751- self .assertEqual (resp .status_code , 201 )
767+ self .assertEqual (resp .status_code , 201 , response . data )
752768 self .assertIn ('HEALTHCHECK_URL' , resp .data ['values' ])
753769 self .assertEqual (resp .data ['values' ]['HEALTHCHECK_URL' ], '/health' )
754770
755771 # post a new build
756- url = "/v2/apps/{app_id}/builds" .format (** locals ())
757- body = {'image' : 'quay.io/autotest/example' }
758- response = self .client .post (url , body )
772+ response = self .client .post (
773+ "/v2/apps/{app_id}/builds" .format (** locals ()),
774+ {'image' : 'quay.io/autotest/example' }
775+ )
776+ self .assertEqual (response .status_code , 201 , response .data )
777+
778+ def test_healthchecks_validations (self , mock_requests ):
779+ """
780+ Test that healthchecks validations work
781+ """
782+ response = self .client .post ('/v2/apps' )
759783 self .assertEqual (response .status_code , 201 , response .data )
784+ app_id = response .data ['id' ]
785+
786+ # Set one of the values that require a numeric value to a string
787+ resp = self .client .post (
788+ '/v2/apps/{app_id}/config' .format (** locals ()),
789+ {'values' : json .dumps ({'HEALTHCHECK_INITIAL_DELAY' : 'horse' })}
790+ )
791+ self .assertEqual (resp .status_code , 400 , response .data )
792+
793+ # test URL - Path is the only allowed thing
794+ # Try setting various things such as query param
795+
796+ # query param
797+ resp = self .client .post (
798+ '/v2/apps/{app_id}/config' .format (** locals ()),
799+ {'values' : json .dumps ({'HEALTHCHECK_URL' : '/health?testing=0' })}
800+ )
801+ self .assertEqual (resp .status_code , 400 , response .data )
802+
803+ # fragment
804+ resp = self .client .post (
805+ '/v2/apps/{app_id}/config' .format (** locals ()),
806+ {'values' : json .dumps ({'HEALTHCHECK_URL' : '/health#db' })}
807+ )
808+ self .assertEqual (resp .status_code , 400 , response .data )
809+
810+ # netloc
811+ resp = self .client .post (
812+ '/v2/apps/{app_id}/config' .format (** locals ()),
813+ {'values' : json .dumps ({'HEALTHCHECK_URL' : 'http://someurl.com/health/' })}
814+ )
815+ self .assertEqual (resp .status_code , 400 , response .data )
816+
817+ # no path
818+ resp = self .client .post (
819+ '/v2/apps/{app_id}/config' .format (** locals ()),
820+ {'values' : json .dumps ({'HEALTHCHECK_URL' : 'http://someurl.com' })}
821+ )
822+ self .assertEqual (resp .status_code , 400 , response .data )
0 commit comments