def testDeleteSubtree(self): a = inmemory.ReadOnlyInMemoryLDAPEntry( dn=distinguishedname.DistinguishedName('dc=example,dc=com')) b = inmemory.ReadOnlyInMemoryLDAPEntry( dn=distinguishedname.DistinguishedName('dc=example,dc=com')) foo=a.addChild( rdn='ou=foo', attributes={ 'objectClass': ['a', 'b'], 'ou': ['foo'], }) baz=foo.addChild( rdn='cn=baz', attributes={ 'objectClass': ['a', 'b'], 'cn': ['baz'], }) bar=a.addChild( rdn='cn=bar', attributes={ 'objectClass': ['a', 'b'], 'cn': ['bar'], }) d = a.diffTree(b) d.addCallback(self.assertEquals, [ delta.DeleteOp(bar), delta.DeleteOp(baz), delta.DeleteOp(foo), ]) return d
def testNoChange(self): a = inmemory.ReadOnlyInMemoryLDAPEntry('dc=example,dc=com', { 'dc': ['example'], }) b = inmemory.ReadOnlyInMemoryLDAPEntry('dc=example,dc=com', { 'dc': ['example'], }) d = a.diffTree(b) d.addCallback(self.assertEquals, []) return d
def setUp(self): self.root = inmemory.ReadOnlyInMemoryLDAPEntry(dn='dc=example,dc=com', attributes={ 'dc': 'example', }) self.stuff = self.root.addChild(rdn='ou=stuff', attributes={ 'objectClass': ['a', 'b'], 'ou': ['stuff'], }) self.thingie = self.stuff.addChild(rdn='cn=thingie', attributes={ 'objectClass': ['a', 'b'], 'cn': ['thingie'], }) self.another = self.stuff.addChild(rdn='cn=another', attributes={ 'objectClass': ['a', 'b'], 'cn': ['another'], }) server = ldapserver.LDAPServer() server.factory = self.root server.transport = proto_helpers.StringTransport() server.connectionMade() self.server = server
def test_modifyDN_rdnOnly_noDeleteOldRDN_success(self): newrdn = 'cn=thingamagic' self.server.dataReceived( str( pureldap.LDAPMessage(pureldap.LDAPModifyDNRequest( entry=self.thingie.dn, newrdn=newrdn, deleteoldrdn=False), id=2))) self.assertEquals( self.server.transport.value(), str( pureldap.LDAPMessage(pureldap.LDAPModifyDNResponse( resultCode=ldaperrors.Success.resultCode), id=2)), ) # tree changed d = self.stuff.children() d.addCallback( self.assertEquals, sets.Set([ self.another, inmemory.ReadOnlyInMemoryLDAPEntry( '%s,ou=stuff,dc=example,dc=com' % newrdn, { 'objectClass': ['a', 'b'], 'cn': ['thingamagic', 'thingie'] }), ])) return d
def test_modify(self): self.server.dataReceived( str( pureldap.LDAPMessage(pureldap.LDAPModifyRequest( self.stuff.dn, modification=[ delta.Add('foo', ['bar']).asLDAP(), ], ), id=2))) self.assertEquals( self.server.transport.value(), str( pureldap.LDAPMessage(pureldap.LDAPModifyResponse( resultCode=ldaperrors.Success.resultCode), id=2)), ) # tree changed self.assertEquals( self.stuff, inmemory.ReadOnlyInMemoryLDAPEntry('ou=stuff,dc=example,dc=com', { 'objectClass': ['a', 'b'], 'ou': ['stuff'], 'foo': ['bar'] }))
def test_add_success(self): dn = 'cn=new,ou=stuff,dc=example,dc=com' self.server.dataReceived( str( pureldap.LDAPMessage(pureldap.LDAPAddRequest( entry=dn, attributes=[ (pureldap.LDAPAttributeDescription("objectClass"), pureber.BERSet(value=[ pureldap.LDAPAttributeValue('something'), ])), ]), id=2))) self.assertEquals( self.server.transport.value(), str( pureldap.LDAPMessage(pureldap.LDAPAddResponse( resultCode=ldaperrors.Success.resultCode), id=2)), ) # tree changed d = self.stuff.children() d.addCallback(self.assertEquals, [ self.thingie, self.another, inmemory.ReadOnlyInMemoryLDAPEntry( 'cn=new,ou=stuff,dc=example,dc=com', {'objectClass': ['something']}), ]) return d
def test_delete_root(self): newRoot = inmemory.ReadOnlyInMemoryLDAPEntry( dn=distinguishedname.DistinguishedName('dc=example,dc=com')) d = newRoot.delete() def eb(fail): fail.trap(inmemory.LDAPCannotRemoveRootError) d.addCallbacks(testutil.mustRaise, eb) return d
def testRootChange_Add(self): a = inmemory.ReadOnlyInMemoryLDAPEntry('dc=example,dc=com', { 'dc': ['example'], }) b = inmemory.ReadOnlyInMemoryLDAPEntry('dc=example,dc=com', { 'dc': ['example'], 'foo': ['bar'], }) d = a.diffTree(b) d.addCallback(self.assertEquals, [ delta.ModifyOp('dc=example,dc=com', [ delta.Add('foo', ['bar']), ]), ]) return d
def test_lessOrEqual_noMatch(self): o = inmemory.ReadOnlyInMemoryLDAPEntry(dn='cn=foo,dc=example,dc=com', attributes={ 'objectClass': ['a', 'b'], 'aValue': ['b'], 'num': [4], }) result = o.match(pureldap.LDAPFilter_lessOrEqual('num', 3)) self.assertEquals(result, False)
def test_present_noMatch(self): o = inmemory.ReadOnlyInMemoryLDAPEntry(dn='cn=foo,dc=example,dc=com', attributes={ 'objectClass': ['a', 'b'], 'aValue': ['a'], 'bValue': ['b'], }) result = o.match(pureldap.LDAPFilter_present('noSuchValue')) self.assertEquals(result, False)
def test_matchAll(self): o = inmemory.ReadOnlyInMemoryLDAPEntry(dn='cn=foo,dc=example,dc=com', attributes={ 'objectClass': ['a', 'b'], 'aValue': ['a'], 'bValue': ['b'], }) result = o.match(pureldap.LDAPFilterMatchAll) self.assertEquals(result, True)
def test_equality_noMatch(self): o = inmemory.ReadOnlyInMemoryLDAPEntry(dn='cn=foo,dc=example,dc=com', attributes={ 'objectClass': ['a', 'b'], 'aValue': ['a'], 'bValue': ['b'], }) result = o.match( pureldap.LDAPFilter_equalityMatch( attributeDesc=pureber.BEROctetString('aValue'), assertionValue=pureber.BEROctetString('b'))) self.assertEquals(result, False)
def test_substrings_match7(self): o = inmemory.ReadOnlyInMemoryLDAPEntry(dn='cn=foo,dc=example,dc=com', attributes={ 'objectClass': ['a', 'b'], 'aValue': ['Foo'], }) result = o.match( pureldap.LDAPFilter_substrings( type='aValue', substrings=[ pureldap.LDAPFilter_substrings_initial('f'), ])) self.assertEquals(result, True)
def test_not(self): o = inmemory.ReadOnlyInMemoryLDAPEntry(dn='cn=foo,dc=example,dc=com', attributes={ 'objectClass': ['a', 'b'], 'aValue': ['a'], 'bValue': ['b'], }) result = o.match( pureldap.LDAPFilter_not( pureldap.LDAPFilter_or([ pureldap.LDAPFilter_present('cValue'), pureldap.LDAPFilter_present('dValue'), ]))) self.assertEquals(result, True)
def test_notImplemented(self): o = inmemory.ReadOnlyInMemoryLDAPEntry(dn='cn=foo,dc=example,dc=com', attributes={ 'objectClass': ['a', 'b'], 'aValue': ['b'], 'num': [4], }) class UnknownMatch(object): pass unknownMatch = UnknownMatch() self.assertRaises(ldapsyntax.MatchNotImplemented, o.match, unknownMatch)
def test_move_children_sameSuperior(self): d = self.meta.move('ou=moved,dc=example,dc=com') def getChildren(dummy): return self.root.children() d.addCallback(getChildren) d.addCallback(self.assertEquals, [ inmemory.ReadOnlyInMemoryLDAPEntry( dn='ou=moved,dc=example,dc=com', attributes={ 'objectClass': ['a', 'b'], 'ou': ['moved'], }), self.empty, self.oneChild, ]) return d
def test_substrings_noMatch(self): o = inmemory.ReadOnlyInMemoryLDAPEntry(dn='cn=foo,dc=example,dc=com', attributes={ 'objectClass': ['a', 'b'], 'aValue': ['a'], 'bValue': ['b'], }) result = o.match( pureldap.LDAPFilter_substrings( type='aValue', substrings=[ pureldap.LDAPFilter_substrings_initial('bad'), pureldap.LDAPFilter_substrings_any('dog'), pureldap.LDAPFilter_substrings_any('no'), pureldap.LDAPFilter_substrings_final('bone'), ])) self.assertEquals(result, False)
def test_substrings_match5(self): o = inmemory.ReadOnlyInMemoryLDAPEntry(dn='cn=foo,dc=example,dc=com', attributes={ 'objectClass': ['a', 'b'], 'aValue': ['aoeuboeucoeudoeue'], 'bValue': ['b'], }) result = o.match( pureldap.LDAPFilter_substrings( type='aValue', substrings=[ pureldap.LDAPFilter_substrings_initial('a'), pureldap.LDAPFilter_substrings_any('b'), pureldap.LDAPFilter_substrings_any('c'), pureldap.LDAPFilter_substrings_any('d'), pureldap.LDAPFilter_substrings_final('e'), ])) self.assertEquals(result, True)
def setUp(self): self.root = inmemory.ReadOnlyInMemoryLDAPEntry( dn=distinguishedname.DistinguishedName('dc=example,dc=com')) self.meta=self.root.addChild( rdn='ou=metasyntactic', attributes={ 'objectClass': ['a', 'b'], 'ou': ['metasyntactic'], }) self.foo=self.meta.addChild( rdn='cn=foo', attributes={ 'objectClass': ['a', 'b'], 'cn': ['foo'], }) self.bar=self.meta.addChild( rdn='cn=bar', attributes={ 'objectClass': ['a', 'b'], 'cn': ['bar'], }) self.empty=self.root.addChild( rdn='ou=empty', attributes={ 'objectClass': ['a', 'b'], 'ou': ['empty'], }) self.oneChild=self.root.addChild( rdn='ou=oneChild', attributes={ 'objectClass': ['a', 'b'], 'ou': ['oneChild'], }) self.theChild=self.oneChild.addChild( rdn='cn=theChild', attributes={ 'objectClass': ['a', 'b'], 'cn': ['theChild'], })
def setUp(self): db = inmemory.ReadOnlyInMemoryLDAPEntry('', {}) com = db.addChild('dc=com', { 'objectClass': ['dcObject'], 'dc': ['com'], }) com.addChild( 'dc=example', { 'objectClass': ['dcObject'], 'dc': ['example'], 'subschemaSubentry': ['cn=schema'], }) db.addChild( 'cn=schema', { 'objectClass': ['TODO'], 'cn': ['schema'], 'attributeTypes': [test_schema.AttributeType_KnownValues.knownValues[0][0]], 'objectClasses': [ test_schema.OBJECTCLASSES['organization'], test_schema.OBJECTCLASSES['organizationalUnit'], ], }) class LDAPServerFactory(protocol.ServerFactory): protocol = ldapserver.LDAPServer def __init__(self, root): self.root = root components.registerAdapter(lambda x: x.root, LDAPServerFactory, interfaces.IConnectedLDAPEntry) serverFactory = LDAPServerFactory(db) self.client = ldapclient.LDAPClient() server = serverFactory.buildProtocol( address.IPv4Address('TCP', 'localhost', '1024')) util.returnConnected(server, self.client)