Skip to content

Commit

Permalink
Don't allow invalid methods passed through
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrobenolt committed Sep 29, 2014
1 parent 1c6f318 commit 826fa32
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions disqusapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ class InterfaceNotDefined(NotImplementedError):
pass


class InvalidHTTPMethod(TypeError):
def __init__(self, message):
self.message = message

def __str__(self):
return "expected 'GET' or 'POST', got: %r" % self.message


class APIError(Exception):
def __init__(self, code, message):
self.code = code
Expand Down Expand Up @@ -130,6 +138,10 @@ def _request(self, endpoint=None, **kwargs):
raise InterfaceNotDefined(
'Interface is not defined, you must pass ``method`` (HTTP Method).')

method = method.upper()
if method not in ('GET', 'POST'):
raise InvalidHTTPMethod(method)

api = self.api

version = kwargs.pop('version', api.version)
Expand Down
5 changes: 5 additions & 0 deletions disqusapi/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ def test_update_interface_legacy(self):
with pytest.raises(disqusapi.InterfaceNotDefined):
api.interface.update(extra_interface)

def test_invalid_method(self):
api = disqusapi.DisqusAPI(self.API_SECRET, self.API_PUBLIC)
with pytest.raises(disqusapi.InvalidHTTPMethod):
api.get('posts.list', method='lol', forum='disqus')

def test_update_interface(self):
api = disqusapi.DisqusAPI(self.API_SECRET, self.API_PUBLIC)
api.update_interface(extra_interface)
Expand Down

0 comments on commit 826fa32

Please sign in to comment.