當前位置: 首頁>>代碼示例>>Python>>正文


Python IdentityManagementServiceClient.read_authentication_token方法代碼示例

本文整理匯總了Python中interface.services.coi.iidentity_management_service.IdentityManagementServiceClient.read_authentication_token方法的典型用法代碼示例。如果您正苦於以下問題:Python IdentityManagementServiceClient.read_authentication_token方法的具體用法?Python IdentityManagementServiceClient.read_authentication_token怎麽用?Python IdentityManagementServiceClient.read_authentication_token使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在interface.services.coi.iidentity_management_service.IdentityManagementServiceClient的用法示例。


在下文中一共展示了IdentityManagementServiceClient.read_authentication_token方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestIdentityManagementServiceInt

# 需要導入模塊: from interface.services.coi.iidentity_management_service import IdentityManagementServiceClient [as 別名]
# 或者: from interface.services.coi.iidentity_management_service.IdentityManagementServiceClient import read_authentication_token [as 別名]

#.........這裏部分代碼省略.........
        # Try merging the account again
        with self.assertRaises(BadRequest):
            self.identity_management_service.complete_account_merge(token, headers={'ion-actor-id':id})

        # Signon again and verify the two accounts have been merged
        id, valid_until, registered = self.identity_management_service.signon(certificate, True)
        self.assertTrue(registered)
        id_2, valid_until_2, registered_2 = self.identity_management_service.signon(certificate_2, True)
        self.assertTrue(registered_2)

        # Validate the two accounts are the same
        self.assertEqual(id, id_2, "The two accounts should have the same id")

        # Try to merge to your own account
        with self.assertRaises(BadRequest):
            token = self.identity_management_service.initiate_account_merge("[email protected]",  headers={'ion-actor-id':id})

        #  Done testing. Delete user
        self.identity_management_service.delete_user_info(user_info_id)
        self.identity_management_service.unregister_user_credentials(id, subject)
        self.identity_management_service.delete_actor_identity(id)

    def test_auth_tokens(self):
        # Note: test of service gateway token functionality is in SGS test

        rr = self.resource_registry

        actor_identity_obj = IonObject("ActorIdentity", {"name": self.subject})
        actor_id = self.identity_management_service.create_actor_identity(actor_identity_obj)

        user_info_obj = IonObject("UserInfo", {"name": "Foo"})
        user_info_id = self.identity_management_service.create_user_info(actor_id, user_info_obj)

        token_str = self.identity_management_service.create_authentication_token(actor_id, validity=10000)
        self.assertIsInstance(token_str, str)
        self.assertGreaterEqual(len(token_str), 25)

        token_info = self.identity_management_service.check_authentication_token(token_str)
        self.assertEquals(token_info["actor_id"], actor_id)

        token_info = self.identity_management_service.check_authentication_token(token_str)
        self.assertGreaterEqual(int(token_info["expiry"]), get_ion_ts_millis())

        with self.assertRaises(BadRequest):
            self.identity_management_service.create_authentication_token(actor_id="", validity=10000)

        with self.assertRaises(BadRequest):
            self.identity_management_service.create_authentication_token(user_info_id, validity=10000)

        with self.assertRaises(BadRequest):
            self.identity_management_service.create_authentication_token(actor_id, validity="FOO")

        with self.assertRaises(BadRequest):
            self.identity_management_service.create_authentication_token(actor_id, validity=-200)

        cur_time = get_ion_ts_millis()

        with self.assertRaises(BadRequest):
            self.identity_management_service.create_authentication_token(actor_id, start_time=str(cur_time-100000), validity=50)

        with self.assertRaises(BadRequest):
            self.identity_management_service.create_authentication_token(actor_id, validity=35000000)

        with self.assertRaises(NotFound):
            self.identity_management_service.check_authentication_token("UNKNOWN")

        token_str2 = self.identity_management_service.create_authentication_token(actor_id, validity=1)
        token_info = self.identity_management_service.check_authentication_token(token_str2)

        gevent.sleep(1.1)

        with self.assertRaises(Unauthorized):
            self.identity_management_service.check_authentication_token(token_str2)

        token = self.identity_management_service.read_authentication_token(token_str2)

        token.expires = str(cur_time + 5000)
        self.identity_management_service.update_authentication_token(token)
        token_info = self.identity_management_service.check_authentication_token(token_str2)

        token_str3 = self.identity_management_service.create_authentication_token(actor_id, validity=2)
        token_info = self.identity_management_service.check_authentication_token(token_str3)

        self.identity_management_service.invalidate_authentication_token(token_str3)

        with self.assertRaises(Unauthorized):
            self.identity_management_service.check_authentication_token(token_str3)

        token = self.identity_management_service.read_authentication_token(token_str3)
        self.assertEquals(token.token_string, token_str3)
        self.assertIn(token_str3, token._id)

        token.status = "OPEN"
        self.identity_management_service.update_authentication_token(token)

        token_info = self.identity_management_service.check_authentication_token(token_str3)

        # Cleanup
        self.identity_management_service.delete_user_info(user_info_id)
        self.identity_management_service.delete_actor_identity(actor_id)
開發者ID:ednad,項目名稱:coi-services,代碼行數:104,代碼來源:test_identity_management_service.py


注:本文中的interface.services.coi.iidentity_management_service.IdentityManagementServiceClient.read_authentication_token方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。