diff options
Diffstat (limited to 'tests/oauth2/rfc6749')
5 files changed, 91 insertions, 7 deletions
diff --git a/tests/oauth2/rfc6749/clients/test_backend_application.py b/tests/oauth2/rfc6749/clients/test_backend_application.py index 19ff1ef..ad6f9f2 100644 --- a/tests/oauth2/rfc6749/clients/test_backend_application.py +++ b/tests/oauth2/rfc6749/clients/test_backend_application.py @@ -4,6 +4,7 @@ from __future__ import absolute_import, unicode_literals from mock import patch from oauthlib.oauth2 import BackendApplicationClient +from oauthlib import signals from ....unittest import TestCase @@ -63,4 +64,17 @@ class BackendApplicationClientTest(TestCase): self.assertEqual(client.token_type, response.get("token_type")) # Mismatching state - self.assertRaises(Warning, client.parse_request_body_response, self.token_json, scope="invalid") + scope_changes_recorded = [] + def record_scope_change(sender, message, old, new): + scope_changes_recorded.append((message, old, new)) + + signals.scope_changed.connect(record_scope_change) + try: + client.parse_request_body_response(self.token_json, scope="invalid") + self.assertEqual(len(scope_changes_recorded), 1) + message, old, new = scope_changes_recorded[0] + self.assertEqual(message, 'Scope has changed from "invalid" to "/profile".') + self.assertEqual(old, ['invalid']) + self.assertEqual(new, ['/profile']) + finally: + signals.scope_changed.disconnect(record_scope_change) diff --git a/tests/oauth2/rfc6749/clients/test_legacy_application.py b/tests/oauth2/rfc6749/clients/test_legacy_application.py index 2af2e6c..a0ed642 100644 --- a/tests/oauth2/rfc6749/clients/test_legacy_application.py +++ b/tests/oauth2/rfc6749/clients/test_legacy_application.py @@ -3,6 +3,7 @@ from __future__ import absolute_import, unicode_literals from mock import patch +from oauthlib import signals from oauthlib.oauth2 import LegacyApplicationClient from ....unittest import TestCase @@ -65,4 +66,17 @@ class LegacyApplicationClientTest(TestCase): self.assertEqual(client.token_type, response.get("token_type")) # Mismatching state - self.assertRaises(Warning, client.parse_request_body_response, self.token_json, scope="invalid") + scope_changes_recorded = [] + def record_scope_change(sender, message, old, new): + scope_changes_recorded.append((message, old, new)) + + signals.scope_changed.connect(record_scope_change) + try: + client.parse_request_body_response(self.token_json, scope="invalid") + self.assertEqual(len(scope_changes_recorded), 1) + message, old, new = scope_changes_recorded[0] + self.assertEqual(message, 'Scope has changed from "invalid" to "/profile".') + self.assertEqual(old, ['invalid']) + self.assertEqual(new, ['/profile']) + finally: + signals.scope_changed.disconnect(record_scope_change) diff --git a/tests/oauth2/rfc6749/clients/test_mobile_application.py b/tests/oauth2/rfc6749/clients/test_mobile_application.py index 7c57101..1186946 100644 --- a/tests/oauth2/rfc6749/clients/test_mobile_application.py +++ b/tests/oauth2/rfc6749/clients/test_mobile_application.py @@ -3,6 +3,7 @@ from __future__ import absolute_import, unicode_literals from mock import patch +from oauthlib import signals from oauthlib.oauth2 import MobileApplicationClient from ....unittest import TestCase @@ -77,4 +78,17 @@ class MobileApplicationClientTest(TestCase): self.assertEqual(client.token_type, response.get("token_type")) # Mismatching scope - self.assertRaises(Warning, client.parse_request_uri_response, self.response_uri, scope="invalid") + scope_changes_recorded = [] + def record_scope_change(sender, message, old, new): + scope_changes_recorded.append((message, old, new)) + + signals.scope_changed.connect(record_scope_change) + try: + client.parse_request_uri_response(self.response_uri, scope="invalid") + self.assertEqual(len(scope_changes_recorded), 1) + message, old, new = scope_changes_recorded[0] + self.assertEqual(message, 'Scope has changed from "invalid" to "/profile".') + self.assertEqual(old, ['invalid']) + self.assertEqual(new, ['/profile']) + finally: + signals.scope_changed.disconnect(record_scope_change) diff --git a/tests/oauth2/rfc6749/clients/test_web_application.py b/tests/oauth2/rfc6749/clients/test_web_application.py index 0eac008..6f7b7e1 100644 --- a/tests/oauth2/rfc6749/clients/test_web_application.py +++ b/tests/oauth2/rfc6749/clients/test_web_application.py @@ -5,7 +5,7 @@ import datetime from mock import patch -from oauthlib import common +from oauthlib import common, signals from oauthlib.oauth2.rfc6749 import utils, errors from oauthlib.oauth2 import Client from oauthlib.oauth2 import WebApplicationClient @@ -128,4 +128,17 @@ class WebApplicationClientTest(TestCase): self.assertEqual(client.token_type, response.get("token_type")) # Mismatching state - self.assertRaises(Warning, client.parse_request_body_response, self.token_json, scope="invalid") + scope_changes_recorded = [] + def record_scope_change(sender, message, old, new): + scope_changes_recorded.append((message, old, new)) + + signals.scope_changed.connect(record_scope_change) + try: + client.parse_request_body_response(self.token_json, scope="invalid") + self.assertEqual(len(scope_changes_recorded), 1) + message, old, new = scope_changes_recorded[0] + self.assertEqual(message, 'Scope has changed from "invalid" to "/profile".') + self.assertEqual(old, ['invalid']) + self.assertEqual(new, ['/profile']) + finally: + signals.scope_changed.disconnect(record_scope_change) diff --git a/tests/oauth2/rfc6749/test_parameters.py b/tests/oauth2/rfc6749/test_parameters.py index c411fee..5122293 100644 --- a/tests/oauth2/rfc6749/test_parameters.py +++ b/tests/oauth2/rfc6749/test_parameters.py @@ -5,6 +5,7 @@ from mock import patch from ...unittest import TestCase from oauthlib.oauth2.rfc6749.parameters import * from oauthlib.oauth2.rfc6749.errors import * +from oauthlib import signals @patch('time.time', new=lambda: 1000) @@ -193,7 +194,21 @@ class ParameterTests(TestCase): self.assertEqual(parse_token_response(self.json_response), self.json_dict) self.assertRaises(InvalidRequestError, parse_token_response, self.json_error) self.assertRaises(MissingTokenError, parse_token_response, self.json_notoken) - self.assertRaises(Warning, parse_token_response, self.json_response, scope='aaa') + + scope_changes_recorded = [] + def record_scope_change(sender, message, old, new): + scope_changes_recorded.append((message, old, new)) + + signals.scope_changed.connect(record_scope_change) + try: + parse_token_response(self.json_response, scope='aaa') + self.assertEqual(len(scope_changes_recorded), 1) + message, old, new = scope_changes_recorded[0] + self.assertEqual(message, 'Scope has changed from "aaa" to "abc def".') + self.assertEqual(old, ['aaa']) + self.assertEqual(new, ['abc', 'def']) + finally: + signals.scope_changed.disconnect(record_scope_change) def test_json_token_notype(self): """Verify strict token type parsing only when configured. """ @@ -209,7 +224,21 @@ class ParameterTests(TestCase): self.assertEqual(parse_token_response(self.url_encoded_response), self.json_dict) self.assertRaises(InvalidRequestError, parse_token_response, self.url_encoded_error) self.assertRaises(MissingTokenError, parse_token_response, self.url_encoded_notoken) - self.assertRaises(Warning, parse_token_response, self.url_encoded_response, scope='aaa') + + scope_changes_recorded = [] + def record_scope_change(sender, message, old, new): + scope_changes_recorded.append((message, old, new)) + + signals.scope_changed.connect(record_scope_change) + try: + parse_token_response(self.url_encoded_response, scope='aaa') + self.assertEqual(len(scope_changes_recorded), 1) + message, old, new = scope_changes_recorded[0] + self.assertEqual(message, 'Scope has changed from "aaa" to "abc def".') + self.assertEqual(old, ['aaa']) + self.assertEqual(new, ['abc', 'def']) + finally: + signals.scope_changed.disconnect(record_scope_change) def test_token_response_with_expires(self): """Verify fallback for alternate spelling of expires_in. """ |