Example #1
0
    def test_two(self):
        ldif = StringIO('''\
dn: dc=example,dc=com
objectClass: dcObject
dc: example

dn: cn=foo,dc=example,dc=com
objectClass: a
cn: foo

''')
        d = inmemory.fromLDIFFile(ldif)

        def cb1(db):
            self.assertEquals(
                db.dn,
                distinguishedname.DistinguishedName('dc=example,dc=com'))
            return db.subtree()

        d.addCallback(cb1)

        def cb2(children):
            self.assertEquals(len(children), 2)
            want = [
                distinguishedname.DistinguishedName('dc=example,dc=com'),
                distinguishedname.DistinguishedName(
                    'cn=foo,dc=example,dc=com'),
            ]
            got = [e.dn for e in children]
            self.assertEquals(got, want)

        d.addCallback(cb2)
        return d
Example #2
0
    def __init__(self, spool, ldif):
        config.ScalemailConfig.__init__(self)
        self.config.set('Scalemail', 'spool', spool)

        d = inmemory.fromLDIFFile(StringIO(ldif))
        assert d.called, 'The Deferred must trigger synchronously'
        self.db = d.result
Example #3
0
    def test_two(self):
        ldif = BytesIO(b"""\
dn: dc=example,dc=com
objectClass: dcObject
dc: example

dn: cn=foo,dc=example,dc=com
objectClass: a
cn: foo

""")
        d = inmemory.fromLDIFFile(ldif)

        def cb1(db):
            self.assertEqual(
                db.dn,
                distinguishedname.DistinguishedName("dc=example,dc=com"))
            return db.subtree()

        d.addCallback(cb1)

        def cb2(children):
            self.assertEqual(len(children), 2)
            want = [
                distinguishedname.DistinguishedName("dc=example,dc=com"),
                distinguishedname.DistinguishedName(
                    "cn=foo,dc=example,dc=com"),
            ]
            got = [e.dn for e in children]
            self.assertCountEqual(got, want)

        d.addCallback(cb2)
        return d
Example #4
0
    def test_two(self):
        ldif = StringIO(
            """\
dn: dc=example,dc=com
objectClass: dcObject
dc: example

dn: cn=foo,dc=example,dc=com
objectClass: a
cn: foo

"""
        )
        d = inmemory.fromLDIFFile(ldif)

        def cb1(db):
            self.assertEquals(db.dn, distinguishedname.DistinguishedName("dc=example,dc=com"))
            return db.subtree()

        d.addCallback(cb1)

        def cb2(children):
            self.assertEquals(len(children), 2)
            want = [
                distinguishedname.DistinguishedName("dc=example,dc=com"),
                distinguishedname.DistinguishedName("cn=foo,dc=example,dc=com"),
            ]
            got = [e.dn for e in children]
            self.assertEquals(got, want)

        d.addCallback(cb2)
        return d
Example #5
0
    def test_two(self):
        ldif = BytesIO(b'''\
dn: dc=example,dc=com
objectClass: dcObject
dc: example

dn: cn=foo,dc=example,dc=com
objectClass: a
cn: foo

''')
        d = inmemory.fromLDIFFile(ldif)
        def cb1(db):
            self.assertEqual(
                db.dn,
                distinguishedname.DistinguishedName('dc=example,dc=com'))
            return db.subtree()
        d.addCallback(cb1)
        def cb2(children):
            self.assertEqual(len(children), 2)
            want = [
                distinguishedname.DistinguishedName('dc=example,dc=com'),
                distinguishedname.DistinguishedName('cn=foo,dc=example,dc=com'),
                ]
            got = [e.dn for e in children]
            six.assertCountEqual(self, got, want)
        d.addCallback(cb2)
        return d
Example #6
0
 def __init__(self, config=0):
     global config1, config2, config3
     ldif = None
     if config == 1:
         ldif = config1
     if config == 2:
         ldif = config2
     if config == 3:
         ldif = config3
     if config == 4:
         ldif = config4
     if config == 5:
         ldif = config5
     self.f = BytesIO(ldif)
     d = fromLDIFFile(self.f)
     d.addCallback(self.ldifRead)
