mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 10:51:14 +00:00
Create the ApplicationOAuth class which is responsible for handling a GitHub application's OAuth authorization process.
72 lines
3.5 KiB
Python
72 lines
3.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
############################ Copyrights and license ############################
|
|
# #
|
|
# Copyright 2019 Rigas Papathanasopoulos <rigaspapas@gmail.com> #
|
|
# #
|
|
# This file is part of PyGithub. #
|
|
# http://pygithub.readthedocs.io/ #
|
|
# #
|
|
# PyGithub is free software: you can redistribute it and/or modify it under #
|
|
# the terms of the GNU Lesser General Public License as published by the Free #
|
|
# Software Foundation, either version 3 of the License, or (at your option) #
|
|
# any later version. #
|
|
# #
|
|
# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY #
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
|
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
|
|
# details. #
|
|
# #
|
|
# You should have received a copy of the GNU Lesser General Public License #
|
|
# along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
|
|
# #
|
|
################################################################################
|
|
|
|
from . import Framework
|
|
|
|
|
|
class ApplicationOAuth(Framework.TestCase):
|
|
def setUp(self):
|
|
super().setUp()
|
|
self.CLIENT_ID = "client_id_removed"
|
|
self.CLIENT_SECRET = "client_secret_removed"
|
|
self.app = self.g.get_oauth_application(self.CLIENT_ID, self.CLIENT_SECRET)
|
|
|
|
def testLoginURL(self):
|
|
BASE_URL = "https://github.com/login/oauth/authorize"
|
|
sample_uri = "https://myapp.com/some/path"
|
|
sample_uri_encoded = "https%3A%2F%2Fmyapp.com%2Fsome%2Fpath"
|
|
self.assertEqual(
|
|
self.app.get_login_url(), "{}?client_id={}".format(BASE_URL, self.CLIENT_ID)
|
|
)
|
|
self.assertTrue(
|
|
"redirect_uri={}".format(sample_uri_encoded)
|
|
in self.app.get_login_url(redirect_uri=sample_uri)
|
|
)
|
|
self.assertTrue(
|
|
"client_id={}".format(self.CLIENT_ID)
|
|
in self.app.get_login_url(redirect_uri=sample_uri)
|
|
)
|
|
self.assertTrue(
|
|
"state=123abc" in self.app.get_login_url(state="123abc", login="user")
|
|
)
|
|
self.assertTrue(
|
|
"login=user" in self.app.get_login_url(state="123abc", login="user")
|
|
)
|
|
self.assertTrue(
|
|
"client_id={}".format(self.CLIENT_ID)
|
|
in self.app.get_login_url(state="123abc", login="user")
|
|
)
|
|
|
|
def testGetAccessToken(self):
|
|
access_token = self.app.get_access_token(
|
|
"oauth_code_removed", state="state_removed"
|
|
)
|
|
# Test string representation
|
|
self.assertEqual(
|
|
str(access_token), 'AccessToken(type="bearer", token="acces...", scope="")'
|
|
)
|
|
self.assertEqual(access_token.token, "access_token_removed")
|
|
self.assertEqual(access_token.scope, "")
|
|
self.assertEqual(access_token.type, "bearer")
|