예제 #1
0
    def testAddSubtree(self):
        a = inmemory.ReadOnlyInMemoryLDAPEntry(
            dn=distinguishedname.DistinguishedName('dc=example,dc=com'))
        b = inmemory.ReadOnlyInMemoryLDAPEntry(
            dn=distinguishedname.DistinguishedName('dc=example,dc=com'))

        foo = b.addChild(rdn='ou=foo',
                         attributes={
                             'objectClass': ['a', 'b'],
                             'ou': ['foo'],
                         })
        baz = foo.addChild(rdn='cn=baz',
                           attributes={
                               'objectClass': ['a', 'b'],
                               'cn': ['baz'],
                           })
        bar = b.addChild(rdn='cn=bar',
                         attributes={
                             'objectClass': ['a', 'b'],
                             'cn': ['bar'],
                         })

        d = a.diffTree(b)
        d.addCallback(self.assertEquals, [
            delta.AddOp(bar),
            delta.AddOp(foo),
            delta.AddOp(baz),
        ])
        return d
예제 #2
0
    def testAddChild(self):
        a = inmemory.ReadOnlyInMemoryLDAPEntry(
            dn=distinguishedname.DistinguishedName("dc=example,dc=com"))
        b = inmemory.ReadOnlyInMemoryLDAPEntry(
            dn=distinguishedname.DistinguishedName("dc=example,dc=com"))

        foo = b.addChild(
            rdn="cn=foo",
            attributes={
                "objectClass": ["a", "b"],
                "cn": ["foo"],
            },
        )
        bar = b.addChild(
            rdn="cn=bar",
            attributes={
                "objectClass": ["a", "b"],
                "cn": ["bar"],
            },
        )

        d = a.diffTree(b)
        d.addCallback(
            self.assertEqual,
            [
                delta.AddOp(bar),
                delta.AddOp(foo),
            ],
        )
        return d
예제 #3
0
    def testAddOpInequalityDifferentEntry(self):
        """
        Objects are not equal when the have different LDAP entries.
        """
        first_entry = entry.BaseLDAPEntry(
            dn='ou=First Team, dc=example,dc=com',
            attributes={'foo': ['same', 'attributes']})
        second_entry = entry.BaseLDAPEntry(
            dn='ou=First Team, dc=example,dc=com',
            attributes={'foo': ['other', 'attributes']})

        first = delta.AddOp(first_entry)
        second = delta.AddOp(second_entry)

        self.assertNotEqual(first, second)
예제 #4
0
    def testAddOpHashSimilar(self):
        """
        Objects which are equal have the same hash.
        """
        first_entry = entry.BaseLDAPEntry(
            dn='ou=Duplicate Team, dc=example,dc=com',
            attributes={'foo': ['same', 'attributes']})
        second_entry = entry.BaseLDAPEntry(
            dn='ou=Duplicate Team, dc=example,dc=com',
            attributes={'foo': ['same', 'attributes']})

        first = delta.AddOp(first_entry)
        second = delta.AddOp(second_entry)

        self.assertEqual(hash(first), hash(second))
예제 #5
0
    def testAddOpHashDifferent(self):
        """
        Objects which are not equal have different hash.
        """
        first_entry = entry.BaseLDAPEntry(
            dn='ou=Duplicate Team, dc=example,dc=com',
            attributes={'foo': ['one', 'attributes']})
        second_entry = entry.BaseLDAPEntry(
            dn='ou=Duplicate Team, dc=example,dc=com',
            attributes={'foo': ['other', 'attributes']})

        first = delta.AddOp(first_entry)
        second = delta.AddOp(second_entry)

        self.assertNotEqual(hash(first), hash(second))
예제 #6
0
    def testAddOpEqualitySameEntry(self):
        """
        Objects are equal when the have the same LDAP entry.
        """
        first_entry = entry.BaseLDAPEntry(
            dn='ou=Duplicate Team, dc=example,dc=com',
            attributes={'foo': ['same', 'attributes']})
        second_entry = entry.BaseLDAPEntry(
            dn='ou=Duplicate Team, dc=example,dc=com',
            attributes={'foo': ['same', 'attributes']})

        first = delta.AddOp(first_entry)
        second = delta.AddOp(second_entry)

        self.assertEqual(first, second)
