def test_Create_OAuthAuthentication_TwoFactorAuthentication(self): db = Database() db.Initialize() username = '******' # 存在するユーザ名。Token登録済み。TwoFactorSecretあり。 creator = AuthenticationsCreator(db, username) authentications = creator.Create( ) # [OAuthAuthentication, TwoFactorAuthentication] self.assertEqual(list, type(authentications)) self.assertEqual(2, len(authentications)) self.assertEqual(OAuthAuthentication, type(authentications[0])) self.assertEqual(TwoFactorAuthentication, type(authentications[1]))
def test_Create_OAuthAuthentication_BasicAuthentication(self): db = Database() db.Initialize() username = '******' # 存在するユーザ名。Token登録済み。TwoFactorSecretなし。 creator = AuthenticationsCreator(db, username) authentications = creator.Create( ) # [OAuthAuthentication, BasicAuthentication] self.assertEqual(list, type(authentications)) self.assertEqual(2, len(authentications)) self.assertEqual(OAuthAuthentication, type(authentications[0])) self.assertEqual(BasicAuthentication, type(authentications[1]))
def test_Create_OAuthAuthentication_BasicAuthentication_BasicApi(self): db = Database() db.Initialize() username = '******' # 存在するユーザ名。Token登録済み。TwoFactorSecretなし。 token = 'TestToken000' creator = AuthenticationsCreator(db, username) authentications = creator.Create( ) # [OAuthAuthentication, BasicAuthentication] self.assertEqual(list, type(authentications)) self.assertEqual(2, len(authentications)) self.assertEqual(OAuthAuthentication, type(authentications[0])) self.assertEqual(BasicAuthentication, type(authentications[1])) reqp = RequestParameter(db, authentications) # Basic認証のみ使えるAPI http_method = 'POST' # endpoint = 'https://api.github.com/authorizations' endpoint = 'authorizations' params = reqp.Get(http_method, endpoint) print(params) self.assertTrue('headers' in params) self.assertTrue('Time-Zone' in params['headers']) self.assertTrue('Asia/Tokyo' in params['headers']['Time-Zone']) self.assertTrue('User-Agent' in params['headers']) self.assertEqual('', params['headers']['User-Agent']) self.assertTrue('Accept' in params['headers']) self.assertEqual('application/vnd.github.v3+json', params['headers']['Accept']) # self.assertTrue('Authorization' in params['headers']) # self.assertEqual('token ' + token, params['headers']['Authorization']) self.assertTrue('auth' in params) self.assertTrue(tuple, type(params['auth'])) self.assertTrue(2, len(params['auth'])) self.assertTrue(username, params['auth'][0]) db_account = dataset.connect( 'sqlite:///' + './database/res/db/GitHub.Accounts.sqlite3') password = db_account['Accounts'].find_one( Username=username)['Password'] self.assertTrue(username, params['auth'][0]) self.assertTrue(password, params['auth'][1])