当前位置: 首页>>代码示例>>Python>>正文


Python IdentDB.persistent_nameid方法代码示例

本文整理汇总了Python中saml2.ident.IdentDB.persistent_nameid方法的典型用法代码示例。如果您正苦于以下问题:Python IdentDB.persistent_nameid方法的具体用法?Python IdentDB.persistent_nameid怎么用?Python IdentDB.persistent_nameid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在saml2.ident.IdentDB的用法示例。


在下文中一共展示了IdentDB.persistent_nameid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestIdentifier

# 需要导入模块: from saml2.ident import IdentDB [as 别名]
# 或者: from saml2.ident.IdentDB import persistent_nameid [as 别名]
class TestIdentifier():
    def setup_class(self):
        self.id = IdentDB("subject.db", "example.com", "example")
        
    def test_persistent_1(self):
        policy = Policy({
            "default": {
                "name_form": "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
                "nameid_format": NAMEID_FORMAT_PERSISTENT,
                "attribute_restrictions": {
                    "surName": [".*berg"],
                }
            }
        })
        
        nameid = self.id.construct_nameid("foobar", policy,
                                          "urn:mace:example.com:sp:1")
        
        assert _eq(nameid.keyswv(), ['format', 'text', 'sp_name_qualifier',
                                     'name_qualifier'])
        assert nameid.sp_name_qualifier == "urn:mace:example.com:sp:1"
        assert nameid.format == NAMEID_FORMAT_PERSISTENT
        
        id = self.id.find_local_id(nameid)
        
        assert id == "foobar"

    def test_transient_1(self):
        policy = Policy({
            "default": {
                "name_form": "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
                "nameid_format": NAMEID_FORMAT_TRANSIENT,
                "attribute_restrictions": {
                    "surName": [".*berg"],
                }
            }
        })
        nameid = self.id.construct_nameid("foobar", policy,
                                          "urn:mace:example.com:sp:1")
        
        assert _eq(nameid.keyswv(), ['text', 'format', 'sp_name_qualifier',
                                     'name_qualifier'])
        assert nameid.format == NAMEID_FORMAT_TRANSIENT
        
    def test_vo_1(self):
        policy = Policy({
            "default": {
                "name_form": "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
                "nameid_format": NAMEID_FORMAT_PERSISTENT,
                "attribute_restrictions": {
                    "surName": [".*berg"],
                }
            }
        })
        
        name_id_policy = samlp.name_id_policy_from_string(NAME_ID_POLICY_1)
        print(name_id_policy)
        nameid = self.id.construct_nameid("foobar", policy,
                                          'http://vo.example.org/biomed',
                                          name_id_policy)

        print(nameid)
        assert _eq(nameid.keyswv(), ['text', 'sp_name_qualifier', 'format',
                                     'name_qualifier'])
        assert nameid.sp_name_qualifier == 'http://vo.example.org/biomed'
        assert nameid.format == NAMEID_FORMAT_PERSISTENT
        assert nameid.text != "foobar"

    def test_vo_2(self):
        policy = Policy({
            "default": {
                "name_form": "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
                "nameid_format": NAMEID_FORMAT_PERSISTENT,
                "attribute_restrictions": {
                    "surName": [".*berg"],
                }
            }
        })
        
        name_id_policy = samlp.name_id_policy_from_string(NAME_ID_POLICY_2)
        
        nameid = self.id.construct_nameid("foobar", policy,
                                          'http://vo.example.org/design',
                                          name_id_policy)
        
        assert _eq(nameid.keyswv(), ['text', 'sp_name_qualifier', 'format',
                                     'name_qualifier'])
        assert nameid.sp_name_qualifier == 'http://vo.example.org/design'
        assert nameid.format == NAMEID_FORMAT_PERSISTENT
        assert nameid.text != "foobar01"


    def test_persistent_nameid(self):
        sp_id = "urn:mace:umu.se:sp"
        nameid = self.id.persistent_nameid("abcd0001", sp_id)
        remote_id = nameid.text.strip()
        print(remote_id)
        local = self.id.find_local_id(nameid)
        assert local == "abcd0001"

#.........这里部分代码省略.........
开发者ID:lvanderree,项目名称:pysaml2-3,代码行数:103,代码来源:test_33_identifier.py

示例2: TargetIdTestCase

