/usr/lib/python2.7/dist-packages/social/tests/backends/test_dummy.py is in python-social-auth 1:0.2.21+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | import json
import datetime
import time
from httpretty import HTTPretty
from social.actions import do_disconnect
from social.backends.oauth import BaseOAuth2
from social.exceptions import AuthForbidden
from social.tests.models import User
from social.tests.backends.oauth import OAuth2Test
class DummyOAuth2(BaseOAuth2):
name = 'dummy'
AUTHORIZATION_URL = 'http://dummy.com/oauth/authorize'
ACCESS_TOKEN_URL = 'http://dummy.com/oauth/access_token'
REVOKE_TOKEN_URL = 'https://dummy.com/oauth/revoke'
REVOKE_TOKEN_METHOD = 'GET'
EXTRA_DATA = [
('id', 'id'),
('expires', 'expires'),
('empty', 'empty', True),
'url'
]
def get_user_details(self, response):
"""Return user details from Github account"""
return {'username': response.get('username'),
'email': response.get('email', ''),
'first_name': response.get('first_name', ''),
'last_name': response.get('last_name', '')}
def user_data(self, access_token, *args, **kwargs):
"""Loads user data from service"""
return self.get_json('http://dummy.com/user', params={
'access_token': access_token
})
class DummyOAuth2Test(OAuth2Test):
backend_path = 'social.tests.backends.test_dummy.DummyOAuth2'
user_data_url = 'http://dummy.com/user'
expected_username = 'foobar'
access_token_body = json.dumps({
'access_token': 'foobar',
'token_type': 'bearer'
})
user_data_body = json.dumps({
'id': 1,
'username': 'foobar',
'url': 'http://dummy.com/user/foobar',
'first_name': 'Foo',
'last_name': 'Bar',
'email': 'foo@bar.com'
})
def test_login(self):
self.do_login()
def test_partial_pipeline(self):
self.do_partial_pipeline()
def test_tokens(self):
user = self.do_login()
self.assertEqual(user.social[0].access_token, 'foobar')
def test_revoke_token(self):
self.strategy.set_settings({
'SOCIAL_AUTH_REVOKE_TOKENS_ON_DISCONNECT': True
})
self.do_login()
user = User.get(self.expected_username)
user.password = 'password'
HTTPretty.register_uri(self._method(self.backend.REVOKE_TOKEN_METHOD),
self.backend.REVOKE_TOKEN_URL,
status=200)
do_disconnect(self.backend, user)
class WhitelistEmailsTest(DummyOAuth2Test):
def test_valid_login(self):
self.strategy.set_settings({
'SOCIAL_AUTH_WHITELISTED_EMAILS': ['foo@bar.com']
})
self.do_login()
def test_invalid_login(self):
self.strategy.set_settings({
'SOCIAL_AUTH_WHITELISTED_EMAILS': ['foo2@bar.com']
})
with self.assertRaises(AuthForbidden):
self.do_login()
class WhitelistDomainsTest(DummyOAuth2Test):
def test_valid_login(self):
self.strategy.set_settings({
'SOCIAL_AUTH_WHITELISTED_DOMAINS': ['bar.com']
})
self.do_login()
def test_invalid_login(self):
self.strategy.set_settings({
'SOCIAL_AUTH_WHITELISTED_EMAILS': ['bar2.com']
})
with self.assertRaises(AuthForbidden):
self.do_login()
DELTA = datetime.timedelta(days=1)
class ExpirationTimeTest(DummyOAuth2Test):
user_data_body = json.dumps({
'id': 1,
'username': 'foobar',
'url': 'http://dummy.com/user/foobar',
'first_name': 'Foo',
'last_name': 'Bar',
'email': 'foo@bar.com',
'expires': time.mktime((datetime.datetime.utcnow() +
DELTA).timetuple())
})
def test_expires_time(self):
user = self.do_login()
social = user.social[0]
expiration = social.expiration_datetime()
self.assertEqual(expiration <= DELTA, True)
|