Esempio n. 1
0
 def testComplex(self):
     a = entry.BaseLDAPEntry(
         dn='cn=Paula Jensen,ou=Product Development,dc=airius,dc=com',
         attributes={
             'description': ['Something'],
             'telephonenumber': ['+123 456'],
             'facsimiletelephonenumber': ['+1 408 555 9876'],
         })
     b = entry.BaseLDAPEntry(
         dn='cn=Paula Jensen,ou=Product Development,dc=airius,dc=com',
         attributes={
             'postalAddress': ['123 Anystreet $ Sunnyvale, CA $ 94086'],
             'telephonenumber': ['+1 408 555 1234', '+1 408 555 5678'],
         })
     result = a.diff(b)
     self.assertEqual(
         result,
         delta.ModifyOp(
             'cn=Paula Jensen,ou=Product Development,dc=airius,dc=com', [
                 delta.Add('postalAddress',
                           ['123 Anystreet $ Sunnyvale, CA $ 94086']),
                 delta.Delete('description', ['Something']),
                 delta.Delete('facsimiletelephonenumber',
                              ['+1 408 555 9876']),
                 delta.Add('telephonenumber',
                           ['+1 408 555 1234', '+1 408 555 5678']),
                 delta.Delete('telephonenumber', ['+123 456']),
             ]))
Esempio n. 2
0
 def testInequalityDifferentDN(self):
     """
     Entries are not equal if their DNs are not equal
     """
     a = entry.BaseLDAPEntry(dn='dn=foo', attributes={'foo': ['bar']})
     b = entry.BaseLDAPEntry(dn='dn=bar', attributes={'foo': ['bar']})
     self.assertNotEqual(a, b)
Esempio n. 3
0
 def testInequalityDifferentDN(self):
     """
     Entries are not equal if their DNs are not equal
     """
     a = entry.BaseLDAPEntry(dn="dn=foo", attributes={"foo": ["bar"]})
     b = entry.BaseLDAPEntry(dn="dn=bar", attributes={"foo": ["bar"]})
     self.assertNotEqual(a, b)
Esempio n. 4
0
 def testComplex(self):
     a = entry.BaseLDAPEntry(
         dn="cn=Paula Jensen,ou=Product Development,dc=airius,dc=com",
         attributes={
             "description": ["Something"],
             "telephonenumber": ["+123 456"],
             "facsimiletelephonenumber": ["+1 408 555 9876"],
         },
     )
     b = entry.BaseLDAPEntry(
         dn="cn=Paula Jensen,ou=Product Development,dc=airius,dc=com",
         attributes={
             "postalAddress": ["123 Anystreet $ Sunnyvale, CA $ 94086"],
             "telephonenumber": ["+1 408 555 1234", "+1 408 555 5678"],
         },
     )
     result = a.diff(b)
     self.assertEqual(
         result,
         delta.ModifyOp(
             "cn=Paula Jensen,ou=Product Development,dc=airius,dc=com",
             [
                 delta.Add(
                     "postalAddress", ["123 Anystreet $ Sunnyvale, CA $ 94086"]
                 ),
                 delta.Delete("description", ["Something"]),
                 delta.Delete("facsimiletelephonenumber", ["+1 408 555 9876"]),
                 delta.Add(
                     "telephonenumber", ["+1 408 555 1234", "+1 408 555 5678"]
                 ),
                 delta.Delete("telephonenumber", ["+123 456"]),
             ],
         ),
     )
Esempio n. 5
0
 def testDelete_Some_OneType(self):
     a = entry.BaseLDAPEntry(
         dn="dc=foo",
         attributes={
             "foo": ["bar"],
             "baz": ["quux", "thud"],
         },
     )
     b = entry.BaseLDAPEntry(
         dn="dc=foo",
         attributes={
             "foo": ["bar"],
             "baz": ["thud"],
         },
     )
     result = a.diff(b)
     self.assertEqual(
         result,
         delta.ModifyOp(
             "dc=foo",
             [
                 delta.Delete("baz", ["quux"]),
             ],
         ),
     )
Esempio n. 6
0
 def testAdd_NewAndExisting_ManyTypes(self):
     a = entry.BaseLDAPEntry(
         dn="dc=foo",
         attributes={
             "foo": ["bar"],
             "baz": ["quux"],
         },
     )
     b = entry.BaseLDAPEntry(
         dn="dc=foo",
         attributes={
             "foo": ["bar", "thud", "bang"],
             "baz": ["quux", "bar", "stump"],
             "bang": ["thud", "barble"],
         },
     )
     result = a.diff(b)
     self.assertEqual(
         result,
         delta.ModifyOp(
             "dc=foo",
             [
                 delta.Add("bang", ["thud", "barble"]),
                 delta.Add("baz", ["bar", "stump"]),
                 delta.Add("foo", ["thud", "bang"]),
             ],
         ),
     )
Esempio n. 7
0
 def testEqual(self):
     a = entry.BaseLDAPEntry(dn='dc=foo', attributes={
         'foo': ['bar'],
     })
     b = entry.BaseLDAPEntry(dn='dc=foo', attributes={
         'foo': ['bar'],
     })
     result = a.diff(b)
     self.assertEqual(result, None)
Esempio n. 8
0
    def testDeleteOpHashSimilar(self):
        """
        Objects which are equal have the same hash.
        """
        first_entry = entry.BaseLDAPEntry(dn='ou=Team, dc=example,dc=com')
        second_entry = entry.BaseLDAPEntry(dn='ou=Team, dc=example,dc=com')

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

        self.assertEqual(hash(first), hash(second))