예제 #7
0
    def testAsLDIF(self):
        """
        It will return the LDIF representation of the operation.
        """
        sut = delta.AddOp(
            entry.BaseLDAPEntry(
                dn="dc=example,dc=com",
                attributes={
                    "foo": ["bar", "baz"],
                    "quux": ["thud"],
                },
            ))

        result = sut.asLDIF()

        self.assertEqual(
            b"""dn: dc=example,dc=com
changetype: add
foo: bar
foo: baz
quux: thud

""",
            result,
        )
예제 #8
0
    def testAdd(self):
        proto = LDIFDeltaDriver()
        proto.dataReceived(b"""\
version: 1
dn: cn=foo,dc=example,dc=com
changetype: add
foo: bar
thud: quux
thud: baz

""")
        proto.connectionLost()
        self.assertEqual(
            proto.listOfCompleted,
            [
                delta.AddOp(
                    entry.BaseLDAPEntry(
                        dn=b"cn=foo,dc=example,dc=com",
                        attributes={
                            b"foo": [b"bar"],
                            b"thud": [b"quux", b"baz"],
                        },
                    ))
            ],
        )
예제 #9
0
    def testAddOpHashSimilar(self):
        """
        Objects which are equal have the same hash.
        """
        first_entry = entry.BaseLDAPEntry(
            dn="ou=Duplicate Team, dc=example,dc=com",
            attributes={"foo": ["same", "attributes"]},
        )
        second_entry = entry.BaseLDAPEntry(
            dn="ou=Duplicate Team, dc=example,dc=com",
            attributes={"foo": ["same", "attributes"]},
        )

        first = delta.AddOp(first_entry)
        second = delta.AddOp(second_entry)

        self.assertEqual(hash(first), hash(second))
예제 #10
0
    def testAddOpInequalityDifferentEntry(self):
        """
        Objects are not equal when the have different LDAP entries.
        """
        first_entry = entry.BaseLDAPEntry(
            dn="ou=First Team, dc=example,dc=com",
            attributes={"foo": ["same", "attributes"]},
        )
        second_entry = entry.BaseLDAPEntry(
            dn="ou=First Team, dc=example,dc=com",
            attributes={"foo": ["other", "attributes"]},
        )

        first = delta.AddOp(first_entry)
        second = delta.AddOp(second_entry)

        self.assertNotEqual(first, second)
예제 #11
0
    def testAddOpEqualitySameEntry(self):
        """
        Objects are equal when the have the same LDAP entry.
        """
        first_entry = entry.BaseLDAPEntry(
            dn="ou=Duplicate Team, dc=example,dc=com",
            attributes={"foo": ["same", "attributes"]},
        )
        second_entry = entry.BaseLDAPEntry(
            dn="ou=Duplicate Team, dc=example,dc=com",
            attributes={"foo": ["same", "attributes"]},
        )

        first = delta.AddOp(first_entry)
        second = delta.AddOp(second_entry)

        self.assertEqual(first, second)
예제 #12
0
    def testAddOpHashDifferent(self):
        """
        Objects which are not equal have different hash.
        """
        first_entry = entry.BaseLDAPEntry(
            dn="ou=Duplicate Team, dc=example,dc=com",
            attributes={"foo": ["one", "attributes"]},
        )
        second_entry = entry.BaseLDAPEntry(
            dn="ou=Duplicate Team, dc=example,dc=com",
            attributes={"foo": ["other", "attributes"]},
        )

        first = delta.AddOp(first_entry)
        second = delta.AddOp(second_entry)

        self.assertNotEqual(hash(first), hash(second))
예제 #13
0
    def testAddOpInequalityNoEntryObject(self):
        """
        Objects is not equal with random objects.
        """
        team_entry = entry.BaseLDAPEntry(
            dn='ou=Duplicate Team, dc=example,dc=com',
            attributes={'foo': ['same', 'attributes']})
        sut = delta.AddOp(team_entry)

        self.assertNotEqual(sut, {'foo': ['same', 'attributes']})
예제 #14
0
    def testAddOpInequalityNoEntryObject(self):
        """
        Objects is not equal with random objects.
        """
        team_entry = entry.BaseLDAPEntry(
            dn="ou=Duplicate Team, dc=example,dc=com",
            attributes={"foo": ["same", "attributes"]},
        )
        sut = delta.AddOp(team_entry)

        self.assertNotEqual(sut, {"foo": ["same", "attributes"]})
예제 #15
0
 def testAddOp_DNExists(self):
     foo2 = entry.BaseLDAPEntry(
         dn='cn=foo,ou=metasyntactic,dc=example,dc=com',
         attributes={'foo': ['bar', 'baz'],
                     'quux': ['thud']})
     op = delta.AddOp(foo2)
     d = op.patch(self.root)
     def eb(fail):
         fail.trap(ldaperrors.LDAPEntryAlreadyExists)
     d.addCallbacks(testutil.mustRaise, eb)
     return d