Example #7
0
    def test_missingNode(self):
        ldif = BytesIO(b'''\
dn: dc=example,dc=com
objectClass: dcObject
dc: example

dn: cn=foo,ou=nonexisting,dc=example,dc=com
objectClass: a
cn: foo

''')
        d = inmemory.fromLDIFFile(ldif)
        def eb(fail):
            fail.trap(ldaperrors.LDAPNoSuchObject)
            self.failUnlessEqual(
                fail.value.toWire(),
                b'noSuchObject: ou=nonexisting,dc=example,dc=com')
        d.addCallbacks(testutil.mustRaise, eb)
        return d
Example #8
0
    def test_missingNode(self):
        ldif = StringIO('''\
dn: dc=example,dc=com
objectClass: dcObject
dc: example

dn: cn=foo,ou=nonexisting,dc=example,dc=com
objectClass: a
cn: foo

''')
        d = inmemory.fromLDIFFile(ldif)
        def eb(fail):
            fail.trap(ldaperrors.LDAPNoSuchObject)
            self.failUnlessEqual(
                str(fail.value),
                'noSuchObject: ou=nonexisting,dc=example,dc=com')
        d.addCallbacks(testutil.mustRaise, eb)
        return d
Example #9
0
    def test_single(self):
        ldif = StringIO('''\
dn: cn=foo,dc=example,dc=com
objectClass: a
objectClass: b
aValue: a
aValue: b
bValue: c

''')
        d = inmemory.fromLDIFFile(ldif)
        def cb1(db):
            self.assertEquals(
                db.dn,
                distinguishedname.DistinguishedName('cn=foo,dc=example,dc=com'))
            return db.children()
        d.addCallback(cb1)
        d.addCallback(self.assertEquals, [])
        return d
Example #10
0
def main(dataFile, patchFile, outputFile):
    d = inmemory.fromLDIFFile(dataFile)

    def _gotDB(db, patchFile):
        patches = ldifdelta.fromLDIFFile(patchFile)

        # find the right entry to patch
        for p in patches:
            p.patch(db)
        return db

    d.addCallback(_gotDB, patchFile)

    d.addCallback(output, outputFile)
    d.addErrback(error)
    d.addBoth(lambda x: reactor.callWhenRunning(reactor.stop))

    reactor.run()
    sys.exit(exitStatus)
Example #11
0
    def test_single(self):
        ldif = BytesIO(b'''\
dn: cn=foo,dc=example,dc=com
objectClass: a
objectClass: b
aValue: a
aValue: b
bValue: c

''')
        d = inmemory.fromLDIFFile(ldif)
        def cb1(db):
            self.assertEqual(
                db.dn,
                distinguishedname.DistinguishedName('cn=foo,dc=example,dc=com'))
            return db.children()
        d.addCallback(cb1)
        d.addCallback(self.assertEqual, [])
        return d
Example #12
0
 def __init__(self):
     global LDIF
     self.f = BytesIO(LDIF)
     d = fromLDIFFile(self.f)
     d.addCallback(self.ldifRead)
Example #13
0
def _create_db():
    f = StringIO(LDIF)
    db = yield fromLDIFFile(f)
    f.close()
    defer.returnValue(db)
Example #14
0
                inherit=pureber.BERDecoderContext())))

if __name__ == '__main__':
    """
    Demonstration LDAP server; reads LDIF from stdin and
    serves that over LDAP on port 10389.
    """
    from twisted.internet import reactor
    import sys
    log.startLogging(sys.stderr)

    from twisted.python import components
    from ldaptor import inmemory

    class LDAPServerFactory(protocol.ServerFactory):
        def __init__(self, root):
            self.root = root
    components.registerAdapter(lambda x: x.root,
                               LDAPServerFactory,
                               interfaces.IConnectedLDAPEntry)

    def start(db):
        factory = LDAPServerFactory(db)
        factory.protocol = LDAPServer
        reactor.listenTCP(10389, factory)

    d = inmemory.fromLDIFFile(sys.stdin)
    d.addCallback(start)
    d.addErrback(log.err)
    reactor.run()
Example #15
0
 def __init__(self):
     global LDIF
     self.f = BytesIO(LDIF)
     d = fromLDIFFile(self.f)
     d.addCallback(self.ldifRead)
Example #16
0
 def __init__(self):
     self.f = StringIO(LDIF)
     d = fromLDIFFile(self.f)
     d.addCallback(self.ldifRead)
Example #17
0
 def _open(filename):
     f = open(filename)
     d = inmemory.fromLDIFFile(f)
     return d