예제 #1
0
class EmptyAttributeRecordTestCase(TestCase):
    def setUp(self):
        self.record = Record(dn='test', attrs={'mail': None})

    def test_attribute_is_empty_list(self):
        self.assertEqual(self.record.attrs['mail'], [])

    def test_empty_attribute_removed(self):
        self.record.remove_empty_attributes()
        self.assertNotIn('mail', self.record.attrs)
예제 #2
0
    def test_mail_deletion(self):
        users_with_mail = [
            u for u in self.users_to_sync if u.User.email is not None
        ]
        if not users_with_mail:
            raise RuntimeError(
                "Fixtures do not provide a syncable user with a mail address")

        modified_user = users_with_mail[0].User
        mod_dn = Record.from_db_user(modified_user, self.base_dn).dn
        modified_user.email = '*****@*****.**'
        session.add(modified_user)
        session.commit()

        self.users_to_sync = fetch_users_to_sync(session,
                                                 self.config.required_property)
        self.sync_all()

        newest_users = fetch_current_ldap_users(self.conn,
                                                base_dn=self.base_dn)
        newest_users_correct_dn = [
            u for u in newest_users if u['dn'] == mod_dn
        ]
        self.assertEqual(len(newest_users_correct_dn), 1)
        modified_record = newest_users_correct_dn[0]
        self.assertNotIn('mail', modified_record)
예제 #3
0
    def test_mail_creation(self):
        users_without_mail = [
            u for u in self.users_to_sync if u.User.email is None
        ]
        if not users_without_mail:
            raise RuntimeError(
                "Fixtures do not provide a syncable user without a mail address"
            )
        mod_user = users_without_mail[0].User
        mod_dn = Record.from_db_user(mod_user, self.base_dn).dn
        mod_user.email = '*****@*****.**'
        session.add(mod_user)
        session.commit()

        users_to_sync = fetch_users_to_sync(session,
                                            self.config.required_property)
        exporter = self.build_exporter(current=self.new_ldap_users,
                                       desired=users_to_sync)
        exporter.compile_actions()
        relevant_actions = [
            a for a in exporter.actions if not isinstance(a, IdleAction)
        ]
        print(relevant_actions)
        self.assertEqual(len(relevant_actions), 1)
        self.assertEqual(type(relevant_actions[0]), ModifyAction)
        exporter.execute_all(self.conn)

        newest_users = fetch_current_ldap_users(self.conn,
                                                base_dn=self.base_dn)
        modified_ldap_record = [u for u in newest_users
                                if u['dn'] == mod_dn][0]
        self.assertIn('mail', modified_ldap_record['attributes'])
        self.assertEqual(modified_ldap_record['attributes']['mail'],
                         [mod_user.email])
예제 #4
0
파일: test_action.py 프로젝트: JuKu/pycroft
 def setUp(self):
     super(DeleteActionTestCase, self).setUp()
     self.uid = 'shizzle'
     self.dn = dn_from_username(self.uid, base=self.base)
     self.connection.add(self.dn, LDAP_OBJECTCLASSES)
     record = Record(dn=self.dn, attrs={})
     DeleteAction(record=record).execute(self.connection)
예제 #5
0
 def test_record_from_ldap_record(self):
     ldapsearch_record = {'dn': 'somedn',
                          'attributes': {'mail': u'mail', 'gecos': u'baz'},
                          'raw_attributes': {'mail': b'mail'}}
     record = Record.from_ldap_record(ldapsearch_record)
     self.assertSubDict({'mail': [u'mail'], 'gecos': [u'baz']}, record.attrs)
     for key in Record.SYNCED_ATTRIBUTES:
         self.assertIn(key, record.attrs)
예제 #6
0
파일: test_action.py 프로젝트: JuKu/pycroft
 def setUp(self):
     super(ModifyActionTestCase, self).setUp()
     self.uid = 'shizzle'
     self.dn = dn_from_username(self.uid, base=self.base)
     self.connection.add(self.dn, LDAP_OBJECTCLASSES)
     record = Record(dn=self.dn, attrs={})
     action = ModifyAction(record=record,
                           modifications={'mail': '*****@*****.**'})
     action.execute(self.connection)
예제 #7
0
    def test_attributes_synced_correctly(self):
        records = {}
        for result in self.users_to_sync:
            record = Record.from_db_user(result.User, self.base_dn,
                                         should_be_blocked=result.should_be_blocked)
            records[record.dn] = record

        for ldap_user in self.new_ldap_users:
            ldap_record = Record.from_ldap_record(ldap_user)
            # Due to the canonicalization, empty attributes will appear in
            # `records`.  We want to ignore those for the comparison.
            effective_attributes_in_db = {
                key: val
                for key, val in records[ldap_record.dn].attrs.items()
                if val != []
            }
            self.assertEqual(effective_attributes_in_db,
                             {k: v for k,v in ldap_record.attrs.items()
                              if k in effective_attributes_in_db})
