summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAbhishek Patel <5524161+Abhishek8394@users.noreply.github.com>2019-05-14 00:36:10 -0700
committerAbhishek Patel <5524161+Abhishek8394@users.noreply.github.com>2019-05-14 00:37:59 -0700
commit056948ac7c14a435d0b65dd27692fe2494bc3743 (patch)
tree912dff38bb170a34df0f84af9e52f0d91e4efdea /tests
parentee06f0f3349d7fd656d35a2eef40ee18fb74e303 (diff)
downloadoauthlib-056948ac7c14a435d0b65dd27692fe2494bc3743.tar.gz
Enforce POST HTTP method on TokenEndpoint, IntrospectEndpoint and RevocationEndpoint
- Add validation checks for HTTP method in TokenEndpoint, IntrospectEndpoint and RevocationEndpoint. - CHANGE DEFAULT HTTP method for TokenEndpoint from 'GET' to 'POST'. - Add tests + Fix an old test in . It used to send query params to TokenEndpoint which is not allowed anymore. Fixed it so payload is sent as POST body.
Diffstat (limited to 'tests')
-rw-r--r--tests/oauth2/rfc6749/endpoints/test_base_endpoint.py2
-rw-r--r--tests/oauth2/rfc6749/endpoints/test_error_responses.py66
-rw-r--r--tests/oauth2/rfc6749/endpoints/test_introspect_endpoint.py15
-rw-r--r--tests/oauth2/rfc6749/endpoints/test_revocation_endpoint.py15
4 files changed, 79 insertions, 19 deletions
diff --git a/tests/oauth2/rfc6749/endpoints/test_base_endpoint.py b/tests/oauth2/rfc6749/endpoints/test_base_endpoint.py
index 4f78d9b..bf04a42 100644
--- a/tests/oauth2/rfc6749/endpoints/test_base_endpoint.py
+++ b/tests/oauth2/rfc6749/endpoints/test_base_endpoint.py
@@ -25,7 +25,7 @@ class BaseEndpointTest(TestCase):
server = Server(validator)
server.catch_errors = True
h, b, s = server.create_token_response(
- 'https://example.com?grant_type=authorization_code&code=abc'
+ 'https://example.com', body='grant_type=authorization_code&code=abc'
)
self.assertIn("server_error", b)
self.assertEqual(s, 500)
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)
diff --git a/tests/oauth2/rfc6749/endpoints/test_introspect_endpoint.py b/tests/oauth2/rfc6749/endpoints/test_introspect_endpoint.py
index a34c970..ae3deae 100644
--- a/tests/oauth2/rfc6749/endpoints/test_introspect_endpoint.py
+++ b/tests/oauth2/rfc6749/endpoints/test_introspect_endpoint.py
@@ -140,6 +140,21 @@ class IntrospectEndpointTest(TestCase):
self.assertEqual(loads(b)['error'], 'invalid_request')
self.assertEqual(s, 400)
+ def test_introspect_invalid_request_method(self):
+ endpoint = IntrospectEndpoint(self.validator,
+ supported_token_types=['access_token'])
+ 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:
+ body = urlencode([('token', 'foo'),
+ ('token_type_hint', 'refresh_token')])
+ h, b, s = endpoint.create_introspect_response(self.uri,
+ http_method = method, headers=self.headers, body=body)
+ self.assertEqual(h, self.resp_h)
+ self.assertEqual(loads(b)['error'], 'invalid_request')
+ self.assertIn('Unsupported request method', loads(b)['error_description'])
+ self.assertEqual(s, 400)
+
def test_introspect_bad_post_request(self):
endpoint = IntrospectEndpoint(self.validator,
supported_token_types=['access_token'])
diff --git a/tests/oauth2/rfc6749/endpoints/test_revocation_endpoint.py b/tests/oauth2/rfc6749/endpoints/test_revocation_endpoint.py
index c73a1ef..17be3a5 100644
--- a/tests/oauth2/rfc6749/endpoints/test_revocation_endpoint.py
+++ b/tests/oauth2/rfc6749/endpoints/test_revocation_endpoint.py
@@ -121,6 +121,21 @@ class RevocationEndpointTest(TestCase):
self.assertEqual(loads(b)['error'], 'invalid_request')
self.assertEqual(s, 400)
+ def test_revoke_invalid_request_method(self):
+ endpoint = RevocationEndpoint(self.validator,
+ supported_token_types=['access_token'])
+ 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:
+ body = urlencode([('token', 'foo'),
+ ('token_type_hint', 'refresh_token')])
+ h, b, s = endpoint.create_revocation_response(self.uri,
+ http_method = method, headers=self.headers, body=body)
+ self.assertEqual(h, self.resp_h)
+ self.assertEqual(loads(b)['error'], 'invalid_request')
+ self.assertIn('Unsupported request method', loads(b)['error_description'])
+ self.assertEqual(s, 400)
+
def test_revoke_bad_post_request(self):
endpoint = RevocationEndpoint(self.validator,
supported_token_types=['access_token'])