Commit 7e36eeef authored by Sofia Papagiannaki's avatar Sofia Papagiannaki

pithos: Eliminate AssertionError in views

Remove check for not allowed request method in view_method() decorator.
Let the api_method() decorator handle such cases.

Refs: #4501
parent f5c5f79c
......@@ -54,6 +54,62 @@ import time as _time
import random
class NotAllowedView(PithosAPITest):
def head(self, url, *args, **kwargs):
with patch("pithos.api.util.get_token_from_cookie") as m:
m.return_value = 'token'
return super(NotAllowedView, self).head(url, *args, **kwargs)
def delete(self, url, *args, **kwargs):
with patch("pithos.api.util.get_token_from_cookie") as m:
m.return_value = 'token'
return super(NotAllowedView, self).delete(url, *args, **kwargs)
def post(self, url, *args, **kwargs):
with patch("pithos.api.util.get_token_from_cookie") as m:
m.return_value = 'token'
return super(NotAllowedView, self).post(url, *args, **kwargs)
def put(self, url, *args, **kwargs):
with patch("pithos.api.util.get_token_from_cookie") as m:
m.return_value = 'token'
return super(NotAllowedView, self).put(url, *args, **kwargs)
def copy(self, url, *args, **kwargs):
with patch("pithos.api.util.get_token_from_cookie") as m:
m.return_value = 'token'
return super(NotAllowedView, self).copy(url, *args, **kwargs)
def move(self, url, *args, **kwargs):
with patch("pithos.api.util.get_token_from_cookie") as m:
m.return_value = 'token'
return super(NotAllowedView, self).move(url, *args, **kwargs)
def test_not_allowed(self):
self.view_path = join_urls(get_service_path(
pithos_settings.pithos_services, 'pithos_ui'), 'view')
self.view_url = join_urls(self.view_path, self.user, get_random_name(),
get_random_name())
r = self.head(self.view_url)
self.assertEqual(r.status_code, 400)
r = self.delete(self.view_url)
self.assertEqual(r.status_code, 400)
r = self.post(self.view_url)
self.assertEqual(r.status_code, 400)
r = self.put(self.view_url)
self.assertEqual(r.status_code, 400)
r = self.copy(self.view_url)
self.assertEqual(r.status_code, 400)
r = self.move(self.view_url)
self.assertEqual(r.status_code, 400)
class ObjectGetView(PithosAPITest):
def setUp(self):
PithosAPITest.setUp(self)
......
......@@ -1115,8 +1115,6 @@ def api_method(http_method=None, token_required=True, user_required=True,
def get_token_from_cookie(request):
assert(request.method == 'GET'),\
"Cookie based authentication is only allowed to GET requests"
token = None
if COOKIE_NAME in request.COOKIES:
cookie_value = unquote(request.COOKIES.get(COOKIE_NAME, ''))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment