This repository has been archived by the owner on May 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 257
/
openid_connect_test.py
67 lines (48 loc) · 2.46 KB
/
openid_connect_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from test_helper import unittest, paypal, client_id, client_secret, assert_regex_matches
from paypalrestsdk.openid_connect import Tokeninfo, Userinfo, authorize_url, logout_url, endpoint
class TestTokeninfo(unittest.TestCase):
def test_create(self):
self.assertRaises(paypal.ResourceNotFound, Tokeninfo.create, "invalid-code")
def test_userinfo(self):
self.assertRaises(paypal.UnauthorizedAccess, Tokeninfo().userinfo, {})
def test_refresh(self):
self.assertRaises(paypal.ResourceNotFound, Tokeninfo().refresh, {})
def test_create_with_refresh_token(self):
self.assertRaises(paypal.ResourceNotFound, Tokeninfo.create_with_refresh_token, "invalid-token")
class TestUserinfo(unittest.TestCase):
def test_get(self):
self.assertRaises(paypal.UnauthorizedAccess, Userinfo.get, "invalid")
class TestUrls(unittest.TestCase):
def test_authorize_url(self):
url = authorize_url()
assert_regex_matches(self, url, 'response_type=code')
assert_regex_matches(self, url, 'scope=openid')
assert_regex_matches(self, url, 'client_id=%s'%(client_id))
assert_regex_matches(self, url, 'https://www.sandbox.paypal.com')
self.assertEqual(endpoint(), 'https://api.sandbox.paypal.com')
def test_live_mode_url(self):
try:
paypal.configure( mode='live', client_id=client_id, client_secret=client_secret )
url = authorize_url()
assert_regex_matches(self, url, 'response_type=code')
assert_regex_matches(self, url, 'scope=openid')
assert_regex_matches(self, url, 'client_id=%s'%(client_id))
assert_regex_matches(self, url, 'https://www.paypal.com')
self.assertEqual(endpoint(), 'https://api.paypal.com')
finally:
paypal.configure( mode='sandbox', client_id=client_id, client_secret=client_secret )
def test_authorize_url_options(self):
url = authorize_url({ 'scope': 'openid profile' })
assert_regex_matches(self, url, 'scope=openid\+profile')
def test_authorize_url_using_tokeninfo(self):
url = Tokeninfo.authorize_url({ 'scope': 'openid profile' })
assert_regex_matches(self, url, 'scope=openid\+profile')
def test_logout_url(self):
url = logout_url()
assert_regex_matches(self, url, 'logout=true')
def test_logout_url_options(self):
url = logout_url({'id_token': '1234'})
assert_regex_matches(self, url, 'id_token=1234')
def test_logout_url_using_tokeninfo(self):
url = Tokeninfo({'id_token': '1234'}).logout_url()
assert_regex_matches(self, url, 'id_token=1234')