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


Python IdentityManagementServiceClient.invalidate_authentication_token方法代碼示例

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


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

示例1: test_non_anonymous_resource_registry_operations_with_token

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

#.........這裏部分代碼省略.........
        self.assertGreaterEqual(len(response_data[0]), 20)  # This is a resource_id
        inst_id = str(response_data[0])

        inst_obj = rr.read(inst_id)
        self.assertEquals(inst_obj.type_, RT.InstrumentDevice)
        self.assertEquals(inst_obj.name, "Instrument1")
        self.assertEquals(inst_obj.visibility, ResourceVisibilityEnum.OWNER)

        act_objs, assocs = rr.find_objects(inst_id, PRED.hasOwner, RT.ActorIdentity, id_only=False)
        self.assertEquals(len(act_objs), 1)
        self.assertEquals(act_objs[0]._id, actor_id)

        # Anonymous query should not show the resource anymore
        response = self.test_app.get("/ion-service/resource_registry/find_resources?name=Instrument1&id_only=True")
        self.check_response_headers(response)
        self.assertIn(GATEWAY_RESPONSE, response.json["data"])
        response_data = response.json["data"][GATEWAY_RESPONSE]
        self.assertEqual(len(response_data), 2)
        self.assertEqual(len(response_data[0]), 0)

        # Authenticated request with owner shows resource
        response = self.test_app.get(
            "/ion-service/resource_registry/find_resources?name=Instrument1&id_only=True&requester=" + actor_id
        )
        self.check_response_headers(response)
        self.assertIn(GATEWAY_RESPONSE, response.json["data"])
        response_data = response.json["data"][GATEWAY_RESPONSE]
        self.assertEqual(len(response_data), 2)
        self.assertEqual(len(response_data[0]), 1)
        self.assertEqual(len(response_data[1]), 1)
        self.assertEqual(response_data[0][0], inst_id)

        token_str = id_client.create_authentication_token(actor_id, validity=2)

        # Request with authentication token for owner shows resource
        response = self.test_app.get(
            "/ion-service/resource_registry/find_resources?name=Instrument1&id_only=True&authtoken=" + token_str
        )
        self.check_response_headers(response)
        self.assertIn(GATEWAY_RESPONSE, response.json["data"])
        response_data = response.json["data"][GATEWAY_RESPONSE]
        self.assertEqual(len(response_data), 2)
        self.assertEqual(len(response_data[0]), 1)
        self.assertEqual(len(response_data[1]), 1)
        self.assertEqual(response_data[0][0], inst_id)

        gevent.sleep(2.1)

        # Request with expired authentication token for owner does not show resource (no error though)
        response = self.test_app.get(
            "/ion-service/resource_registry/find_resources?name=Instrument1&id_only=True&authtoken=" + token_str
        )
        self.check_response_headers(response)
        self.assertIn(GATEWAY_RESPONSE, response.json["data"])
        response_data = response.json["data"][GATEWAY_RESPONSE]
        self.assertEqual(len(response_data), 2)
        self.assertEqual(len(response_data[0]), 0)

        # Request with valid authentication token for different user does not show resource
        actor_id2, _ = rr.create(IonObject(RT.ActorIdentity, name="Actor2"))
        token_str2 = id_client.create_authentication_token(actor_id2, validity=2)

        response = self.test_app.get(
            "/ion-service/resource_registry/find_resources?name=Instrument1&id_only=True&authtoken=" + token_str2
        )
        self.check_response_headers(response)
        self.assertIn(GATEWAY_RESPONSE, response.json["data"])
        response_data = response.json["data"][GATEWAY_RESPONSE]
        self.assertEqual(len(response_data), 2)
        self.assertEqual(len(response_data[0]), 0)

        token_str3 = id_client.create_authentication_token(actor_id, validity=2)

        # Request with new authentication token for owner shows resource
        response = self.test_app.get(
            "/ion-service/resource_registry/find_resources?name=Instrument1&id_only=True&authtoken=" + token_str3
        )
        self.check_response_headers(response)
        self.assertIn(GATEWAY_RESPONSE, response.json["data"])
        response_data = response.json["data"][GATEWAY_RESPONSE]
        self.assertEqual(len(response_data), 2)
        self.assertEqual(len(response_data[0]), 1)
        self.assertEqual(len(response_data[1]), 1)
        self.assertEqual(response_data[0][0], inst_id)

        id_client.invalidate_authentication_token(token_str3)

        response = self.test_app.get(
            "/ion-service/resource_registry/find_resources?name=Instrument1&id_only=True&authtoken=" + token_str3
        )
        self.check_response_headers(response)
        self.assertIn(GATEWAY_RESPONSE, response.json["data"])
        response_data = response.json["data"][GATEWAY_RESPONSE]
        self.assertEqual(len(response_data), 2)
        self.assertEqual(len(response_data[0]), 0)

        # Cleanup
        rr.delete(inst_id)
        rr.delete(actor_id2)
        id_client.delete_actor_identity(actor_id)
開發者ID:edwardhunter2,項目名稱:coi-services,代碼行數:104,代碼來源:test_service_gateway_service.py

示例2: TestIdentityManagementServiceInt

# 需要導入模塊: from interface.services.coi.iidentity_management_service import IdentityManagementServiceClient [as 別名]
# 或者: from interface.services.coi.iidentity_management_service.IdentityManagementServiceClient import invalidate_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.invalidate_authentication_token方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。