# 需要导入模块: from saml2.ident import IdentDB [as 别名]
# 或者: from saml2.ident.IdentDB import persistent_nameid [as 别名]
class TargetIdTestCase(unittest.TestCase):

    def setup_class(self):
        self.id = IdentDB({})
        self.sp_entity_id = "https://localhost:/sp.xml"
        sp_id = "urn:mace:umu.se:sp"
        self.nameid1_text = "abcd0001"
        self.nameid1 = self.id.persistent_nameid(self.nameid1_text, sp_id)

    def get_aes_128_key(self):
        return os.urandom(16)

    def get_aes_192_key(self):
        return os.urandom(24)

    def get_aes_256_key(self):
        return os.urandom(32)

    def test_create_tid2_json(self):
        tih = TargetIdHandler()
        tid1 = self.nameid1.text.strip()
        tid2_json = tih.tid2_json(tid1, self.sp_entity_id)
        tid2_dict = tih.tid2_dict(tid2_json)
        assert tid2_dict["tid1"] == self.nameid1_text, "Cannot verify tid1."
        assert tid2_dict["sp_entityid"] == self.sp_entity_id, "Cannot verify SP entity id."
        assert tid2_dict["uuid"] is not None and len(tid2_dict["uuid"]) > 0, "Cannot verify SP entity id."

    def test_hash_tid1(self):
        hash_verify = {'md5': 32, 'sha1': 40, 'sha224': 56, 'sha256': 64, 'sha384': 96, 'sha512': 128}
        try:
            TargetIdHandler(h_alg="do_not_exist_alg")
            assert False, "Must be an assert since the alg. do not exist."
        except:
            pass

        tih = TargetIdHandler()
        tid1 = self.nameid1.text.strip()
        tid2_hash = tih.tid2_hash(tid1, self.sp_entity_id)
        assert len(tid2_hash) == 64, "Default is sha256 alg and i should generate a string with length 64."

        for tmp_h_alg in hash_verify:
            tih = TargetIdHandler(h_alg=tmp_h_alg)
            tid1 = self.nameid1.text.strip()
            tid2_hash = tih.tid2_hash(tid1, self.sp_entity_id)
            assert len(tid2_hash) == hash_verify[tmp_h_alg], "%s alg should generate a string with length %d." % \
                                         (tmp_h_alg, hash_verify[tmp_h_alg])

    def test_encrypt_tid1(self):
        tih = TargetIdHandler()
        tid1 = self.nameid1.text.strip()
        tid2_encrypted = tih.tid2_encrypt(tid1, self.sp_entity_id)
        tid2_dict = tih.tid2_decrypt(tid2_encrypted)
        assert tid2_dict["tid1"] == self.nameid1_text, "Cannot verify tid1."
        assert tid2_dict["sp_entityid"] == self.sp_entity_id, "Cannot verify SP entity id."
        assert tid2_dict["uuid"] is not None and len(tid2_dict["uuid"]) > 0, "Cannot verify SP entity id."

    def test_encrypt_alg_1(self):
        for alg in TargetIdHandler.AES_ALG:
            typ, bits, cmode = alg.split("_")
            tih = TargetIdHandler(e_alg=alg)
            tid1 = self.nameid1.text.strip()
            tid2_encrypted = tih.tid2_encrypt(tid1, self.sp_entity_id)
            tid2_dict = tih.tid2_decrypt(tid2_encrypted)
            assert tid2_dict["tid1"] == self.nameid1_text, "Cannot verify tid1."
            assert tid2_dict["sp_entityid"] == self.sp_entity_id, "Cannot verify SP entity id."
            assert tid2_dict["uuid"] is not None and len(tid2_dict["uuid"]) > 0, "Cannot verify SP entity id."

    def test_encrypt_alg_2(self):
        for alg in TargetIdHandler.AES_ALG:
            typ, bits, cmode = alg.split("_")
            iv = os.urandom(16)
            key = os.urandom(int(bits) >> 3)
            tih = TargetIdHandler(e_alg=alg, iv=iv, key=key)
            tid1 = self.nameid1.text.strip()
            tid2_encrypted = tih.tid2_encrypt(tid1, self.sp_entity_id)
            tid2_dict = tih.tid2_decrypt(tid2_encrypted)
            assert tid2_dict["tid1"] == self.nameid1_text, "Cannot verify tid1."
            assert tid2_dict["sp_entityid"] == self.sp_entity_id, "Cannot verify SP entity id."
            assert tid2_dict["uuid"] is not None and len(tid2_dict["uuid"]) > 0, "Cannot verify uuid."

    def test_encrypt_alg_3(self):
        for alg in TargetIdHandler.AES_ALG:
            typ, bits, cmode = alg.split("_")
            iv = os.urandom(16)
            key = os.urandom(int(bits) >> 3)
            tih = TargetIdHandler(e_alg=alg, iv=iv, key=key)
            tid1 = self.nameid1.text.strip()
            tid2_encrypted_1 = tih.tid2_encrypt(tid1, self.sp_entity_id)
            tid2_encrypted_2 = tih.tid2_encrypt(tid1, self.sp_entity_id)
            tid2_dict_1 = tih.tid2_decrypt(tid2_encrypted_1)
            tid2_dict_2 = tih.tid2_decrypt(tid2_encrypted_2)
            assert tid2_encrypted_1 != tid2_encrypted_2, "Two encryption of the same data must never be the same!"
            assert tid2_dict_1["tid1"] == tid2_dict_2["tid1"] == self.nameid1_text, "Cannot verify tid1."
            assert tid2_dict_1["sp_entityid"] == tid2_dict_2["sp_entityid"] == self.sp_entity_id, \
                "Cannot verify SP entity id."
            assert tid2_dict_1["uuid"] != tid2_dict_2["uuid"], "Cannot verify uuid."

    def test_encrypt_alg_4(self):
        for alg in TargetIdHandler.AES_ALG:
            typ, bits, cmode = alg.split("_")
#.........这里部分代码省略.........
开发者ID:rhoerbe,项目名称:pefim-proxy,代码行数:103,代码来源:test_TargetIdTest.py


注:本文中的saml2.ident.IdentDB.persistent_nameid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。