@@ -36,12 +36,12 @@ def run_validation_test(response, test_array):
3636 else : return True
3737
3838 if test .get ('test_type' ) == 'response_length_check' :
39- if ResponseValidator .response_length_check (response , test .get ('threshold' , 0 ), test .get ('comparison_type' )):
39+ if ResponseValidator .response_length_check (ResponseValidator . get_response_text ( response ) , test .get ('threshold' , 0 ), test .get ('comparison_type' )):
4040 fail_counter += 1
4141 else : return True
4242
4343 if test .get ('test_type' ) == 'string_check' and test .get ('test_location' ) == 'body' :
44- if ResponseValidator .string_check (response , test .get ('text_check' , '' ), test .get ('comparison_type' ), text_slice = test .get ('text_slice' )):
44+ if ResponseValidator .string_check (ResponseValidator . get_response_text ( response ) , test .get ('text_check' , '' ), test .get ('comparison_type' ), text_slice = test .get ('text_slice' )):
4545 fail_counter += 1
4646 else : return True
4747
@@ -89,9 +89,16 @@ def failed_scan(request_response_object, domains):
8989
9090
9191 @staticmethod
92- def string_check (response , text_check , comparison , text_slice = None ):
93- if text_check == '' : return False
94- text = response .text if isinstance (response , Response ) else response
92+ def get_response_text (response ):
93+ try :
94+ if isinstance (response , Response ): return response .text
95+ else : return ''
96+ except AttributeError :
97+ return ''
98+
99+
100+ @staticmethod
101+ def string_check (text , text_check , comparison , text_slice = None ):
95102 if text_slice is not None :
96103 text = ResponseValidator .string_slice (text , text_slice )
97104 if comparison == 'contains' and text_check in text :
@@ -100,6 +107,7 @@ def string_check(response, text_check, comparison, text_slice=None):
100107 return True
101108 return False
102109
110+
103111 @staticmethod
104112 def string_slice (text , text_slice ):
105113 if text_slice .get ('active' ):
@@ -155,9 +163,9 @@ def bytes_check(response, threshold, comparison):
155163
156164
157165 @staticmethod
158- def response_length_check (response , threshold , comparison ):
166+ def response_length_check (text , threshold , comparison ):
159167 if threshold == 0 : return False
160- response_text_length = len (response . text )
168+ response_text_length = len (text )
161169 return ResponseValidator .comparison_operators (response_text_length , threshold , comparison )
162170
163171
0 commit comments