Exemplo 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']),
             ]))
Exemplo n.º 2
0
    def testModification_twoAdds(self):
        proto = LDIFDeltaDriver()
        proto.dataReceived(b"""\
version: 1
dn: cn=foo,dc=example,dc=com
changetype: modify
add: foo
foo: bar
-
add: thud
thud: quux
thud: baz
-

""")
        proto.connectionLost()
        self.assertEqual(
            proto.listOfCompleted,
            [
                delta.ModifyOp(
                    dn=b"cn=foo,dc=example,dc=com",
                    modifications=[
                        delta.Add(b"foo", [b"bar"]),
                        delta.Add(b"thud", [b"quux", b"baz"]),
                    ],
                ),
            ],
        )
Exemplo n.º 3
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"]),
             ],
         ),
     )
Exemplo n.º 4
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"]),
             ],
         ),
     )
Exemplo n.º 5
0
 def cb3(got):
     self.assertEquals(got, [
         delta.ModifyOp(
             self.empty.dn,
             [delta.Add('foo', ['bar'])],
         ),
     ])
Exemplo n.º 6
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.assertEqual,
         [
             delta.ModifyOp(
                 "dc=example,dc=com",
                 [
                     delta.Add("foo", ["bar"]),
                 ],
             ),
         ],
     )
     return d
Exemplo n.º 7
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
-

""")
Exemplo n.º 8
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"]
             },
         ),
     )
Exemplo n.º 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']
             }))
Exemplo n.º 10
0
    def testAdd(self):
        m = delta.Add('foo', ['bar', 'baz'])
        self.assertEqual(m.asLDIF(), b"""\
add: foo
foo: bar
foo: baz
-
""")
Exemplo n.º 11
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
Exemplo n.º 12
0
 def testAdd_New_ManyTypes(self):
     a = entry.BaseLDAPEntry(dn='dc=foo', attributes={
         'foo': ['bar'],
     })
     b = entry.BaseLDAPEntry(dn='dc=foo',
                             attributes={
                                 'foo': ['bar'],
                                 'baz': ['quux'],
                                 'bang': ['thud'],
                             })
     result = a.diff(b)
     self.assertEqual(
         result,
         delta.ModifyOp('dc=foo', [
             delta.Add('bang', ['thud']),
             delta.Add('baz', ['quux']),
         ]))
Exemplo n.º 13
0
    def testModification_complex(self):
        proto = LDIFDeltaDriver()
        proto.dataReceived(b"""\
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=b"cn=foo,dc=example,dc=com",
                    modifications=[
                        delta.Delete(b"foo", [b"bar"]),
                        delta.Delete(b"garply"),
                        delta.Add(b"thud", [b"quux", b"baz"]),
                        delta.Replace(b"waldo"),
                        delta.Add(b"foo", [b"baz"]),
                        delta.Replace(b"thud", [b"xyzzy"]),
                        delta.Add(b"silly"),
                    ],
                ),
            ],
        )
Exemplo n.º 14
0
 def cb3(got):
     self.assertEqual(
         got,
         [
             delta.ModifyOp(
                 self.empty.dn,
                 [delta.Add(b"foo", [b"bar"])],
             ),
         ],
     )
Exemplo n.º 15
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 = set(key for key in self)
        otherKeys = set(key for key in other)

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

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

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

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

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

        return delta.ModifyOp(dn=self.dn, modifications=r)
Exemplo n.º 16
0
    def testInequalityDifferentModifications(self):
        """
        Modify operations with different modifications are not equal
        """
        first = delta.ModifyOp("cn=john,dc=example,dc=com",
                               [delta.Add("description")])

        second = delta.ModifyOp("cn=john,dc=example,dc=com",
                                [delta.Delete("description")])

        self.assertNotEqual(first, second)
Exemplo n.º 17
0
    def testAdd(self):
        m = delta.Add("foo", ["bar", "baz"])
        self.assertEqual(
            m.asLDIF(),
            b"""\
add: foo
foo: bar
foo: baz
-
""",
        )