예제 #8
0
파일: test_action.py 프로젝트: JuKu/pycroft
    def setUp(self):
        super(AddActionTestCase, self).setUp()
        self.attributes = {
            'mail': ['bas'],
            'userPassword': ['$1$dtruiandetnuhgaldrensutrhawtruhs']
        }
        self.uid = 'shizzle'
        self.dn = dn_from_username(self.uid, base=self.base)
        record = Record(dn=self.dn, attrs=self.attributes)
        action = AddAction(record=record)

        action.execute(self.connection)

        self.objects = self.get_all_objects()
예제 #9
0
    def test_attributes_synced_correctly(self):
        records = {}
        for result in self.users_to_sync:
            record = Record.from_db_user(
                result.User,
                self.base_dn,
                should_be_blocked=result.should_be_blocked)
            records[record.dn] = record

        for ldap_user in self.new_ldap_users:
            ldap_record = Record.from_ldap_record(ldap_user)
            # Due to the canonicalization, empty attributes will appear in
            # `records`.  We want to ignore those for the comparison.
            effective_attributes_in_db = {
                key: val
                for key, val in records[ldap_record.dn].attrs.items()
                if val != []
            }
            self.assertEqual(
                effective_attributes_in_db, {
                    k: v
                    for k, v in ldap_record.attrs.items()
                    if k in effective_attributes_in_db
                })
예제 #10
0
    def test_mail_deletion(self):
        users_with_mail = [u for u in self.users_to_sync if u.User.email is not None]
        if not users_with_mail:
            raise RuntimeError("Fixtures do not provide a syncable user with a mail address")

        modified_user = users_with_mail[0].User
        mod_dn = Record.from_db_user(modified_user, self.base_dn).dn
        modified_user.email = '*****@*****.**'
        session.add(modified_user)
        session.commit()

        self.users_to_sync = fetch_users_to_sync(session, self.config.required_property)
        self.sync_all()

        newest_users = fetch_current_ldap_users(self.conn, base_dn=self.base_dn)
        newest_users_correct_dn = [u for u in newest_users if u['dn'] == mod_dn]
        self.assertEqual(len(newest_users_correct_dn), 1)
        modified_record = newest_users_correct_dn[0]
        self.assertNotIn('mail', modified_record)
예제 #11
0
    def test_mail_creation(self):
        users_without_mail = [u for u in self.users_to_sync if u.User.email is None]
        if not users_without_mail:
            raise RuntimeError("Fixtures do not provide a syncable user without a mail address")
        mod_user = users_without_mail[0].User
        mod_dn = Record.from_db_user(mod_user, self.base_dn).dn
        mod_user.email = '*****@*****.**'
        session.add(mod_user)
        session.commit()

        users_to_sync = fetch_users_to_sync(session, self.config.required_property)
        exporter = self.build_exporter(current=self.new_ldap_users,
                                       desired=users_to_sync)
        exporter.compile_actions()
        relevant_actions = [a for a in exporter.actions if not isinstance(a, IdleAction)]
        print(relevant_actions)
        self.assertEqual(len(relevant_actions), 1)
        self.assertEqual(type(relevant_actions[0]), ModifyAction)
        exporter.execute_all(self.conn)

        newest_users = fetch_current_ldap_users(self.conn, base_dn=self.base_dn)
        modified_ldap_record = [u for u in newest_users if u['dn'] == mod_dn][0]
        self.assertIn('mail', modified_ldap_record['attributes'])
        self.assertEqual(modified_ldap_record['attributes']['mail'], [mod_user.email])
예제 #12
0
 def setUp(self):
     self.desired_user = Record(dn='user', attrs={})
     self.exporter = LdapExporter(desired=[self.desired_user], current=[])
     self.exporter.compile_actions()
예제 #13
0
 def setUp(self):
     self.record = Record(dn='test', attrs={'mail': None})
예제 #14
0
파일: test_action.py 프로젝트: JuKu/pycroft
 def test_desired_record_passed(self):
     desired = Record(dn=None, attrs={'gecos': 'test'})
     current = Record(dn=None, attrs={})
     action = ModifyAction.from_two_records(desired_record=desired,
                                            current_record=current)
     self.assertEqual(action.record, desired)
예제 #15
0
파일: test_action.py 프로젝트: JuKu/pycroft
 def action_from_attrs(self, current, desired):
     current_record = Record(dn=None, attrs=current)
     desired_record = Record(dn=None, attrs=desired)
     return ModifyAction.from_two_records(desired_record=desired_record,
                                          current_record=current_record)
예제 #16
0
파일: test_action.py 프로젝트: JuKu/pycroft
 def test_execute_does_nothing(self):
     record = Record(dn='test', attrs={})
     IdleAction(record=record).execute()
예제 #17
0
 def setUp(self):
     self.attrs = Record.from_db_user(self.complete_user, base_dn='o=test').attrs