예제 #1
0
    def testSimple(self):
        client = LDAPClientTestDriver(
            [
                pureldap.LDAPSearchResultEntry(
                    objectName='',
                    attributes=(
                        ('subschemaSubentry', ['cn=Subschema']),
                        ('bar', ['b', 'c']),
                    ),
                ),
                pureldap.LDAPSearchResultDone(
                    resultCode=0, matchedDN='', errorMessage='')
            ],
            [
                pureldap.LDAPSearchResultEntry(
                    objectName='cn=Subschema',
                    attributes=(
                        ('attributeTypes', [self.cn]),
                        ('objectClasses', [self.dcObject]),
                    ),
                ),
                pureldap.LDAPSearchResultDone(
                    resultCode=0, matchedDN='', errorMessage='')
            ],
        )

        d = fetchschema.fetch(client, 'dc=example,dc=com')
        d.addCallback(self._cb_testSimple, client)
        return d
예제 #2
0
 def test_search_scope_oneLevel(self):
     self.server.dataReceived(
         str(
             pureldap.LDAPMessage(pureldap.LDAPSearchRequest(
                 baseObject='ou=stuff,dc=example,dc=com',
                 scope=pureldap.LDAP_SCOPE_singleLevel,
             ),
                                  id=2)))
     self.assertEquals(
         self.server.transport.value(),
         str(
             pureldap.LDAPMessage(pureldap.LDAPSearchResultEntry(
                 objectName='cn=thingie,ou=stuff,dc=example,dc=com',
                 attributes=[
                     ('objectClass', ['a', 'b']),
                     ('cn', ['thingie']),
                 ]),
                                  id=2)) +
         str(
             pureldap.LDAPMessage(pureldap.LDAPSearchResultEntry(
                 objectName='cn=another,ou=stuff,dc=example,dc=com',
                 attributes=[
                     ('objectClass', ['a', 'b']),
                     ('cn', ['another']),
                 ]),
                                  id=2)) +
         str(
             pureldap.LDAPMessage(
                 pureldap.LDAPSearchResultDone(resultCode=0), id=2)),
     )
예제 #3
0
 def test_search(self):
     server = self.createServer(
         [
             pureldap.LDAPBindResponse(resultCode=0),
         ],
         [
             pureldap.LDAPSearchResultEntry('cn=foo,dc=example,dc=com',
                                            [('a', ['b'])]),
             pureldap.LDAPSearchResultEntry('cn=bar,dc=example,dc=com',
                                            [('b', ['c'])]),
             pureldap.LDAPSearchResultDone(ldaperrors.Success.resultCode),
         ],
     )
     server.dataReceived(
         str(pureldap.LDAPMessage(pureldap.LDAPBindRequest(), id=2)))
     server.dataReceived(
         str(pureldap.LDAPMessage(pureldap.LDAPSearchRequest(), id=3)))
     reactor.iterate()  #TODO
     self.assertEquals(
         server.transport.value(),
         str(
             pureldap.LDAPMessage(
                 pureldap.LDAPBindResponse(resultCode=0), id=2)) + str(
                     pureldap.LDAPMessage(pureldap.LDAPSearchResultEntry(
                         'cn=foo,dc=example,dc=com', [('a', ['b'])]),
                                          id=3)) +
         str(
             pureldap.LDAPMessage(pureldap.LDAPSearchResultEntry(
                 'cn=bar,dc=example,dc=com', [('b', ['c'])]),
                                  id=3)) +
         str(
             pureldap.LDAPMessage(pureldap.LDAPSearchResultDone(
                 ldaperrors.Success.resultCode),
                                  id=3)))
예제 #4
0
 def test_rootDSE(self):
     self.server.dataReceived(
         str(
             pureldap.LDAPMessage(pureldap.LDAPSearchRequest(
                 baseObject='',
                 scope=pureldap.LDAP_SCOPE_baseObject,
                 filter=pureldap.LDAPFilter_present('objectClass'),
             ),
                                  id=2)))
     self.assertEquals(
         self.server.transport.value(),
         str(
             pureldap.LDAPMessage(pureldap.LDAPSearchResultEntry(
                 objectName='',
                 attributes=[
                     ('supportedLDAPVersion', ['3']),
                     ('namingContexts', ['dc=example,dc=com']),
                     ('supportedExtension', [
                         pureldap.LDAPPasswordModifyRequest.oid,
                     ]),
                 ]),
                                  id=2)) +
         str(
             pureldap.LDAPMessage(pureldap.LDAPSearchResultDone(
                 resultCode=ldaperrors.Success.resultCode),
                                  id=2)),
     )
