Fix checks for content length in object storage tests.
Tempest verifies whether HTTP response have "Content-Length" header specified. However, the checks do not have exceptions for the cases clearly mentioned in the RFC 7230: "A server MUST NOT send a Content-Length header field in any response with a status code of 1xx (Informational) or 204 (No Content)." This patch rectifies the checks to not enforce presence of the Content-Length in such cases. Change-Id: I725982dbcf1f1ea4ffb2bb7106aefdd3029d3e03 Closes-Bug: #1536251
This commit is contained in:
parent
aff9cc072b
commit
c22ef48aec
|
@ -78,7 +78,16 @@ class AccountTest(base.BaseObjectTest):
|
|||
# container request, the response does not contain 'accept-ranges'
|
||||
# header. This is a special case, therefore the existence of response
|
||||
# headers is checked without custom matcher.
|
||||
self.assertIn('content-length', resp)
|
||||
#
|
||||
# As the expected response is 204 No Content, Content-Length presence
|
||||
# is not checked here intensionally. According to RFC 7230 a server
|
||||
# MUST NOT send the header in such responses. Thus, clients should not
|
||||
# depend on this header. However, the standard does not require them
|
||||
# to validate the server's behavior. We leverage that to not refuse
|
||||
# any implementation violating it like Swift [1] or some versions of
|
||||
# Ceph RadosGW [2].
|
||||
# [1] https://bugs.launchpad.net/swift/+bug/1537811
|
||||
# [2] http://tracker.ceph.com/issues/13582
|
||||
self.assertIn('x-timestamp', resp)
|
||||
self.assertIn('x-account-bytes-used', resp)
|
||||
self.assertIn('x-account-container-count', resp)
|
||||
|
|
|
@ -37,13 +37,32 @@ class ExistsAllResponseHeaders(object):
|
|||
self.target = target
|
||||
self.method = method
|
||||
|
||||
def _content_length_required(self, resp):
|
||||
# Verify whether given HTTP response must contain content-length.
|
||||
# Take into account the exceptions defined in RFC 7230.
|
||||
if resp.status in range(100, 200) or resp.status == 204:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def match(self, actual):
|
||||
"""Check headers
|
||||
|
||||
param: actual HTTP response headers
|
||||
param: actual HTTP response object containing headers and status
|
||||
"""
|
||||
# Check common headers for all HTTP methods
|
||||
if 'content-length' not in actual:
|
||||
# Check common headers for all HTTP methods.
|
||||
#
|
||||
# Please note that for 1xx and 204 responses Content-Length presence
|
||||
# is not checked intensionally. According to RFC 7230 a server MUST
|
||||
# NOT send the header in such responses. Thus, clients should not
|
||||
# depend on this header. However, the standard does not require them
|
||||
# to validate the server's behavior. We leverage that to not refuse
|
||||
# any implementation violating it like Swift [1] or some versions of
|
||||
# Ceph RadosGW [2].
|
||||
# [1] https://bugs.launchpad.net/swift/+bug/1537811
|
||||
# [2] http://tracker.ceph.com/issues/13582
|
||||
if ('content-length' not in actual and
|
||||
self._content_length_required(actual)):
|
||||
return NonExistentHeader('content-length')
|
||||
if 'content-type' not in actual:
|
||||
return NonExistentHeader('content-type')
|
||||
|
|
Loading…
Reference in New Issue