/usr/lib/python3/dist-packages/social/tests/backends/test_github.py is in python3-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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | import json
from httpretty import HTTPretty
from social.exceptions import AuthFailed
from social.tests.backends.oauth import OAuth2Test
class GithubOAuth2Test(OAuth2Test):
backend_path = 'social.backends.github.GithubOAuth2'
user_data_url = 'https://api.github.com/user'
expected_username = 'foobar'
access_token_body = json.dumps({
'access_token': 'foobar',
'token_type': 'bearer'
})
user_data_body = json.dumps({
'login': 'foobar',
'id': 1,
'avatar_url': 'https://github.com/images/error/foobar_happy.gif',
'gravatar_id': 'somehexcode',
'url': 'https://api.github.com/users/foobar',
'name': 'monalisa foobar',
'company': 'GitHub',
'blog': 'https://github.com/blog',
'location': 'San Francisco',
'email': 'foo@bar.com',
'hireable': False,
'bio': 'There once was...',
'public_repos': 2,
'public_gists': 1,
'followers': 20,
'following': 0,
'html_url': 'https://github.com/foobar',
'created_at': '2008-01-14T04:33:35Z',
'type': 'User',
'total_private_repos': 100,
'owned_private_repos': 100,
'private_gists': 81,
'disk_usage': 10000,
'collaborators': 8,
'plan': {
'name': 'Medium',
'space': 400,
'collaborators': 10,
'private_repos': 20
}
})
def test_login(self):
self.do_login()
def test_partial_pipeline(self):
self.do_partial_pipeline()
class GithubOAuth2NoEmailTest(GithubOAuth2Test):
user_data_body = json.dumps({
'login': 'foobar',
'id': 1,
'avatar_url': 'https://github.com/images/error/foobar_happy.gif',
'gravatar_id': 'somehexcode',
'url': 'https://api.github.com/users/foobar',
'name': 'monalisa foobar',
'company': 'GitHub',
'blog': 'https://github.com/blog',
'location': 'San Francisco',
'email': '',
'hireable': False,
'bio': 'There once was...',
'public_repos': 2,
'public_gists': 1,
'followers': 20,
'following': 0,
'html_url': 'https://github.com/foobar',
'created_at': '2008-01-14T04:33:35Z',
'type': 'User',
'total_private_repos': 100,
'owned_private_repos': 100,
'private_gists': 81,
'disk_usage': 10000,
'collaborators': 8,
'plan': {
'name': 'Medium',
'space': 400,
'collaborators': 10,
'private_repos': 20
}
})
def test_login(self):
url = 'https://api.github.com/user/emails'
HTTPretty.register_uri(HTTPretty.GET, url, status=200,
body=json.dumps(['foo@bar.com']),
content_type='application/json')
self.do_login()
def test_login_next_format(self):
url = 'https://api.github.com/user/emails'
HTTPretty.register_uri(HTTPretty.GET, url, status=200,
body=json.dumps([{'email': 'foo@bar.com'}]),
content_type='application/json')
self.do_login()
def test_partial_pipeline(self):
self.do_partial_pipeline()
class GithubOrganizationOAuth2Test(GithubOAuth2Test):
backend_path = 'social.backends.github.GithubOrganizationOAuth2'
def auth_handlers(self, start_url):
url = 'https://api.github.com/orgs/foobar/members/foobar'
HTTPretty.register_uri(HTTPretty.GET, url, status=204, body='')
return super(GithubOrganizationOAuth2Test, self).auth_handlers(
start_url
)
def test_login(self):
self.strategy.set_settings({'SOCIAL_AUTH_GITHUB_ORG_NAME': 'foobar'})
self.do_login()
def test_partial_pipeline(self):
self.strategy.set_settings({'SOCIAL_AUTH_GITHUB_ORG_NAME': 'foobar'})
self.do_partial_pipeline()
class GithubOrganizationOAuth2FailTest(GithubOAuth2Test):
backend_path = 'social.backends.github.GithubOrganizationOAuth2'
def auth_handlers(self, start_url):
url = 'https://api.github.com/orgs/foobar/members/foobar'
HTTPretty.register_uri(HTTPretty.GET, url, status=404,
body='{"message": "Not Found"}',
content_type='application/json')
return super(GithubOrganizationOAuth2FailTest, self).auth_handlers(
start_url
)
def test_login(self):
self.strategy.set_settings({'SOCIAL_AUTH_GITHUB_ORG_NAME': 'foobar'})
with self.assertRaises(AuthFailed):
self.do_login()
def test_partial_pipeline(self):
self.strategy.set_settings({'SOCIAL_AUTH_GITHUB_ORG_NAME': 'foobar'})
with self.assertRaises(AuthFailed):
self.do_partial_pipeline()
class GithubTeamOAuth2Test(GithubOAuth2Test):
backend_path = 'social.backends.github.GithubTeamOAuth2'
def auth_handlers(self, start_url):
url = 'https://api.github.com/teams/123/members/foobar'
HTTPretty.register_uri(HTTPretty.GET, url, status=204, body='')
return super(GithubTeamOAuth2Test, self).auth_handlers(
start_url
)
def test_login(self):
self.strategy.set_settings({'SOCIAL_AUTH_GITHUB_TEAM_ID': '123'})
self.do_login()
def test_partial_pipeline(self):
self.strategy.set_settings({'SOCIAL_AUTH_GITHUB_TEAM_ID': '123'})
self.do_partial_pipeline()
class GithubTeamOAuth2FailTest(GithubOAuth2Test):
backend_path = 'social.backends.github.GithubTeamOAuth2'
def auth_handlers(self, start_url):
url = 'https://api.github.com/teams/123/members/foobar'
HTTPretty.register_uri(HTTPretty.GET, url, status=404,
body='{"message": "Not Found"}',
content_type='application/json')
return super(GithubTeamOAuth2FailTest, self).auth_handlers(
start_url
)
def test_login(self):
self.strategy.set_settings({'SOCIAL_AUTH_GITHUB_TEAM_ID': '123'})
with self.assertRaises(AuthFailed):
self.do_login()
def test_partial_pipeline(self):
self.strategy.set_settings({'SOCIAL_AUTH_GITHUB_TEAM_ID': '123'})
with self.assertRaises(AuthFailed):
self.do_partial_pipeline()
|