Exemple #1
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 = UserRecord.from_db_user(mod_user, self.user_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_user_exporter(current_users=self.new_ldap_users,
                                            desired_users=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.user_base_dn)
        modified_ldap_record = self.get_by_dn(newest_users, mod_dn)
        self.assertIn('mail', modified_ldap_record['attributes'])
        self.assertEqual(modified_ldap_record['attributes']['mail'],
                         [mod_user.email])
Exemple #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)
Exemple #3
0
    def test_exporter_compiles_all_addactions(self):
        exporter = self.build_exporter()
        exporter.compile_actions()
        self.assertEqual(len(exporter.actions), len(self.users_to_sync))
        self.assertTrue(isinstance(a, AddAction) for a in exporter.actions)

        exporter.execute_all(self.conn)
        new_users = fetch_current_ldap_users(self.conn, base_dn=self.base_dn)
        self.assertEqual(len(new_users), len(self.users_to_sync))
Exemple #4
0
    def test_exporter_compiles_all_addactions(self):
        exporter = self.build_exporter()
        exporter.compile_actions()
        self.assertEqual(len(exporter.actions), len(self.users_to_sync))
        self.assertTrue(isinstance(a, AddAction) for a in exporter.actions)

        exporter.execute_all(self.conn)
        new_users = fetch_current_ldap_users(self.conn, base_dn=self.base_dn)
        self.assertEqual(len(new_users), len(self.users_to_sync))
Exemple #5
0
 def assert_entries_synced(self):
     new_users = fetch_current_ldap_users(self.conn,
                                          base_dn=self.user_base_dn)
     self.assertEqual(len(new_users), len(self.users_to_sync))
     new_groups = fetch_current_ldap_groups(self.conn,
                                            base_dn=self.group_base_dn)
     self.assertEqual(len(new_groups), len(self.groups_to_sync))
     new_properties = fetch_current_ldap_properties(
         self.conn, base_dn=self.property_base_dn)
     self.assertEqual(len(new_properties), len(self.properties_to_sync))
Exemple #6
0
 def setUp(self):
     super(LdapOnceSyncedTestCase, self).setUp()
     self.sync_all()
     # In comparison to `initial_ldap_users`:
     self.new_ldap_users = fetch_current_ldap_users(
         self.conn, base_dn=self.user_base_dn)
     self.new_ldap_groups = fetch_current_ldap_groups(
         self.conn, base_dn=self.group_base_dn)
     self.new_ldap_properties = fetch_current_ldap_properties(
         self.conn, base_dn=self.property_base_dn)
Exemple #7
0
 def setUp(self):
     super(LdapSyncerTestBase, self).setUp()
     self.users_to_sync = fetch_users_to_sync(session,
                                              self.config.required_property)
     self.initial_ldap_users = fetch_current_ldap_users(
         self.conn, base_dn=self.user_base_dn)
     self.groups_to_sync = fetch_groups_to_sync(session)
     self.initial_ldap_groups = fetch_current_ldap_groups(
         self.conn, base_dn=self.group_base_dn)
     self.properties_to_sync = fetch_properties_to_sync(session)
     self.initial_ldap_properties = fetch_current_ldap_properties(
         self.conn, base_dn=self.property_base_dn)
Exemple #8
0
    def test_no_desired_records_removes_everything(self):
        exporter = self.build_exporter(current=self.new_ldap_users, desired=[])
        exporter.compile_actions()

        # Test the actions are correct
        self.assertEqual(len(exporter.actions), len(self.new_ldap_users))
        for action in exporter.actions:
            self.assertEqual(type(action), DeleteAction)

        # Actually execute these and check they delete everything
        exporter.execute_all(self.conn)

        newest_users = fetch_current_ldap_users(self.conn, base_dn=self.base_dn)
        self.assertEqual(newest_users, [])
Exemple #9
0
    def test_no_desired_records_removes_everything(self):
        exporter = self.build_exporter(current=self.new_ldap_users, desired=[])
        exporter.compile_actions()

        # Test the actions are correct
        self.assertEqual(len(exporter.actions), len(self.new_ldap_users))
        for action in exporter.actions:
            self.assertEqual(type(action), DeleteAction)

        # Actually execute these and check they delete everything
        exporter.execute_all(self.conn)

        newest_users = fetch_current_ldap_users(self.conn,
                                                base_dn=self.base_dn)
        self.assertEqual(newest_users, [])
Exemple #10
0
    def test_no_desired_records_removes_everything(self):
        exporter = self.build_user_exporter(current_users=self.new_ldap_users,
                                            desired_users=[])
        exporter.compile_actions()

        # Test the actions are correct
        assert len(exporter.actions) == len(self.new_ldap_users)
        for action in exporter.actions:
            assert type(action) == DeleteAction

        # Actually execute these and check they delete everything
        exporter.execute_all(self.conn)

        newest_users = fetch_current_ldap_users(self.conn,
                                                base_dn=self.user_base_dn)
        assert newest_users == []
Exemple #11
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)
Exemple #12
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 = UserRecord.from_db_user(modified_user, self.user_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.user_base_dn)
        modified_record = self.get_by_dn(newest_users, mod_dn)
        assert 'mail' not in modified_record
Exemple #13
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])
Exemple #14
0
 def setUp(self):
     super(LdapOnceSyncedTestCase, self).setUp()
     self.sync_all()
     # In comparison to `initial_ldap_users`:
     self.new_ldap_users = fetch_current_ldap_users(self.conn,
                                                    base_dn=self.base_dn)
Exemple #15
0
 def test_syncall_adds_users(self):
     self.sync_all()
     new_users = fetch_current_ldap_users(self.conn, base_dn=self.base_dn)
     self.assertEqual(len(new_users), len(self.users_to_sync))
Exemple #16
0
 def setUp(self):
     super(LdapOnceSyncedTestCase, self).setUp()
     self.sync_all()
     # In comparison to `initial_ldap_users`:
     self.new_ldap_users = fetch_current_ldap_users(self.conn, base_dn=self.base_dn)
Exemple #17
0
 def test_syncall_adds_users(self):
     self.sync_all()
     new_users = fetch_current_ldap_users(self.conn, base_dn=self.base_dn)
     self.assertEqual(len(new_users), len(self.users_to_sync))
Exemple #18
0
 def setUp(self):
     super(LdapSyncerTestBase, self).setUp()
     self.users_to_sync = fetch_users_to_sync(session, self.config.required_property)
     self.initial_ldap_users = fetch_current_ldap_users(self.conn, base_dn=self.base_dn)