示例#1
0
 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
示例#2
0
 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
示例#3
0
 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
示例#4
0
 def test_modifyDN_rdnOnly_deleteOldRDN_success(self):
     newrdn = 'cn=thingamagic'
     self.server.dataReceived(
         pureldap.LDAPMessage(
             pureldap.LDAPModifyDNRequest(
                 entry=self.thingie.dn.getText(),
                 newrdn=newrdn,
                 deleteoldrdn=True),
             id=2).toWire())
     self.assertEqual(
         self.server.transport.value(),
         pureldap.LDAPMessage(
             pureldap.LDAPModifyDNResponse(
                 resultCode=ldaperrors.Success.resultCode),
             id=2).toWire())
     # tree changed
     d = self.stuff.children()
     d.addCallback(lambda actual: six.assertCountEqual(
         self,
         actual,
         [
             inmemory.ReadOnlyInMemoryLDAPEntry(
                 '%s,ou=stuff,dc=example,dc=com' % newrdn,
                 {
                     'objectClass': ['a', 'b'],
                     'cn': ['thingamagic']
                 }),
             self.another,
         ]))
     return d
示例#5
0
 def test_modify(self):
     self.server.dataReceived(
         pureldap.LDAPMessage(
             pureldap.LDAPModifyRequest(
                 self.stuff.dn.getText(),
                 modification=[
                     delta.Add('foo', ['bar']).asLDAP(),
                 ]),
             id=2).toWire())
     self.assertEqual(
         self.server.transport.value(),
         pureldap.LDAPMessage(
             pureldap.LDAPModifyResponse(
                 resultCode=ldaperrors.Success.resultCode),
             id=2).toWire())
     # tree changed
     self.assertEqual(
         self.stuff,
         inmemory.ReadOnlyInMemoryLDAPEntry(
             'ou=stuff,dc=example,dc=com',
             {
                 b'objectClass': [b'a', b'b'],
                 b'ou': [b'stuff'],
                 b'foo': [b'bar']
             }))
示例#6
0
    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)
示例#7
0
    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'],
                                               })
示例#8
0
    def test_move_children_newSuperior(self):
        d = self.meta.move('ou=moved,ou=oneChild,dc=example,dc=com')

        def getChildren(dummy):
            return self.root.children()

        d.addCallback(getChildren)
        d.addCallback(self.assertEquals, [
            self.empty,
            self.oneChild,
        ])

        def getChildren2(dummy):
            return self.oneChild.children()

        d.addCallback(getChildren2)
        d.addCallback(self.assertEquals, [
            self.theChild,
            inmemory.ReadOnlyInMemoryLDAPEntry(
                dn='ou=moved,ou=oneChild,dc=example,dc=com',
                attributes={
                    'objectClass': ['a', 'b'],
                    'ou': ['moved'],
                }),
        ])
        return d
示例#9
0
 def test_modify(self):
     self.server.dataReceived(
         pureldap.LDAPMessage(
             pureldap.LDAPModifyRequest(
                 self.stuff.dn.getText(),
                 modification=[
                     delta.Add("foo", ["bar"]).asLDAP(),
                 ],
             ),
             id=2,
         ).toWire())
     self.assertEqual(
         self.server.transport.value(),
         pureldap.LDAPMessage(
             pureldap.LDAPModifyResponse(
                 resultCode=ldaperrors.Success.resultCode),
             id=2,
         ).toWire(),
     )
     # tree changed
     self.assertEqual(
         self.stuff,
         inmemory.ReadOnlyInMemoryLDAPEntry(
             "ou=stuff,dc=example,dc=com",
             {
                 b"objectClass": [b"a", b"b"],
                 b"ou": [b"stuff"],
                 b"foo": [b"bar"]
             },
         ),
     )
示例#10
0
 def test_modifyDN_rdnOnly_deleteOldRDN_success(self):
     newrdn = "cn=thingamagic"
     self.server.dataReceived(
         pureldap.LDAPMessage(
             pureldap.LDAPModifyDNRequest(entry=self.thingie.dn.getText(),
                                          newrdn=newrdn,
                                          deleteoldrdn=True),
             id=2,
         ).toWire())
     self.assertEqual(
         self.server.transport.value(),
         pureldap.LDAPMessage(
             pureldap.LDAPModifyDNResponse(
                 resultCode=ldaperrors.Success.resultCode),
             id=2,
         ).toWire(),
     )
     # tree changed
     d = self.stuff.children()
     d.addCallback(lambda actual: self.assertCountEqual(
         actual,
         [
             inmemory.ReadOnlyInMemoryLDAPEntry(
                 "%s,ou=stuff,dc=example,dc=com" % newrdn,
                 {
                     "objectClass": ["a", "b"],
                     "cn": ["thingamagic"]
                 },
             ),
             self.another,
         ],
     ))
     return d
示例#11
0
 def test_add_success(self):
     dn = "cn=new,ou=stuff,dc=example,dc=com"
     self.server.dataReceived(
         pureldap.LDAPMessage(
             pureldap.LDAPAddRequest(
                 entry=dn,
                 attributes=[(
                     pureldap.LDAPAttributeDescription("objectClass"),
                     pureber.BERSet(
                         value=[pureldap.LDAPAttributeValue("something")]),
                 )],
             ),
             id=2,
         ).toWire())
     self.assertEqual(
         self.server.transport.value(),
         pureldap.LDAPMessage(pureldap.LDAPAddResponse(
             resultCode=ldaperrors.Success.resultCode),
                              id=2).toWire(),
     )
     # tree changed
     d = self.stuff.children()
     d.addCallback(lambda actual: self.assertCountEqual(
         actual,
         [
             self.thingie,
             self.another,
             inmemory.ReadOnlyInMemoryLDAPEntry(
                 b"cn=new,ou=stuff,dc=example,dc=com",
                 {b"objectClass": [b"something"]},
             ),
         ],
     ))
     return d
示例#12
0
 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
示例#13
0
 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.assertEqual(result, True)
示例#14
0
 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)
示例#15
0
 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.assertEqual(result, False)
示例#16
0
 def test_greaterOrEqual_noMatch_nosuchattr(self):
     o = inmemory.ReadOnlyInMemoryLDAPEntry(dn='cn=foo,dc=example,dc=com',
                                            attributes={
                                                'objectClass': ['a', 'b'],
                                                'aValue': ['b'],
                                                'num': [4],
                                            })
     result = o.match(
         pureldap.LDAPFilter_greaterOrEqual(pureber.BEROctetString('foo'),
                                            pureber.BERInteger(42)))
     self.assertEqual(result, False)
示例#17
0
 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.assertEqual(result, True)
示例#18
0
 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.assertEqual(result, False)
示例#19
0
 def test_lessOrEqual_match_equal(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(pureber.BEROctetString('num'),
                                         pureber.BERInteger(4)))
     self.assertEqual(result, True)
示例#20
0
 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.assertEqual(result, False)
示例#21
0
 def test_or_match(self):
     o = inmemory.ReadOnlyInMemoryLDAPEntry(dn='cn=foo,dc=example,dc=com',
                                            attributes={
                                                'objectClass': ['a', 'b'],
                                                'aValue': ['a'],
                                                'bValue': ['b'],
                                            })
     result = o.match(
         pureldap.LDAPFilter_or([
             pureldap.LDAPFilter_present('cValue'),
             pureldap.LDAPFilter_present('bValue'),
         ]))
     self.assertEquals(result, True)
示例#22
0
 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.assertEqual(result, True)