Example #1
0
    def test_load_user_file(self):
        
        user = UserInfo("no_date", "Luke Murphey", ["admin", "power"])
        user.save(self.tmp_dir)

        # Try to load the given user
        loaded_user = UserInfo.getUserInfo(user.username, self.tmp_dir)

        self.assertEqual(user.username, loaded_user.username)
Example #2
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)