قرینه از
https://github.com/matomo-org/matomo.git
synced 2025-08-24 16:07:37 +00:00

* [Coding Style] Enable rule PSR1.Methods.CamelCapsMethodName.NotCamelCaps * [Coding Style] Use camel case for method names in API plugin tests (#22145) * [Coding Style] Use camel case for method names in Core* plugin tests (#22147) * [Coding Style] Use camel case for method names in core Unit tests (#22149) * [Coding Style] Use camel case for method names in Actions and BulkTracking plugin tests (#22146) * [Coding Style] Use camel case for method names in CustomDimensions and CustomJSTracker plugin tests (#22148) * [Coding Style] Use camel case for method names in core Integration tests (#22151) * [Coding Style] Use camel case for method names in more core plugin tests (#22153) * [Coding Style] Use camel case for method names in more core plugin tests (#22157) * [Coding Style] Use camel case for method names in more core plugin tests * Update plugins/Monolog/tests/Unit/Processor/ExceptionToTextProcessorTest.php Co-authored-by: Michal Kleiner <michal@innocraft.com> --------- Co-authored-by: Michal Kleiner <michal@innocraft.com> * [Coding Style] Use camel case for method names in more core plugin tests (#22159) * [Coding Style] Use camel case for method names in remaining tests (#22160) * [Coding Style] Use camel case for method names in remaining tests * rename expected test files --------- Co-authored-by: Michal Kleiner <michal@innocraft.com>
117 خطوط
4.7 KiB
PHP
117 خطوط
4.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* 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\Integration\Tracker;
|
|
|
|
use Piwik\Date;
|
|
use Piwik\Tracker\FingerprintSalt;
|
|
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
|
|
|
|
/**
|
|
* @group Core
|
|
* @group ActionTest
|
|
*/
|
|
class FingerprintSaltTest extends IntegrationTestCase
|
|
{
|
|
/**
|
|
* @var FingerprintSalt
|
|
*/
|
|
private $fingerprintSalt;
|
|
|
|
public function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->fingerprintSalt = new FingerprintSalt();
|
|
}
|
|
|
|
public function testGenerateSalt()
|
|
{
|
|
$salt = $this->fingerprintSalt->generateSalt();
|
|
$this->assertEquals(32, strlen($salt));
|
|
$this->assertTrue(ctype_alnum($salt));
|
|
}
|
|
|
|
public function testGenerateSaltIsRandom()
|
|
{
|
|
$this->assertNotSame($this->fingerprintSalt->generateSalt(), $this->fingerprintSalt->generateSalt());
|
|
}
|
|
|
|
public function testGetDateString()
|
|
{
|
|
$date = Date::factory('2020-05-05 14:04:05');
|
|
$this->assertSame('2020-05-06', $this->fingerprintSalt->getDateString($date, 'Pacific/Auckland'));
|
|
$this->assertSame('2020-05-05', $this->fingerprintSalt->getDateString($date, 'Europe/Berlin'));
|
|
}
|
|
|
|
public function testGetDateStringDoubleCheckingWeAreGeneratingRightString()
|
|
{
|
|
for ($i = 0; $i <= 23; $i++) {
|
|
$d = '2020-05-05 ' . $i . ':04:05';
|
|
$date = Date::factory($d);
|
|
// double checking using the logic used in CoreHome::VisitRequestProcesser::wasLastActionNotToday where we detect midnight
|
|
// in timezone just to double check we return the correct date string for the given timezone. Should anything change and test not pass
|
|
// then we might have a problem that we would generate a different fingerprint for the same visitor even though it is not midnight
|
|
// just yet. Meaning during the day we would suddenly change the fingerprint hash causing additional visits to be created when not needed yet
|
|
$this->assertSame($this->fingerprintSalt->getDateString($date, 'Pacific/Auckland'), Date::factory($d, 'Pacific/Auckland')->toString());
|
|
$this->assertSame($this->fingerprintSalt->getDateString($date, 'Europe/Berlin'), Date::factory($d, 'Europe/Berlin')->toString());
|
|
$this->assertSame($this->fingerprintSalt->getDateString($date, 'America/Los_Angeles'), Date::factory($d, 'America/Los_Angeles')->toString());
|
|
}
|
|
}
|
|
|
|
public function testGetSaltRemembersSaltPerSite()
|
|
{
|
|
$salt05_1 = $this->fingerprintSalt->getSalt('2020-05-05', $idSite = 1);
|
|
$salt06_1 = $this->fingerprintSalt->getSalt('2020-05-06', $idSite = 1);
|
|
$salt05_2 = $this->fingerprintSalt->getSalt('2020-05-05', $idSite = 2);
|
|
$salt06_2 = $this->fingerprintSalt->getSalt('2020-05-06', $idSite = 2);
|
|
|
|
$this->assertNotSame($salt05_1, $salt06_1);
|
|
$this->assertNotSame($salt05_2, $salt06_2);
|
|
$this->assertNotSame($salt06_1, $salt06_2);
|
|
|
|
$this->assertSame($salt05_1, $this->fingerprintSalt->getSalt('2020-05-05', $idSite = 1));
|
|
$this->assertSame($salt06_1, $this->fingerprintSalt->getSalt('2020-05-06', $idSite = 1));
|
|
$this->assertSame($salt05_2, $this->fingerprintSalt->getSalt('2020-05-05', $idSite = 2));
|
|
}
|
|
|
|
public function testDeleteOldSaltsWhenNothingToDelete()
|
|
{
|
|
$this->fingerprintSalt->getSalt('2020-05-05', $idSite = 1);
|
|
$this->fingerprintSalt->getSalt('2020-05-06', $idSite = 1);
|
|
|
|
Date::$now = time() - FingerprintSalt::DELETE_FINGERPRINT_OLDER_THAN_SECONDS + 30;// they would expire in 30 seconds
|
|
$this->fingerprintSalt->getSalt('2020-05-05', $idSite = 2);
|
|
$this->fingerprintSalt->getSalt('2020-05-06', $idSite = 2);
|
|
|
|
Date::$now = time();
|
|
$this->assertSame(array(), $this->fingerprintSalt->deleteOldSalts());
|
|
}
|
|
|
|
public function testDeleteOldSaltsSomeToBeDeleted()
|
|
{
|
|
$this->fingerprintSalt->getSalt('2020-05-05', $idSite = 1);
|
|
|
|
Date::$now = time() - FingerprintSalt::DELETE_FINGERPRINT_OLDER_THAN_SECONDS - 30; // these entries should be expired
|
|
$this->fingerprintSalt->getSalt('2020-05-06', $idSite = 1);
|
|
$this->fingerprintSalt->getSalt('2020-05-05', $idSite = 2);
|
|
$this->fingerprintSalt->getSalt('2020-05-06', $idSite = 2);
|
|
|
|
Date::$now = time();
|
|
$this->assertSame(array(
|
|
'fingerprint_salt_1_2020-05-06',
|
|
'fingerprint_salt_2_2020-05-05',
|
|
'fingerprint_salt_2_2020-05-06'
|
|
), $this->fingerprintSalt->deleteOldSalts());
|
|
|
|
// executing it again wont delete anything
|
|
$this->assertSame(array(), $this->fingerprintSalt->deleteOldSalts());
|
|
}
|
|
}
|