예제 #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.assertEquals(
         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']),
             ]))
예제 #2
0
    def testModify(self):
        op=delta.ModifyOp('cn=Paula Jensen, ou=Product Development, dc=airius, dc=com',
                          [
            delta.Add('postaladdress',
                      ['123 Anystreet $ Sunnyvale, CA $ 94086']),
            delta.Delete('description'),
            delta.Replace('telephonenumber', ['+1 408 555 1234', '+1 408 555 5678']),
            delta.Delete('facsimiletelephonenumber', ['+1 408 555 9876']),
            ])
        self.assertEquals(op.asLDIF(),
                          """\
dn: cn=Paula Jensen,ou=Product Development,dc=airius,dc=com
changetype: modify
add: postaladdress
postaladdress: 123 Anystreet $ Sunnyvale, CA $ 94086
-
delete: description
-
replace: telephonenumber
telephonenumber: +1 408 555 1234
telephonenumber: +1 408 555 5678
-
delete: facsimiletelephonenumber
facsimiletelephonenumber: +1 408 555 9876
-

""")
예제 #3
0
 def cb3(got):
     self.assertEquals(got, [
         delta.ModifyOp(
             self.empty.dn,
             [delta.Add('foo', ['bar'])],
         ),
     ])
예제 #4
0
 def testModifyOp_DNNotFound(self):
     op = delta.ModifyOp('cn=nope,dc=example,dc=com',
                         [delta.Add('foo', ['bar'])])
     d = op.patch(self.root)
     def eb(fail):
         fail.trap(ldaperrors.LDAPNoSuchObject)
     d.addCallbacks(testutil.mustRaise, eb)
     return d
예제 #5
0
    def testModification_empty(self):
        proto = LDIFDeltaDriver()
        proto.dataReceived("""\
version: 1
dn: cn=foo,dc=example,dc=com
changetype: modify

""")
        proto.connectionLost()
        self.assertEqual(proto.listOfCompleted,
                         [
            delta.ModifyOp(dn='cn=foo,dc=example,dc=com'),
            ])
예제 #6
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.assertEquals(
         result, delta.ModifyOp('dc=foo', [
             delta.Add('foo', ['quux']),
         ]))
예제 #7
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.assertEquals(
         result,
         delta.ModifyOp('dc=foo', [
             delta.Add('baz', ['quux', 'thud', 'foo']),
         ]))
예제 #8
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.assertEquals(
         result,
         delta.ModifyOp('dc=foo', [
             delta.Delete('baz', ['quux', 'thud']),
         ]))
예제 #9
0
    def testModification_oneAdd(self):
        proto = LDIFDeltaDriver()
        proto.dataReceived("""\
version: 1
dn: cn=foo,dc=example,dc=com
changetype: modify
add: foo
foo: bar
-

""")
        proto.connectionLost()
        self.assertEqual(
            proto.listOfCompleted,
            [delta.ModifyOp(dn='cn=foo,dc=example,dc=com',
                            modifications=[delta.Add('foo', ['bar']),
                                           ]),
             ])
예제 #10
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
예제 #11
0
    def diff(self, other):
        """
        Compute differences between this and another LDAP entry.

        @param other: An LDAPEntry to compare to.

        @return: None if equal, otherwise a ModifyOp that would make
        this entry look like other.
        """
        assert self.dn == other.dn
        if self == other:
            return None

        r = []

        myKeys = sets.Set(self.keys())
        otherKeys = sets.Set(other.keys())

        addedKeys = list(otherKeys - myKeys)
        addedKeys.sort() # for reproducability only
        for added in addedKeys:
            r.append(delta.Add(added, other[added]))

        deletedKeys = list(myKeys - otherKeys)
        deletedKeys.sort() # for reproducability only
        for deleted in deletedKeys:
            r.append(delta.Delete(deleted, self[deleted]))

        sharedKeys = list(myKeys & otherKeys)
        sharedKeys.sort() # for reproducability only
        for shared in sharedKeys:

            addedValues = list(other[shared] - self[shared])
            if addedValues:
                addedValues.sort() # for reproducability only
                r.append(delta.Add(shared, addedValues))

            deletedValues = list(self[shared] - other[shared])
            if deletedValues:
                deletedValues.sort() # for reproducability only
                r.append(delta.Delete(shared, deletedValues))

        return delta.ModifyOp(dn=self.dn, modifications=r)
예제 #12
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.assertEquals(
         result,
         delta.ModifyOp('dc=foo', [
             delta.Add('bang', ['thud', 'barble']),
             delta.Add('baz', ['bar', 'stump']),
             delta.Add('foo', ['thud', 'bang']),
         ]))
예제 #13
0
    def state_WAIT_FOR_MOD_SPEC(self, line):
        if line == '':
            # end of entry
            self.mode = ldifprotocol.WAIT_FOR_DN
            m = delta.ModifyOp(dn=self.dn, modifications=self.modifications)
            self.dn = None
            self.data = None
            self.modifications = None
            self.gotEntry(m)
            return

        key, val = self._parseLine(line)

        if key not in self.MOD_SPEC_TO_DELTA:
            raise LDIFDeltaUnknownModificationError, \
                  (self.dn, key)

        self.mod_spec = key
        self.mod_spec_attr = val
        self.mod_spec_data = []
        self.mode = IN_MOD_SPEC
예제 #14
0
    def testModification_complex(self):
        proto = LDIFDeltaDriver()
        proto.dataReceived("""\
version: 1
dn: cn=foo,dc=example,dc=com
changetype: modify
delete: foo
foo: bar
-
delete: garply
-
add: thud
thud: quux
thud: baz
-
replace: waldo
-
add: foo
foo: baz
-
replace: thud
thud: xyzzy
-
add: silly
-

""")
        proto.connectionLost()
        self.assertEqual(
            proto.listOfCompleted,
            [delta.ModifyOp(dn='cn=foo,dc=example,dc=com',
                            modifications=[delta.Delete('foo', ['bar']),
                                           delta.Delete('garply'),
                                           delta.Add('thud', ['quux', 'baz']),
                                           delta.Replace('waldo'),
                                           delta.Add('foo', ['baz']),
                                           delta.Replace('thud', ['xyzzy']),
                                           delta.Add('silly'),
                                           ]),
             ])