예제 #5
0
    def test_bind_match_success(self):
        server = self.createServer(
            services=[
                'svc1',
                'svc2',
                'svc3',
            ],
            fallback=True,
            responses=[

                # svc1
                [
                    pureldap.LDAPSearchResultEntry(
                        r'cn=svc1+owner=cn\=jack\,dc\=example\,dc\=com,dc=example,dc=com',
                        attributes=[]),
                    pureldap.LDAPSearchResultDone(
                        ldaperrors.Success.resultCode)
                ],
                [
                    pureldap.LDAPBindResponse(
                        resultCode=ldaperrors.Success.resultCode)
                ],
            ])

        server.dataReceived(
            str(
                pureldap.LDAPMessage(pureldap.LDAPBindRequest(
                    dn='cn=jack,dc=example,dc=com', auth='secret'),
                                     id=4)))
        reactor.iterate()  #TODO
        client = server.client

        client.assertSent(
            pureldap.LDAPSearchRequest(
                baseObject='dc=example,dc=com',
                derefAliases=0,
                sizeLimit=0,
                timeLimit=0,
                typesOnly=0,
                filter=ldapfilter.parseFilter(
                    '(&' + '(objectClass=serviceSecurityObject)' +
                    '(owner=cn=jack,dc=example,dc=com)' + '(cn=svc1)' +
                    ('(|(!(validFrom=*))(validFrom<=%s))' % server.now) +
                    ('(|(!(validUntil=*))(validUntil>=%s))' % server.now) +
                    ')'),
                attributes=('1.1', )),
            pureldap.LDAPBindRequest(
                dn=
                r'cn=svc1+owner=cn\=jack\,dc\=example\,dc\=com,dc=example,dc=com',
                auth='secret'),
        )
        self.assertEquals(
            server.transport.value(),
            str(
                pureldap.LDAPMessage(pureldap.LDAPBindResponse(
                    resultCode=ldaperrors.Success.resultCode,
                    matchedDN='cn=jack,dc=example,dc=com'),
                                     id=4)))
예제 #6
0
 def getRootDSE(self, request, reply):
     root = interfaces.IConnectedLDAPEntry(self.factory)
     reply(
         pureldap.LDAPSearchResultEntry(
             objectName='',
             attributes=[
                 ('supportedLDAPVersion', ['3']),
                 ('namingContexts', [str(root.dn)]),
                 ('supportedExtension', [
                     pureldap.LDAPPasswordModifyRequest.oid,
                 ]),
             ],
         ))
     return pureldap.LDAPSearchResultDone(
         resultCode=ldaperrors.Success.resultCode)
예제 #7
0
 def _sendEntryToClient(entry):
     reply(
         pureldap.LDAPSearchResultEntry(
             objectName=str(entry.dn),
             attributes=entry.items(),
         ))
예제 #8
0
    def testDefaultSetting(self):
        """Test that fields get their default values."""

        client = LDAPClientTestDriver(
            # uid==1000 -> free
            [
                pureldap.LDAPSearchResultDone(
                    resultCode=0, matchedDN='', errorMessage=''),
            ],

            # gid==1000 -> taken
            [
                pureldap.LDAPSearchResultEntry(
                    objectName='',
                    attributes=[('objectClass',
                                 ('foo', 'posixAccount', 'bar'))]),
                pureldap.LDAPSearchResultDone(
                    resultCode=0, matchedDN='', errorMessage=''),
            ],
            # gid==1500 -> free
            [
                pureldap.LDAPSearchResultDone(
                    resultCode=0, matchedDN='', errorMessage=''),
            ],

            # gid==1250 -> free
            [
                pureldap.LDAPSearchResultDone(
                    resultCode=0, matchedDN='', errorMessage=''),
            ],

            # gid==1125 -> free
            [
                pureldap.LDAPSearchResultDone(
                    resultCode=0, matchedDN='', errorMessage=''),
            ],

            # gid==1062 -> free
            [
                pureldap.LDAPSearchResultDone(
                    resultCode=0, matchedDN='', errorMessage=''),
            ],
            # gid==1031 -> free
            [
                pureldap.LDAPSearchResultEntry(
                    objectName='',
                    attributes=[('objectClass',
                                 ('foo', 'posixAccount', 'bar'))]),
                pureldap.LDAPSearchResultDone(
                    resultCode=0, matchedDN='', errorMessage=''),
            ],

            # gid==1046 -> free
            [
                pureldap.LDAPSearchResultDone(
                    resultCode=0, matchedDN='', errorMessage=''),
            ],

            # gid==1038 -> taken
            [
                pureldap.LDAPSearchResultEntry(
                    objectName='',
                    attributes=[('objectClass',
                                 ('foo', 'posixAccount', 'bar'))]),
                pureldap.LDAPSearchResultDone(
                    resultCode=0, matchedDN='', errorMessage=''),
            ],

            # gid==1042 -> free
            [
                pureldap.LDAPSearchResultDone(
                    resultCode=0, matchedDN='', errorMessage=''),
            ],

            # gid==1040 -> taken
            [
                pureldap.LDAPSearchResultEntry(
                    objectName='',
                    attributes=[('objectClass',
                                 ('foo', 'posixAccount', 'bar'))]),
                pureldap.LDAPSearchResultDone(
                    resultCode=0, matchedDN='', errorMessage=''),
            ],

            # gid==1041 -> taken
            [
                pureldap.LDAPSearchResultEntry(
                    objectName='',
                    attributes=[('objectClass',
                                 ('foo', 'posixAccount', 'bar'))]),
                pureldap.LDAPSearchResultDone(
                    resultCode=0, matchedDN='', errorMessage=''),
            ],
        )

        o = ldapsyntax.LDAPEntryWithAutoFill(client=client,
                                             dn='cn=foo,dc=example,dc=com',
                                             attributes={
                                                 'objectClass':
                                                 ['posixAccount', 'other'],
                                             })

        d = o.addAutofiller(
            posixAccount.Autofill_posix(baseDN='dc=example,dc=com'))
        d.addCallback(self._cb_testDefaultSetting, client, o)
        return d