How to use the bonsai.LDIFReader function in bonsai

To help you get started, we’ve selected a few bonsai examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github noirello / bonsai / tests / test_ldifreader.py View on Github external
def test_comment():
    """ Test parsing comment lines in LDIF files. """
    ldif = "# DN: cn=test\ndn: cn=test\n#Other comment line.\ncn: test\n"
    with StringIO(ldif) as test:
        reader = LDIFReader(test)
        ent = next(reader)
        assert ent.dn == "cn=test"
        assert ent["cn"] == ["test"]
    multiline = "# A long multiline comment\n in an LDIF file.\ndn: cn=test\n"
    with StringIO(multiline) as test:
        reader = LDIFReader(test)
        ent = next(reader)
        assert ent.dn == "cn=test"
github noirello / bonsai / tests / test_ldifreader.py View on Github external
def test_init_params():
    """ Test constructor parameters for LDIFReader. """
    with pytest.raises(TypeError):
        _ = LDIFReader("wrong")
    with pytest.raises(TypeError):
        _ = LDIFReader(StringIO(), max_length=None)
    with pytest.raises(TypeError):
        _ = LDIFReader(BytesIO())
    inp = StringIO()
    ldif = LDIFReader(inp, max_length=100)
    assert ldif.input_file == inp
    assert ldif.max_length == 100
github noirello / bonsai / tests / test_ldifreader.py View on Github external
def test_encoded_attributes():
    """ Test parsing base64 encoded attributes. """
    attr = "test"
    text = "version: 1\ndn: cn=test\ncn:: {0}\n".format(
        base64.b64encode(attr.encode("UTF-8")).decode("UTF-8")
    )
    with StringIO(text) as test:
        reader = LDIFReader(test)
        ent = next(reader)
    assert ent.dn == "cn=test"
    assert ent["cn"][0] == attr
github noirello / bonsai / tests / test_ldifreader.py View on Github external
def test_init_params():
    """ Test constructor parameters for LDIFReader. """
    with pytest.raises(TypeError):
        _ = LDIFReader("wrong")
    with pytest.raises(TypeError):
        _ = LDIFReader(StringIO(), max_length=None)
    with pytest.raises(TypeError):
        _ = LDIFReader(BytesIO())
    inp = StringIO()
    ldif = LDIFReader(inp, max_length=100)
    assert ldif.input_file == inp
    assert ldif.max_length == 100
github noirello / bonsai / tests / test_ldifreader.py View on Github external
def test_url_attribute():
    """ Test URL attribute in LDIF file. """
    text = "dn: cn=test\ncn: test1\njpegPhoto:< file://./testenv/test.jpeg\n"
    with StringIO(text) as test:
        test.name = __file__
        reader = LDIFReader(test)
        ent = next(reader)
    assert ent.dn == "cn=test"
    assert len(ent["jpegPhoto"][0]) == 1959
    assert isinstance(ent["jpegPhoto"][0], bytes)
github noirello / bonsai / tests / test_ldifreader.py View on Github external
def test_changetype():
    """ Test changetype attribute in LDIF file. """
    text = "dn: cn=test\nchangetype: add\ncn: test\n"
    with StringIO(text) as test:
        reader = LDIFReader(test)
        ent = next(reader)
    assert ent.dn == "cn=test"
    assert "cn" in ent
    assert "changetype" not in ent
github noirello / bonsai / tests / test_ldifreader.py View on Github external
def test_init_params():
    """ Test constructor parameters for LDIFReader. """
    with pytest.raises(TypeError):
        _ = LDIFReader("wrong")
    with pytest.raises(TypeError):
        _ = LDIFReader(StringIO(), max_length=None)
    with pytest.raises(TypeError):
        _ = LDIFReader(BytesIO())
    inp = StringIO()
    ldif = LDIFReader(inp, max_length=100)
    assert ldif.input_file == inp
    assert ldif.max_length == 100
github noirello / bonsai / tests / test_ldifreader.py View on Github external
def test_autoload():
    """ Test autoload property. """
    inp = StringIO()
    ldif = LDIFReader(inp)
    assert ldif.autoload == True
    with pytest.raises(TypeError):
        ldif.autoload = "Yes"
    ldif.autoload = False
    assert ldif.autoload == False
github noirello / bonsai / tests / test_ldifreader.py View on Github external
def test_input_file():
    """ Test input_file property. """
    inp = StringIO()
    ldif = LDIFReader(inp)
    assert ldif.input_file == inp
    with pytest.raises(TypeError):
        ldif.input_file = None
    inp2 = StringIO()
    ldif.input_file = inp2
    assert ldif.input_file == inp2
github noirello / bonsai / tests / test_ldifreader.py View on Github external
def test_multiline_attribute():
    """ Test parsing multiline attributes in LDIF. """
    text = "dn: cn=unimaginably+sn=very,ou=very,dc=very,dc=long,\n dc=line\ncn: unimaginably\nsn: very\nsn: long\n"
    with StringIO(text) as test:
        reader = LDIFReader(test)
        ent = next(reader)
    assert ent.dn == "cn=unimaginably+sn=very,ou=very,dc=very,dc=long,dc=line"
    assert ent["cn"][0] == "unimaginably"
    assert ent["sn"][0] == "very"
    assert ent["sn"][1] == "long"