diff --git a/tempest/api/object_storage/test_account_services.py b/tempest/api/object_storage/test_account_services.py index 6bab9b30e3..12d54fa69b 100644 --- a/tempest/api/object_storage/test_account_services.py +++ b/tempest/api/object_storage/test_account_services.py @@ -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) diff --git a/tempest/common/custom_matchers.py b/tempest/common/custom_matchers.py index 8ba33ed586..998612bd45 100644 --- a/tempest/common/custom_matchers.py +++ b/tempest/common/custom_matchers.py @@ -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')