示例#1
0
 def test_Create_OAuthAuthentication_TwoFactorAuthentication_TokenApi(self):
     db = Database()
     db.Initialize()
     username = '******'  # 存在するユーザ名。Token登録済み。TwoFactorSecretあり。
     #        token = 'dummy00000000'
     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(TwoFactorAuthentication, type(authentications[1]))
     reqp = RequestParameter(db, authentications)
     # Token認証API
     http_method = 'GET'
     #        endpoint = 'https://api.github.com/user'
     endpoint = 'user'
     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'])
示例#2
0
 def test_Create_UnregisteredException_ConstractorParameter(self):
     db = Database()
     db.Initialize()
     username = '******'  # 存在しないユーザ名
     creator = AuthenticationsCreator(db, username)
     with self.assertRaises(Exception) as e:
         creator.Create()
         self.assertEqual(
             e.msg,
             '指定したユーザ {0} はDBに未登録です。登録してから実行してください。'.format(username))
示例#3
0
 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]))
示例#4
0
 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]))
示例#5
0
 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])
 def __init__(self):
     self.__db = Database()
     self.__db.Initialize()
示例#7
0
 def __init__(self):
     self.__path_dir_this = os.path.abspath(os.path.dirname(__file__))
     self.__db = Database(self.__path_dir_this)
     #        self.__db = Database()
     self.__db.Initialize()