Skip to content

Commit

Permalink
Improve proxy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aarranz committed May 20, 2016
1 parent 261d5b9 commit 83ae284
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 22 additions & 1 deletion src/wirecloud/proxy/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,17 @@ def test_basic_proxy_requests_from_widget_restricted_to_get_post(self):

self.network._servers['http']['example.com'].add_response('PUT', '/path', {'content': 'data'})
widget_url = reverse('wirecloud.widget_code_entry', kwargs={"vendor": "Wirecloud", "name": "Test", "version": "1.0"})
response = client.put(self.basic_url, "{}", content_type="application/json", HTTP_HOST='localhost', HTTP_REFERER=widget_url)
response = client.put(self.basic_url, "{}", content_type="application/json", HTTP_HOST='localhost', HTTP_REFERER='http://localhost' + widget_url)
self.assertEqual(response.status_code, 403)

def test_basic_proxy_requests_invalid_referer(self):

client = Client()
client.login(username='test', password='test')

self.network._servers['http']['example.com'].add_response('PUT', '/path', {'content': 'data'})
response = client.get(self.basic_url, HTTP_HOST='localhost', HTTP_REFERER='http://localhost/')
self.assertEqual(response.status_code, 403)

def test_basic_proxy_requests_from_proxied_content(self):

Expand Down Expand Up @@ -318,6 +326,19 @@ def test_encoded_urls(self):
self.assertEqual(response.status_code, 200)
self.assertEqual(self.read_response(response), b'data')

def test_transfer_encoding(self):

client = Client()
client.login(username='test', password='test')

response = client.get(
self.basic_url,
HTTP_HOST='localhost',
HTTP_REFERER='http://localhost/test/workspace',
HTTP_TRANSFER_ENCODING='chunked',
)
self.assertEqual(response.status_code, 422)

def test_cookies(self):

client = Client()
Expand Down
2 changes: 1 addition & 1 deletion src/wirecloud/proxy/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def do_request(self, request, url, method, workspace):

# Extract headers from META
if 'HTTP_TRANSFER_ENCODING' in request.META:
return build_error_response(request, 422, "Wirecloud doesn't support requests using the Transfer-Encoding header")
return build_error_response(request, 422, "WireCloud doesn't support requests using the Transfer-Encoding header")

for header in request.META.items():
header_name = header[0].lower()
Expand Down

0 comments on commit 83ae284

Please sign in to comment.