Download tests/PHPUnit/System/TrackerDisallowedIpTest.php from Leon4gr45/matomo: direct link, hf CLI and curl.
- Browser
- Download file 2.61 kB
-
https://huggingface.co/spaces/Leon4gr45/matomo/resolve/main/tests/PHPUnit/System/TrackerDisallowedIpTest.php
- Command line
-
hf download hf://spaces/Leon4gr45/matomo/tests/PHPUnit/System/TrackerDisallowedIpTest.php
-
curl -L -o TrackerDisallowedIpTest.php https://huggingface.co/spaces/Leon4gr45/matomo/resolve/main/tests/PHPUnit/System/TrackerDisallowedIpTest.php
2.61 kB
| /** | |
| * Matomo - free/libre analytics platform | |
| * | |
| * @link https://matomo.org | |
| * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | |
| */ | |
| namespace Piwik\Tests\System; | |
| use Piwik\Common; | |
| use Piwik\Config; | |
| use Piwik\Db; | |
| use Piwik\Tests\Framework\Fixture; | |
| use Piwik\Tests\Framework\TestCase\IntegrationTestCase; | |
| /** | |
| * @group Core | |
| * @group Tracker | |
| * @group TrackerDisallowedIp | |
| */ | |
| class TrackerDisallowedIpTest extends IntegrationTestCase | |
| { | |
| public function setUp(): void | |
| { | |
| parent::setUp(); | |
| Fixture::createWebsite('2014-02-04'); | |
| Fixture::createSuperUser(false); | |
| } | |
| public function testAuthenticatedRequestShouldWorkWhenAuthenticationRequired() | |
| { | |
| // authentication required due to an older date and custom ip | |
| $tracker = Fixture::getTracker(1, '2021-02-02 16:00:00', $defaultInit = true, $useLocalTracker = false); | |
| $tracker->setTokenAuth(Fixture::getTokenAuth()); | |
| Fixture::checkResponse($tracker->doTrackPageView('test')); | |
| $this->assertEquals(1, Db::fetchOne('SELECT count(*) FROM ' . Common::prefixTable('log_visit'))); | |
| } | |
| public function testUnauthenticatedRequestShouldWorkWhenAuthenticationNotRequired() | |
| { | |
| $tracker = Fixture::getTracker(1, date('Y-m-d H:i:s'), $defaultInit = false, $useLocalTracker = false); | |
| Fixture::checkResponse($tracker->doTrackPageView('test')); | |
| $this->assertEquals(1, Db::fetchOne('SELECT count(*) FROM ' . Common::prefixTable('log_visit'))); | |
| } | |
| public function testUnauthenticatedRequestShouldNotWorkWhenAuthenticationRequired() | |
| { | |
| // authentication required due to an older date | |
| $tracker = Fixture::getTracker(1, '2021-02-02 16:00:00', $defaultInit = false, $useLocalTracker = false); | |
| Fixture::checkTrackingFailureResponse($tracker->doTrackPageView('test')); | |
| $this->assertEquals(0, Db::fetchOne('SELECT count(*) FROM ' . Common::prefixTable('log_visit'))); | |
| } | |
| public static function provideContainerConfigBeforeClass() | |
| { | |
| return [ | |
| 'observers.global' => \Piwik\DI::add(array( | |
| array('Environment.bootstrapped', \Piwik\DI::value(function () { | |
| // ensure tracking request uses an IP that is not local or on allow list | |
| $_SERVER['REMOTE_ADDR'] = '3.3.3.3'; | |
| })), | |
| )), | |
| Config::class => \Piwik\DI::decorate(function (Config $config) { | |
| $config->General['login_allowlist_ip'] = ['1.1.1.1']; | |
| return $config; | |
| }), | |
| ]; | |
| } | |
| } | |