Selaa lähdekoodia

Merge pull request #1485 from LadyMozzarella/clean-up-header-check

Toolset: Verify headers last
Hamilton Turner 10 vuotta sitten
vanhempi
commit
74deb32ad9

+ 6 - 6
toolset/benchmark/test_types/db_type.py

@@ -18,7 +18,7 @@ class DBTestType(FrameworkTestType):
     '''
 
     url = base_url + self.db_url
-    response = self._curl(url)
+    full_response = self._curl(url)
     body = self._curl_body(url)
     
     # Empty response
@@ -27,11 +27,6 @@ class DBTestType(FrameworkTestType):
     elif len(body) == 0:
       return [('fail','Empty Response', url)]
 
-    # Ensure required response headers are present
-    if any(v not in response for v in ('Server','Date','Content-Type: application/json')) \
-       or all(v not in response for v in ('Content-Length','Transfer-Encoding')):
-      return [('warn','Required response header missing.',url)]
-
     # Valid JSON? 
     try: 
       response = json.loads(body)
@@ -54,6 +49,11 @@ class DBTestType(FrameworkTestType):
 
     problems += self._verifyObject(response, url)
 
+    # Ensure required response headers are present
+    if any(v.lower() not in full_response.lower() for v in ('Server','Date','Content-Type: application/json')) \
+       or all(v.lower() not in full_response.lower() for v in ('Content-Length','Transfer-Encoding')):
+      problems.append( ('warn','Required response header missing.',url) )
+
     if len(problems) == 0:
       return [('pass','',url)]
     else:

+ 6 - 6
toolset/benchmark/test_types/fortune_type.py

@@ -18,7 +18,7 @@ class FortuneTestType(FrameworkTestType):
     valid fortune response
     '''
     url = base_url + self.fortune_url
-    response = self._curl(url)
+    full_response = self._curl(url)
     body = self._curl_body(url)
     
     # Empty response
@@ -27,15 +27,15 @@ class FortuneTestType(FrameworkTestType):
     elif len(body) == 0:
       return [('fail','Empty Response', url)]
 
-    # Ensure required response headers are present
-    if any(v not in response for v in ('Server','Date','Content-Type: text/html')) \
-       or all(v not in response for v in ('Content-Length','Transfer-Encoding')):
-      return [('warn','Required response header missing.',url)]
-
     parser = FortuneHTMLParser()
     parser.feed(body)
     (valid, diff) = parser.isValidFortune(self.out)
     if valid:
+      # Ensure required response headers are present
+      if any(v.lower() not in full_response.lower() for v in ('Server','Date','Content-Type: text/html')) \
+         or all(v.lower() not in full_response.lower() for v in ('Content-Length','Transfer-Encoding')):
+        return[('warn','Required response header missing.',url)]
+
       return [('pass','',url)]
     else:
       failures = [('fail','Invalid according to FortuneHTMLParser',url)]

+ 6 - 6
toolset/benchmark/test_types/json_type.py

@@ -17,7 +17,7 @@ class JsonTestType(FrameworkTestType):
     '''
 
     url = base_url + self.json_url
-    response = self._curl(url)
+    full_response = self._curl(url)
     body = self._curl_body(url)
     
     # Empty response
@@ -26,11 +26,6 @@ class JsonTestType(FrameworkTestType):
     elif len(body) == 0:
       return [('fail','Empty Response', url)]
 
-    # Ensure required response headers are present
-    if any(v not in response for v in ('Server','Date','Content-Type: application/json')) \
-       or all(v not in response for v in ('Content-Length','Transfer-Encoding')):
-      return [('warn','Required response header missing.',url)]
-
     # Valid JSON? 
     try: 
       response = json.loads(body)
@@ -49,4 +44,9 @@ class JsonTestType(FrameworkTestType):
     if response['message'] != 'hello, world!':
       return [('fail',"Expected message of 'hello, world!', got '%s'"%response['message'], url)]
 
+    # Ensure required response headers are present
+    if any(v.lower() not in full_response for v in ('Server','Date','Content-Type: application/json')) \
+       or all(v.lower() not in full_response for v in ('Content-Length','Transfer-Encoding')):
+      return [('warn','Required response header missing.',url)]
+
     return [('pass','',url)]

+ 6 - 6
toolset/benchmark/test_types/plaintext_type.py

@@ -7,7 +7,7 @@ class PlaintextTestType(FrameworkTestType):
 
   def verify(self, base_url):
     url = base_url + self.plaintext_url
-    response = self._curl(url)
+    full_response = self._curl(url)
     body = self._curl_body(url)
 
     # Empty response
@@ -16,11 +16,6 @@ class PlaintextTestType(FrameworkTestType):
     elif len(body) == 0:
       return [('fail','Empty Response', url)]
 
-    # Ensure required response headers are present
-    if any(v not in response for v in ('Server','Date','Content-Type: text/plain')) \
-       or all(v not in response for v in ('Content-Length','Transfer-Encoding')):
-      return [('warn','Required response header missing.',url)]
-
     # Case insensitive
     orig = body
     body = body.lower()
@@ -32,6 +27,11 @@ class PlaintextTestType(FrameworkTestType):
       return [('warn', """Server is returning %s more bytes than are required.
         This may negatively affect benchmark performance""" % (len(body) - len("hello, world!")), url)]
 
+    # Ensure required response headers are present
+    if any(v.lower() not in full_response.lower() for v in ('Server','Date','Content-Type: text/plain')) \
+       or all(v.lower() not in full_response.lower() for v in ('Content-Length','Transfer-Encoding')):
+      return [('warn','Required response header missing.',url)]
+
     return [('pass', '', url)]
 
   def get_url(self):

+ 5 - 5
toolset/benchmark/test_types/query_type.py

@@ -65,11 +65,6 @@ class QueryTestType(DBTestType):
       return [(max_infraction,'No response', url)]
     elif len(body) == 0:
       return [(max_infraction,'Empty Response', url)]
-
-    # Ensure required response headers are present
-    if any(v not in curlResponse for v in ('Server','Date','Content-Type: application/json')) \
-       or all(v not in curlResponse for v in ('Content-Length','Transfer-Encoding')):
-      return [('warn','Required response header missing.',url)]
   
     # Valid JSON? 
     try: 
@@ -106,6 +101,11 @@ class QueryTestType(DBTestType):
         if maxBadObjects == 0:
           break
 
+    # Ensure required response headers are present
+    if any(v.lower() not in curlResponse.lower() for v in ('Server','Date','Content-Type: application/json')) \
+       or all(v.lower() not in curlResponse.lower() for v in ('Content-Length','Transfer-Encoding')):
+      problems.append( ('warn','Required response header missing.',url) )
+
     return problems