示例#1
0
    def testPrimaryGroupId(self):
        """Test that primaryGroupID field is updated based on gidNumber."""
        client = testutil.LDAPClientTestDriver()
        o=ldapsyntax.LDAPEntryWithAutoFill(client=client,
                                            dn='cn=foo,dc=example,dc=com',
                                            attributes={
            'objectClass': ['sambaAccount', 'other'],
            })
        d = o.addAutofiller(sambaAccount.Autofill_samba())
        def cb(dummy):
            client.assertNothingSent()

            o['gidNumber'] = ['1000']
            self.failUnless('primaryGroupID' in o)
            self.failUnlessEqual(o['primaryGroupID'], [str(2*1000+1001)])
            o['gidNumber'] = ['1001']
            self.failUnlessEqual(o['primaryGroupID'], [str(2*1001+1001)])
            o['gidNumber'] = ['1002']
            self.failUnlessEqual(o['primaryGroupID'], [str(2*1002+1001)])
            o['gidNumber'] = ['2000']
            self.failUnlessEqual(o['primaryGroupID'], [str(2*2000+1001)])
            o['gidNumber'] = ['3000']
            self.failUnlessEqual(o['primaryGroupID'], [str(2*3000+1001)])
            o['gidNumber'] = ['0']
            self.failUnlessEqual(o['primaryGroupID'], [str(2*0+1001)])
            o['gidNumber'] = ['16000']
            self.failUnlessEqual(o['primaryGroupID'], [str(2*16000+1001)])
        d.addCallback(cb)
        return d
示例#2
0
    def testDefaultSetting(self):
        """Test that fields get their default values."""
        client = testutil.LDAPClientTestDriver()
        o=ldapsyntax.LDAPEntryWithAutoFill(client=client,
                                           dn='cn=foo,dc=example,dc=com',
                                           attributes={
            'objectClass': ['sambaAccount', 'other'],
            })
        d = o.addAutofiller(sambaAccount.Autofill_samba())
        def cb(dummy):
            client.assertNothingSent()

            self.failUnless('acctFlags' in o)
            self.failUnlessEqual(o['acctFlags'], ['[UX         ]'])

            self.failUnless('pwdLastSet' in o)
            self.failUnlessEqual(o['pwdLastSet'], ['0'])
            self.failUnless('logonTime' in o)
            self.failUnlessEqual(o['logonTime'], ['0'])
            self.failUnless('logoffTime' in o)
            self.failUnlessEqual(o['logoffTime'], ['0'])
            self.failUnless('pwdCanChange' in o)
            self.failUnlessEqual(o['pwdCanChange'], ['0'])
            self.failUnless('pwdMustChange' in o)
            self.failUnlessEqual(o['pwdMustChange'], ['0'])
        d.addCallback(cb)
        return d
示例#3
0
    def testDefaultSetting_fixedPrimaryGroupSID(self):
        """Test that fields get their default values."""
        client = testutil.LDAPClientTestDriver()
        o=ldapsyntax.LDAPEntryWithAutoFill(client=client,
                                           dn='cn=foo,dc=example,dc=com',
                                           attributes={
            'objectClass': ['sambaSamAccount', 'other'],
            })
        d = o.addAutofiller(sambaSamAccount.Autofill_samba(domainSID='foo',
                                                           fixedPrimaryGroupSID=4131312))
        def cb(dummy):
            client.assertNothingSent()

            self.failUnlessEqual(sets.Set(o.keys()), sets.Set([
                'objectClass',
                'sambaAcctFlags',
                'sambaLogoffTime',
                'sambaLogonTime',
                'sambaPwdCanChange',
                'sambaPwdLastSet',
                'sambaPwdMustChange',
                'sambaPrimaryGroupSID',
                ]))

            self.failUnlessEqual(o['sambaPrimaryGroupSID'], ['foo-4131312'])
            self.failUnlessEqual(o['sambaAcctFlags'], ['[UX         ]'])
            self.failUnlessEqual(o['sambaPwdLastSet'], ['0'])
            self.failUnlessEqual(o['sambaLogonTime'], ['0'])
            self.failUnlessEqual(o['sambaLogoffTime'], ['0'])
            self.failUnlessEqual(o['sambaPwdCanChange'], ['0'])
            self.failUnlessEqual(o['sambaPwdMustChange'], ['0'])
        d.addCallback(cb)
        return d
示例#4
0
    def testMustHaveObjectClass(self):
        """Test that Autofill_samba fails unless object is a sambaSamAccount."""
        client = testutil.LDAPClientTestDriver()
        o=ldapsyntax.LDAPEntryWithAutoFill(client=client,
                                           dn='cn=foo,dc=example,dc=com',
                                           attributes={
            'objectClass': ['something', 'other'],
            })
        autoFiller = sambaSamAccount.Autofill_samba(domainSID='foo')
        d = o.addAutofiller(autoFiller)

        def eb(val):
            client.assertNothingSent()
            val.trap(sambaSamAccount.ObjectMissingObjectClassException)
        d.addCallbacks(testutil.mustRaise, eb)
        return d
示例#5
0
    def testSambaPrimaryGroupSID_preExisting(self):
        """Test that sambaPrimaryGroupSID field is updated based on gidNumber."""
        client = testutil.LDAPClientTestDriver()
        o=ldapsyntax.LDAPEntryWithAutoFill(client=client,
                                            dn='cn=foo,dc=example,dc=com',
                                            attributes={
            'objectClass': ['sambaSamAccount', 'other'],
            'gidNumber': ['1000'],
            })
        d = o.addAutofiller(sambaSamAccount.Autofill_samba(domainSID='foo'))
        def cb(dummy):
            client.assertNothingSent()

            self.failUnless('sambaPrimaryGroupSID' in o)
            self.failUnlessEqual(o['sambaPrimaryGroupSID'], ['foo-%s' % (2*1000+1001)])
        d.addCallback(cb)
        return d
    def testMustHaveObjectClass(self):
        """Test that Autofill_posix fails unless object is a posixAccount."""
        client = LDAPClientTestDriver()
        o = ldapsyntax.LDAPEntryWithAutoFill(client=client,
                                             dn='cn=foo,dc=example,dc=com',
                                             attributes={
                                                 'objectClass':
                                                 ['something', 'other'],
                                             })
        autoFiller = posixAccount.Autofill_posix(baseDN='dc=example,dc=com')
        d = o.addAutofiller(autoFiller)

        def _cbMustRaise(_):
            raise unittest.FailTest('Should have raised an exception')

        def _eb(fail):
            client.assertNothingSent()
            fail.trap(autofill.ObjectMissingObjectClassException)
            return None

        d.addCallbacks(_cbMustRaise, _eb)
        return d
示例#7
0
    def testSimpleSum(self):
        """A simple autofiller that calculates sums of attributes should work.."""
        client = LDAPClientTestDriver()
        o = ldapsyntax.LDAPEntryWithAutoFill(client=client,
                                             dn='cn=foo,dc=example,dc=com',
                                             attributes={
                                                 'objectClass':
                                                 ['some', 'other'],
                                             })
        d = o.addAutofiller(Autofill_sum(resultAttr='sum', sumAttrs=['a',
                                                                     'b']))

        def cb(dummy):
            client.assertNothingSent()

            o['a'] = ['1']
            o['b'] = ['2', '3']

            self.failUnless('sum' in o)
            self.failUnlessEqual(o['sum'], ['6'])

        d.addCallback(cb)
        return d
    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