コード例 #1
0
ファイル: dn.py プロジェクト: zpytela/freeipa
 def _rdns_from_value(self, value):
     if isinstance(value, str):
         try:
             if isinstance(value, str):
                 value = val_encode(value)
             rdns = str2dn(value)
         except DECODING_ERROR:
             raise ValueError("malformed RDN string = \"%s\"" % value)
         for rdn in rdns:
             sort_avas(rdn)
     elif isinstance(value, DN):
         rdns = value._copy_rdns()
     elif isinstance(value, (tuple, list, AVA)):
         ava = get_ava(value)
         rdns = [[ava]]
     elif isinstance(value, RDN):
         rdns = [value.to_openldap()]
     elif isinstance(value, cryptography.x509.name.Name):
         rdns = list(reversed([
             [get_ava(
                 ATTR_NAME_BY_OID.get(ava.oid, ava.oid.dotted_string),
                 ava.value) for ava in rdn]
             for rdn in value.rdns
         ]))
         for rdn in rdns:
             sort_avas(rdn)
     else:
         raise TypeError(
             "must be str, unicode, tuple, Name, RDN or DN, got %s instead"
             % type(value))
     return rdns
コード例 #2
0
ファイル: dn.py プロジェクト: zpytela/freeipa
def str2rdn(value):
    try:
        rdns = str2dn(value.encode('utf-8'))
    except DECODING_ERROR:
        raise ValueError("malformed AVA string = \"%s\"" % value)
    if len(rdns) != 1:
        raise ValueError("multiple RDN's specified by \"%s\"" % (value))
    return rdns[0]
コード例 #3
0
def test_dn2str_special():
    dnstring = 'cn=R\\2cW privilege'
    dnstring2 = 'cn=R\\,W privilege'
    expected = [[('cn', 'R,W privilege', 1)]]

    dn = str2dn(dnstring)
    assert dn == expected
    assert dn2str(dn) == dnstring2
    assert dn_ctypes.str2dn(dnstring) == dn
    assert dn_ctypes.dn2str(dn) == dnstring2
コード例 #4
0
def test_str2dn_errors(dnstring):
    with pytest.raises(DECODING_ERROR):
        str2dn(dnstring)
    with pytest.raises(dn_ctypes.DECODING_ERROR):
        dn_ctypes.str2dn(dnstring)
コード例 #5
0
def test_str2dn2str(dnstring, expected):
    dn = str2dn(dnstring)
    assert dn == expected
    assert dn2str(dn) == dnstring
    assert dn_ctypes.str2dn(dnstring) == dn
    assert dn_ctypes.dn2str(dn) == dnstring