parent
48fbe0db70
commit
33ad777f71
@ -319,7 +319,7 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin):
|
|||||||
elif method == "POST":
|
elif method == "POST":
|
||||||
return self._bucket_response_post(request, body, bucket_name)
|
return self._bucket_response_post(request, body, bucket_name)
|
||||||
elif method == "OPTIONS":
|
elif method == "OPTIONS":
|
||||||
return self._bucket_response_options(bucket_name)
|
return self._response_options(bucket_name)
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
"Method {0} has not been implemented in the S3 backend yet".format(
|
"Method {0} has not been implemented in the S3 backend yet".format(
|
||||||
@ -389,7 +389,7 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin):
|
|||||||
|
|
||||||
return self.headers
|
return self.headers
|
||||||
|
|
||||||
def _bucket_response_options(self, bucket_name):
|
def _response_options(self, bucket_name):
|
||||||
# Return 200 with the headers from the bucket CORS configuration
|
# Return 200 with the headers from the bucket CORS configuration
|
||||||
self._authenticate_and_authorize_s3_action()
|
self._authenticate_and_authorize_s3_action()
|
||||||
try:
|
try:
|
||||||
@ -1294,6 +1294,9 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin):
|
|||||||
return self._key_response_delete(headers, bucket_name, query, key_name)
|
return self._key_response_delete(headers, bucket_name, query, key_name)
|
||||||
elif method == "POST":
|
elif method == "POST":
|
||||||
return self._key_response_post(request, body, bucket_name, query, key_name)
|
return self._key_response_post(request, body, bucket_name, query, key_name)
|
||||||
|
elif method == "OPTIONS":
|
||||||
|
# OPTIONS response doesn't depend on the key_name: always return 200 with CORS headers
|
||||||
|
return self._response_options(bucket_name)
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
"Method {0} has not been implemented in the S3 backend yet".format(
|
"Method {0} has not been implemented in the S3 backend yet".format(
|
||||||
|
@ -223,17 +223,19 @@ def test_s3_server_post_cors_exposed_header():
|
|||||||
cors_res = test_client.get("/?cors", "http://testcors.localhost:5000")
|
cors_res = test_client.get("/?cors", "http://testcors.localhost:5000")
|
||||||
assert b"<ExposedHeader>ETag</ExposedHeader>" in cors_res.data
|
assert b"<ExposedHeader>ETag</ExposedHeader>" in cors_res.data
|
||||||
|
|
||||||
preflight_response = test_client.options(
|
# Test OPTIONS bucket response and key response
|
||||||
"/", "http://testcors.localhost:5000/", headers=preflight_headers
|
for key_name in ("/", "/test"):
|
||||||
)
|
preflight_response = test_client.options(
|
||||||
assert preflight_response.status_code == 200
|
key_name, "http://testcors.localhost:5000/", headers=preflight_headers
|
||||||
expected_cors_headers = {
|
)
|
||||||
"Access-Control-Allow-Methods": "HEAD, GET, PUT, POST, DELETE",
|
assert preflight_response.status_code == 200
|
||||||
"Access-Control-Allow-Origin": "https://example.org",
|
expected_cors_headers = {
|
||||||
"Access-Control-Allow-Headers": "*",
|
"Access-Control-Allow-Methods": "HEAD, GET, PUT, POST, DELETE",
|
||||||
"Access-Control-Expose-Headers": "ETag",
|
"Access-Control-Allow-Origin": "https://example.org",
|
||||||
"Access-Control-Max-Age": "3000",
|
"Access-Control-Allow-Headers": "*",
|
||||||
}
|
"Access-Control-Expose-Headers": "ETag",
|
||||||
for header_name, header_value in expected_cors_headers.items():
|
"Access-Control-Max-Age": "3000",
|
||||||
assert header_name in preflight_response.headers
|
}
|
||||||
assert preflight_response.headers[header_name] == header_value
|
for header_name, header_value in expected_cors_headers.items():
|
||||||
|
assert header_name in preflight_response.headers
|
||||||
|
assert preflight_response.headers[header_name] == header_value
|
||||||
|
Loading…
x
Reference in New Issue
Block a user