Esempio n. 9
0
    def testDeleteOpEqualitySameDN(self):
        """
        Objects are equal when the have the same DN.
        """
        first_entry = entry.BaseLDAPEntry(dn='ou=Team, dc=example,dc=com')
        second_entry = entry.BaseLDAPEntry(dn='ou=Team, dc=example,dc=com')

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

        self.assertEqual(first, second)
Esempio n. 10
0
    def testDeleteOpInequalityDifferentEntry(self):
        """
        DeleteOp objects are not equal when the have different LDAP entries.
        """
        first_entry = entry.BaseLDAPEntry(dn='ou=Team, dc=example,dc=com')
        second_entry = entry.BaseLDAPEntry(dn='ou=Cowboys, dc=example,dc=com')

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

        self.assertNotEqual(first, second)
Esempio n. 11
0
    def testDeleteOpHashDifferent(self):
        """
        Objects which are not equal have different hash.
        """
        first_entry = entry.BaseLDAPEntry(dn='ou=Team, dc=example,dc=com')
        second_entry = entry.BaseLDAPEntry(dn='ou=Cowboys, dc=example,dc=com')

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

        self.assertNotEqual(hash(first), hash(second))
Esempio n. 12
0
 def testAdd_Existing_OneType_OneValue(self):
     a = entry.BaseLDAPEntry(dn='dc=foo', attributes={
         'foo': ['bar'],
     })
     b = entry.BaseLDAPEntry(dn='dc=foo',
                             attributes={
                                 'foo': ['bar', 'quux'],
                             })
     result = a.diff(b)
     self.assertEqual(
         result, delta.ModifyOp('dc=foo', [
             delta.Add('foo', ['quux']),
         ]))
Esempio n. 13
0
    def testEqualitySameType(self):
        """
        It is equal if it has the same DN (case insensitive)
        and same attributes and values.
        """
        a = entry.BaseLDAPEntry(dn='dc=foo', attributes={
            'foo': ['bar'],
        })
        b = entry.BaseLDAPEntry(dn='Dc=Foo', attributes={
            'foo': ['bar'],
        })

        self.assertEqual(a, b)
Esempio n. 14
0
 def testEqual(self):
     a = entry.BaseLDAPEntry(
         dn="dc=foo",
         attributes={
             "foo": ["bar"],
         },
     )
     b = entry.BaseLDAPEntry(
         dn="dc=foo",
         attributes={
             "foo": ["bar"],
         },
     )
     result = a.diff(b)
     self.assertEqual(result, None)
Esempio n. 15
0
 def testDelete_All_OneType(self):
     a = entry.BaseLDAPEntry(dn='dc=foo',
                             attributes={
                                 'foo': ['bar'],
                                 'baz': ['quux', 'thud'],
                             })
     b = entry.BaseLDAPEntry(dn='dc=foo', attributes={
         'foo': ['bar'],
     })
     result = a.diff(b)
     self.assertEqual(
         result,
         delta.ModifyOp('dc=foo', [
             delta.Delete('baz', ['quux', 'thud']),
         ]))
Esempio n. 16
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)
Esempio n. 17
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)
Esempio n. 18
0
 def testAdd_New_OneType_ManyValues(self):
     a = entry.BaseLDAPEntry(dn='dc=foo', attributes={
         'foo': ['bar'],
     })
     b = entry.BaseLDAPEntry(dn='dc=foo',
                             attributes={
                                 'foo': ['bar'],
                                 'baz': ['quux', 'thud', 'foo'],
                             })
     result = a.diff(b)
     self.assertEqual(
         result,
         delta.ModifyOp('dc=foo', [
             delta.Add('baz', ['quux', 'thud', 'foo']),
         ]))
Esempio n. 19
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))
Esempio n. 20
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))
Esempio n. 21
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"],
                        },
                    ))
            ],
        )
Esempio n. 22
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,
        )
Esempio n. 23
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)
Esempio n. 24
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)
Esempio n. 25
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))
Esempio n. 26
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))
Esempio n. 27
0
    def testDeleteOpInequalityNoEntryObject(self):
        """
        DeleteOp objects is not equal with random objects.
        """
        team_entry = entry.BaseLDAPEntry(dn='ou=Team, dc=example,dc=com')

        sut = delta.DeleteOp(team_entry)

        self.assertNotEqual(sut, 'ou=Team, dc=example,dc=com')
Esempio n. 28
0
    def testEqualitySameType(self):
        """
        It is equal if it has the same DN (case insensitive)
        and same attributes and values.
        """
        a = entry.BaseLDAPEntry(
            dn="dc=foo",
            attributes={
                "foo": ["bar"],
            },
        )
        b = entry.BaseLDAPEntry(
            dn="Dc=Foo",
            attributes={
                "foo": ["bar"],
            },
        )

        self.assertEqual(a, b)
Esempio n. 29
0
 def testGetLDIF(self):
     """
     Getting human readable representation of an entry
     """
     sut = entry.BaseLDAPEntry(dn='dc=foo',
                               attributes={
                                   'foo': ['bar'],
                                   'bar': ['foo'],
                               })
     self.assertEqual(sut.getLDIF(), u'dn: dc=foo\nbar: foo\nfoo: bar\n\n')
Esempio n. 30
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']})