Ejemplo n.º 1
0
    def test_clear_user_cache(self):
        # Save a user to the cache
        ui_before = UserInfo("lmurphey2", "Luke Murphey", ["admin", "power"])
        self.assertTrue(ui_before.save(self.tmp_dir ), "File was not saved properly")
        
        # Clear the user info
        self.assertTrue(UserInfo.clearUserInfo("lmurphey2", os.path.join(self.tmp_dir)))

        # Verify the file doesn't exist
        self.assertFalse(os.path.isfile(os.path.join(self.tmp_dir, "70fce03a92dd14d910839bccbd1b474b.json")))
Ejemplo n.º 2
0
    def test_clear_user_cache_doesnt_exist(self):
        # Clear the user info
        self.assertFalse(UserInfo.clearUserInfo("lmurphey2", os.path.join(self.tmp_dir)))

        # Verify the file doesn't exist
        self.assertFalse(os.path.isfile(os.path.join(self.tmp_dir, "70fce03a92dd14d910839bccbd1b474b.json")))
Ejemplo n.º 3
0
    def handle_results(self, results, session_key, in_preview):

        # Make sure the user has permission
        if not self.has_capability('clear_radius_user_cache'):
            raise ValueError(
                'You do not have permission to remove entries from the cache' +
                ' (you need the "clear_radius_user_cache" capability)')

        # Clear the user if requested
        if self.user is not None:
            # Run in test mode if necessary
            if self.test:
                if UserInfo.getUserInfo(self.user) is not None:
                    self.output_results([{
                        'user':
                        self.user,
                        'message':
                        'The user record was found and will be cleared for the user "'
                        + self.user + '" if not run in test mode'
                    }])
                else:
                    self.output_results([{
                        'user':
                        self.user,
                        'message':
                        'No user record was found for the user "' + self.user +
                        '"'
                    }])
            else:
                if UserInfo.clearUserInfo(self.user):
                    self.output_results([{
                        'user':
                        self.user,
                        'message':
                        'The user record was cleared for the user "' +
                        self.user + '"'
                    }])
                    self.logger.info(
                        'Successfully removed cache entry for user=%s' %
                        self.user)
                else:
                    self.output_results([{
                        'user':
                        self.user,
                        'message':
                        'No user record was found for the user "' + self.user +
                        '"'
                    }])

        # Clear the cache by date if requested
        if self.days_ago is not None:
            deleted_users = UserInfo.clearCache(self.days_ago, test=self.test)

            self.logger.info(
                'Successfully removed cache entries for users that have not logged in within days=%i, count_deleted=%i'
                % (self.days_ago, len(deleted_users)))

            deleted_users_dicts = []

            if self.test:
                message = 'Would be removed from the cache when not run in test mode'
            else:
                message = 'Successfully removed from the cache'

            for user in deleted_users:
                deleted_users_dicts.append({'user': user, 'message': message})

            self.output_results(deleted_users_dicts)