aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/oauthlib/tests/oauth1/rfc5849/endpoints/test_authorization.py
diff options
context:
space:
mode:
authoralexv-smirnov <alex@ydb.tech>2023-12-01 12:02:50 +0300
committeralexv-smirnov <alex@ydb.tech>2023-12-01 13:28:10 +0300
commit0e578a4c44d4abd539d9838347b9ebafaca41dfb (patch)
treea0c1969c37f818c830ebeff9c077eacf30be6ef8 /contrib/python/oauthlib/tests/oauth1/rfc5849/endpoints/test_authorization.py
parent84f2d3d4cc985e63217cff149bd2e6d67ae6fe22 (diff)
downloadydb-0e578a4c44d4abd539d9838347b9ebafaca41dfb.tar.gz
Change "ya.make"
Diffstat (limited to 'contrib/python/oauthlib/tests/oauth1/rfc5849/endpoints/test_authorization.py')
-rw-r--r--contrib/python/oauthlib/tests/oauth1/rfc5849/endpoints/test_authorization.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/contrib/python/oauthlib/tests/oauth1/rfc5849/endpoints/test_authorization.py b/contrib/python/oauthlib/tests/oauth1/rfc5849/endpoints/test_authorization.py
new file mode 100644
index 0000000000..a9b2fc0c9f
--- /dev/null
+++ b/contrib/python/oauthlib/tests/oauth1/rfc5849/endpoints/test_authorization.py
@@ -0,0 +1,54 @@
+from unittest.mock import MagicMock
+
+from oauthlib.oauth1 import RequestValidator
+from oauthlib.oauth1.rfc5849 import errors
+from oauthlib.oauth1.rfc5849.endpoints import AuthorizationEndpoint
+
+from tests.unittest import TestCase
+
+
+class AuthorizationEndpointTest(TestCase):
+
+ def setUp(self):
+ self.validator = MagicMock(wraps=RequestValidator())
+ self.validator.verify_request_token.return_value = True
+ self.validator.verify_realms.return_value = True
+ self.validator.get_realms.return_value = ['test']
+ self.validator.save_verifier = MagicMock()
+ self.endpoint = AuthorizationEndpoint(self.validator)
+ self.uri = 'https://i.b/authorize?oauth_token=foo'
+
+ def test_get_realms_and_credentials(self):
+ realms, credentials = self.endpoint.get_realms_and_credentials(self.uri)
+ self.assertEqual(realms, ['test'])
+
+ def test_verify_token(self):
+ self.validator.verify_request_token.return_value = False
+ self.assertRaises(errors.InvalidClientError,
+ self.endpoint.get_realms_and_credentials, self.uri)
+ self.assertRaises(errors.InvalidClientError,
+ self.endpoint.create_authorization_response, self.uri)
+
+ def test_verify_realms(self):
+ self.validator.verify_realms.return_value = False
+ self.assertRaises(errors.InvalidRequestError,
+ self.endpoint.create_authorization_response,
+ self.uri,
+ realms=['bar'])
+
+ def test_create_authorization_response(self):
+ self.validator.get_redirect_uri.return_value = 'https://c.b/cb'
+ h, b, s = self.endpoint.create_authorization_response(self.uri)
+ self.assertEqual(s, 302)
+ self.assertIn('Location', h)
+ location = h['Location']
+ self.assertTrue(location.startswith('https://c.b/cb'))
+ self.assertIn('oauth_verifier', location)
+
+ def test_create_authorization_response_oob(self):
+ self.validator.get_redirect_uri.return_value = 'oob'
+ h, b, s = self.endpoint.create_authorization_response(self.uri)
+ self.assertEqual(s, 200)
+ self.assertNotIn('Location', h)
+ self.assertIn('oauth_verifier', b)
+ self.assertIn('oauth_token', b)