Exemplo n.º 18
0
    def testModification_complex(self):
        proto = LDIFDeltaDriver()
        proto.dataReceived(b"""\
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=b'cn=foo,dc=example,dc=com',
                           modifications=[
                               delta.Delete(b'foo', [b'bar']),
                               delta.Delete(b'garply'),
                               delta.Add(b'thud', [b'quux', b'baz']),
                               delta.Replace(b'waldo'),
                               delta.Add(b'foo', [b'baz']),
                               delta.Replace(b'thud', [b'xyzzy']),
                               delta.Add(b'silly'),
                           ]),
        ])
Exemplo n.º 19
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']),
         ]))
Exemplo n.º 20
0
    def testAddBase64(self):
        """
        LDIF attribute representation is base64 encoded
        if attribute value contains nonprintable characters
        or starts with reserved characters
        """
        m = delta.Add('attr', [':value1', 'value\n\r2'])
        self.assertEqual(m.asLDIF(),
                         b"""\
add: attr
attr:: OnZhbHVlMQ==
attr:: dmFsdWUKDTI=
-
""")
Exemplo n.º 21
0
    def testModification_twoAdds(self):
        proto = LDIFDeltaDriver()
        proto.dataReceived(b"""\
version: 1
dn: cn=foo,dc=example,dc=com
changetype: modify
add: foo
foo: bar
-
add: thud
thud: quux
thud: baz
-

""")
        proto.connectionLost()
        self.assertEqual(proto.listOfCompleted, [
            delta.ModifyOp(dn=b'cn=foo,dc=example,dc=com',
                           modifications=[
                               delta.Add(b'foo', [b'bar']),
                               delta.Add(b'thud', [b'quux', b'baz']),
                           ]),
        ])
Exemplo n.º 22
0
    def testModifyOp_DNNotFound(self):
        """
        If fail to modify when the RDN does not exists.
        """
        root = self.getRoot()
        sut = delta.ModifyOp(
            'cn=nope,dc=example,dc=com',
            [delta.Add('foo', ['bar'])],
            )

        deferred = sut.patch(root)

        failure = self.failureResultOf(deferred)
        self.assertIsInstance(failure.value, ldaperrors.LDAPNoSuchObject)
Exemplo n.º 23
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
Exemplo n.º 24
0
    def testModification_oneAdd(self):
        proto = LDIFDeltaDriver()
        proto.dataReceived(b"""\
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']),
                           ]),
        ])
Exemplo n.º 25
0
    def testAsLDIF(self):
        """
        It will return a LDIF representation of the contained operations.
        """
        sut = delta.ModifyOp(
            'cn=Paula Jensen, ou=Dev Ops, 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']),
                ]
            )

        result = sut.asLDIF()

        self.assertEqual(b"""dn: cn=Paula Jensen,ou=Dev Ops,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
-

""",
        result,
        )
Exemplo n.º 26
0
    def testAsLDIF(self):
        """
        It will return a LDIF representation of the contained operations.
        """
        sut = delta.ModifyOp(
            "cn=Paula Jensen, ou=Dev Ops, 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"]),
            ],
        )

        result = sut.asLDIF()

        self.assertEqual(
            b"""dn: cn=Paula Jensen,ou=Dev Ops,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
-

""",
            result,
        )
Exemplo n.º 27
0
 def testAdd_Existing_OneType_ManyValues(self):
     a = entry.BaseLDAPEntry(
         dn="dc=foo",
         attributes={
             "foo": ["bar"],
         },
     )
     b = entry.BaseLDAPEntry(
         dn="dc=foo",
         attributes={
             "foo": ["bar", "quux", "thud", "foo"],
         },
     )
     result = a.diff(b)
     self.assertEqual(
         result,
         delta.ModifyOp(
             "dc=foo",
             [
                 delta.Add("foo", ["quux", "thud", "foo"]),
             ],
         ),
     )
Exemplo n.º 28
0
 def testAdd_New_OneType_OneValue(self):
     a = entry.BaseLDAPEntry(
         dn="dc=foo",
         attributes={
             "foo": ["bar"],
         },
     )
     b = entry.BaseLDAPEntry(
         dn="dc=foo",
         attributes={
             "foo": ["bar"],
             "baz": ["quux"],
         },
     )
     result = a.diff(b)
     self.assertEqual(
         result,
         delta.ModifyOp(
             "dc=foo",
             [
                 delta.Add("baz", ["quux"]),
             ],
         ),
     )
Exemplo n.º 29
0
 def update(self, sequence):
     self.ldapObject.journal(delta.Add(self.key, sequence))
     super(JournaledLDAPAttributeSet, self).update(sequence)
Exemplo n.º 30
0
 def add(self, value):
     self.ldapObject.journal(delta.Add(self.key, [value]))
     super(JournaledLDAPAttributeSet, self).add(value)