예제 #16
0
    def testSimple(self):
        op=delta.AddOp(entry.BaseLDAPEntry(
            dn='dc=example,dc=com',
            attributes={'foo': ['bar', 'baz'],
                        'quux': ['thud']}))
        self.assertEquals(op.asLDIF(),
                          """\
dn: dc=example,dc=com
changetype: add
foo: bar
foo: baz
quux: thud

""")
예제 #17
0
    def testRepr(self):
        """
        Getting string representation
        """
        sut = delta.AddOp(entry.BaseLDAPEntry(
            dn='dc=example,dc=com',
            attributes={
                'bar': ['foo'],
                'foo': ['bar'],
            },
        ))

        self.assertEqual(repr(sut), "AddOp(BaseLDAPEntry('dc=example,dc=com', "
                                    "{'bar': ['foo'], 'foo': ['bar']}))")
예제 #18
0
    def testAdd(self):
        proto = LDIFDeltaDriver()
        proto.dataReceived("""\
version: 1
dn: cn=foo,dc=example,dc=com
changetype: add
foo: bar
thud: quux
thud: baz

""")
        proto.connectionLost()
        self.assertEqual(proto.listOfCompleted,
                         [delta.AddOp(entry.BaseLDAPEntry(
            dn='cn=foo,dc=example,dc=com',
            attributes={
            'foo': ['bar'],
            'thud': ['quux', 'baz'],
            }))])
예제 #19
0
    def testAddOp_DNExists(self):
        """
        It fails to perform the `add` operation for an existing entry.
        """
        root = self.getRoot()
        root.addChild(rdn='ou=Existing Team',
                      attributes={
                          'objectClass': ['a', 'b'],
                          'ou': ['HR'],
                      })

        hr_entry = entry.BaseLDAPEntry(
            dn='ou=Existing Team, dc=example,dc=com',
            attributes={'foo': ['dont', 'care']})
        sut = delta.AddOp(hr_entry)

        deferred = sut.patch(root)

        failure = self.failureResultOf(deferred)
        self.assertIsInstance(failure.value, ldaperrors.LDAPEntryAlreadyExists)
예제 #20
0
    def state_IN_ADD_ENTRY(self, line):
        assert self.dn is not None, "self.dn must be set when in entry"
        assert self.data is not None, "self.data must be set when in entry"

        if line == b"":
            # end of entry
            if not self.data:
                raise LDIFDeltaAddMissingAttributesError(self.dn)
            self.mode = ldifprotocol.WAIT_FOR_DN
            o = delta.AddOp(entry.BaseLDAPEntry(dn=self.dn, attributes=self.data))
            self.dn = None
            self.data = None
            self.gotEntry(o)
            return

        key, val = self._parseLine(line)

        if not key in self.data:
            self.data[key] = []

        self.data[key].append(val)
예제 #21
0
    def testAsLDIF(self):
        """
        It will return the LDIF representation of the operation.
        """
        sut =delta.AddOp(entry.BaseLDAPEntry(
            dn='dc=example,dc=com',
            attributes={
                'foo': ['bar', 'baz'],
                'quux': ['thud'],
                },
            ))

        result = sut.asLDIF()

        self.assertEqual(b"""dn: dc=example,dc=com
changetype: add
foo: bar
foo: baz
quux: thud

""",
        result)
예제 #22
0
    def testAddOp_DNExists(self):
        """
        It fails to perform the `add` operation for an existing entry.
        """
        root = self.getRoot()
        root.addChild(
            rdn="ou=Existing Team",
            attributes={
                "objectClass": ["a", "b"],
                "ou": ["HR"],
            },
        )

        hr_entry = entry.BaseLDAPEntry(
            dn="ou=Existing Team, dc=example,dc=com",
            attributes={"foo": ["dont", "care"]},
        )
        sut = delta.AddOp(hr_entry)

        deferred = sut.patch(root)

        failure = self.failureResultOf(deferred)
        self.assertIsInstance(failure.value, ldaperrors.LDAPEntryAlreadyExists)
예제 #23
0
 def cb2(r):
     d = self.root.diffTree(other)
     d.addCallback(self.assertEqual, [delta.AddOp(r)])
     return d
예제 #24
0
 def _gotSubtree(l, result):
     for c in l:
         o = delta.AddOp(c)
         result.append(o)
     return result