summaryrefslogtreecommitdiff
path: root/tests/oauth2/rfc6749/endpoints/test_error_responses.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/oauth2/rfc6749/endpoints/test_error_responses.py')
-rw-r--r--tests/oauth2/rfc6749/endpoints/test_error_responses.py66
1 files changed, 48 insertions, 18 deletions
diff --git a/tests/oauth2/rfc6749/endpoints/test_error_responses.py b/tests/oauth2/rfc6749/endpoints/test_error_responses.py
index 2b87032..2479836 100644
--- a/tests/oauth2/rfc6749/endpoints/test_error_responses.py
+++ b/tests/oauth2/rfc6749/endpoints/test_error_responses.py
@@ -11,7 +11,6 @@ from oauthlib.oauth2 import (BackendApplicationServer, LegacyApplicationServer,
MobileApplicationServer, RequestValidator,
WebApplicationServer)
from oauthlib.oauth2.rfc6749 import errors
-
from ....unittest import TestCase
@@ -439,24 +438,55 @@ class ErrorResponseTest(TestCase):
body='grant_type=bar')
self.assertEqual('unsupported_grant_type', json.loads(body)['error'])
+ def test_invalid_request_method(self):
+ test_methods = ['GET', 'pUt', 'dEleTe', 'paTcH']
+ test_methods = test_methods + [x.lower() for x in test_methods] + [x.upper() for x in test_methods]
+ for method in test_methods:
+ self.validator.authenticate_client.side_effect = self.set_client
+
+ uri = "http://i/b/token/"
+ try:
+ _, body, s = self.web.create_token_response(uri,
+ body='grant_type=access_token&code=123', http_method=method)
+ self.fail('This should have failed with InvalidRequestError')
+ except errors.InvalidRequestError as ire:
+ self.assertIn('Unsupported request method', ire.description)
+
+ try:
+ _, body, s = self.legacy.create_token_response(uri,
+ body='grant_type=access_token&code=123', http_method=method)
+ self.fail('This should have failed with InvalidRequestError')
+ except errors.InvalidRequestError as ire:
+ self.assertIn('Unsupported request method', ire.description)
+
+ try:
+ _, body, s = self.backend.create_token_response(uri,
+ body='grant_type=access_token&code=123', http_method=method)
+ self.fail('This should have failed with InvalidRequestError')
+ except errors.InvalidRequestError as ire:
+ self.assertIn('Unsupported request method', ire.description)
+
def test_invalid_post_request(self):
self.validator.authenticate_client.side_effect = self.set_client
for param in ['token', 'secret', 'code', 'foo']:
uri = 'https://i/b/token?' + urlencode([(param, 'secret')])
- _, body, s = self.web.create_introspect_response(uri,
- body='grant_type=access_token&code=123')
- self.assertEqual(json.loads(body)['error'], 'invalid_request')
- self.assertIn('query parameters are not allowed', json.loads(body)['error_description'])
- self.assertEqual(s, 400)
-
- _, body, s = self.legacy.create_introspect_response(uri,
- body='grant_type=access_token&code=123')
- self.assertEqual(json.loads(body)['error'], 'invalid_request')
- self.assertIn('query parameters are not allowed', json.loads(body)['error_description'])
- self.assertEqual(s, 400)
-
- _, body, s = self.backend.create_introspect_response(uri,
- body='grant_type=access_token&code=123')
- self.assertEqual(json.loads(body)['error'], 'invalid_request')
- self.assertIn('query parameters are not allowed', json.loads(body)['error_description'])
- self.assertEqual(s, 400)
+ try:
+ _, body, s = self.web.create_token_response(uri,
+ body='grant_type=access_token&code=123')
+ self.fail('This should have failed with InvalidRequestError')
+ except errors.InvalidRequestError as ire:
+ self.assertIn('URL query parameters are not allowed', ire.description)
+
+ try:
+ _, body, s = self.legacy.create_token_response(uri,
+ body='grant_type=access_token&code=123')
+ self.fail('This should have failed with InvalidRequestError')
+ except errors.InvalidRequestError as ire:
+ self.assertIn('URL query parameters are not allowed', ire.description)
+
+ try:
+ _, body, s = self.backend.create_token_response(uri,
+ body='grant_type=access_token&code=123')
+ self.fail('This should have failed with InvalidRequestError')
+ except errors.InvalidRequestError as ire:
+ self.assertIn('URL query parameters are not allowed', ire.description)