قرینه از
https://github.com/matomo-org/matomo.git
synced 2025-08-22 15:07:44 +00:00

* Add token expiry warning email notification to scheduler * Add token expiry warning email notification to scheduler * add logic for -1 disable notification' * Fix spelling mistake * Fix some bugs around rendering the email * Update version * Refactor rotation code to use a standardised naming convention with new code * PHPStan * PHPCS fix * add test, not finished * finish off implementing test * Fix regression test failure * Update config to disable feature when set to 0 * update text to make more sense * Update token logic to more accurately determine when tokens are created * Update broken UI test * Add support for custom auth token expire date in UI and API (#23340) * Add support for custom auth token expire date in UI and API * Apply initial review feedback - require token expire date to be in future - refactor and simplify controller logic - remove unsude model method params - always display expire column in the list of tokens - pass default expiration to help text * Update config name to match emails-related work * Update UI test screenshot where expire date column is always visible * Update UI test screenshot with new global config options * Move initial expire date calculation to back-end * Use mock date for tests * Update UI tests * Update UI test screenshots * Update UI test screenshots * Move logic to override Tests.now to the Date class * Remove unused use statement * Update UI test screenshots * Tweak Date logic around Tests.now * Fix datepicker visibility * Add UI test for token expiration date picker * Fix 'label for a missing id' accessibility issue * Use custom fixture not to impact other tests * Fix CS * Fix fixture namespacing and use correct fixture in tests * Uncomment code commented out when debugging * Ensure initial date is set correctly for the date picker * Test config change to a different token expire interval * Update screenshot after config wording change * Remove unused function * Build vue components * Update expected screenshots * Remove obsolete comments * Allow numeric strings in Tests.now * Accept only values representing dates over 1990-01-01 in Tests.now * set date correctly for tests --------- Co-authored-by: Marc Neudert <marc@innocraft.com> Co-authored-by: sgiehl <stefan@matomo.org> --------- Co-authored-by: Nathan Gavin <nathangavin987@gmail.com> Co-authored-by: Marc Neudert <marc@innocraft.com> Co-authored-by: sgiehl <stefan@matomo.org>
97 خطوط
6.0 KiB
PHP
97 خطوط
6.0 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\Plugins\UsersManager\tests\Fixtures;
|
|
|
|
use Piwik\Common;
|
|
use Piwik\Db;
|
|
use Piwik\Plugins\UsersManager\API;
|
|
use Piwik\Plugins\UsersManager\Model as UsersManagerModel;
|
|
use Piwik\Tests\Framework\Fixture;
|
|
|
|
/**
|
|
* Generates auth tokens for token notification tests
|
|
*/
|
|
class ExpiringTokens extends Fixture
|
|
{
|
|
public $expiringTokens = [
|
|
'user1' => [
|
|
['user1, not expired user token, secure only', '2025-01-01 00:00:00', null, '0', '1'],
|
|
['user1, not expired user token, not secure only', '2025-01-01 00:00:00', null, '0', '0'],
|
|
['user1, not expired system token, secure only', '2025-01-01 00:00:00', null, '1', '1'],
|
|
['user1, not expired system token, not secure only', '2025-01-01 00:00:00', null, '1', '0'],
|
|
['user1, expiring user token <30 days, secure only', '2025-01-01 00:00:00', '2025-04-03 00:00:00', '0', '1'],
|
|
['user1, expiring user token <30 days, not secure only', '2025-01-01 00:00:00', '2025-04-03 00:00:00', '0', '0'],
|
|
['user1, expiring system token <30 days, secure only', '2025-01-01 00:00:00', '2025-04-03 00:00:00', '1', '1'],
|
|
['user1, expiring system token <30 days, not secure only', '2025-01-01 00:00:00', '2025-04-03 00:00:00', '1', '0'],
|
|
['user1, expiring user token =30 days, secure only', '2025-01-01 00:00:00', '2025-04-30 00:00:00', '0', '1'],
|
|
['user1, expiring user token =30 days, not secure only', '2025-01-01 00:00:00', '2025-04-30 00:00:00', '0', '0'],
|
|
['user1, expiring system token =30 days, secure only', '2025-01-01 00:00:00', '2025-04-30 00:00:00', '1', '1'],
|
|
['user1, expiring system token =30 days, not secure only', '2025-01-01 00:00:00', '2025-04-30 00:00:00', '1', '0'],
|
|
['user1, expiring user token >30 days, secure only', '2025-01-01 00:00:00', '2025-05-29 00:00:00', '0', '1'],
|
|
['user1, expiring user token >30 days, not secure only', '2025-01-01 00:00:00', '2025-05-29 00:00:00', '0', '0'],
|
|
['user1, expiring system token >30 days, secure only', '2025-01-01 00:00:00', '2025-05-29 00:00:00', '1', '1'],
|
|
['user1, expiring system token >30 days, not secure only', '2025-01-01 00:00:00', '2025-05-29 00:00:00', '1', '0'],
|
|
['user1, expired user token, secure only', '2025-01-01 00:00:00', '2025-02-01 00:00:00', '0', '1'],
|
|
['user1, expired user token, not secure only', '2025-01-01 00:00:00', '2025-02-01 00:00:00', '0', '0'],
|
|
['user1, expired system token, secure only', '2025-01-01 00:00:00', '2025-02-01 00:00:00', '1', '1'],
|
|
['user1, expired system token, not secure only', '2025-01-01 00:00:00', '2025-02-01 00:00:00', '1', '0'],
|
|
],
|
|
'user2' => [
|
|
['user2, not expired user token, secure only', '2025-01-01 00:00:00', null, '0', '1'],
|
|
['user2, not expired user token, not secure only', '2025-01-01 00:00:00', null, '0', '0'],
|
|
['user2, not expired system token, secure only', '2025-01-01 00:00:00', null, '1', '1'],
|
|
['user2, not expired system token, not secure only', '2025-01-01 00:00:00', null, '1', '0'],
|
|
['user2, expiring user token <30 days, secure only', '2025-01-01 00:00:00', '2025-04-03 00:00:00', '0', '1'],
|
|
['user2, expiring user token <30 days, not secure only', '2025-01-01 00:00:00', '2025-04-03 00:00:00', '0', '0'],
|
|
['user2, expiring system token <30 days, secure only', '2025-01-01 00:00:00', '2025-04-03 00:00:00', '1', '1'],
|
|
['user2, expiring system token <30 days, not secure only', '2025-01-01 00:00:00', '2025-04-03 00:00:00', '1', '0'],
|
|
['user2, expiring user token =30 days, secure only', '2025-01-01 00:00:00', '2025-04-30 00:00:00', '0', '1'],
|
|
['user2, expiring user token =30 days, not secure only', '2025-01-01 00:00:00', '2025-04-30 00:00:00', '0', '0'],
|
|
['user2, expiring system token =30 days, secure only', '2025-01-01 00:00:00', '2025-04-30 00:00:00', '1', '1'],
|
|
['user2, expiring system token =30 days, not secure only', '2025-01-01 00:00:00', '2025-04-30 00:00:00', '1', '0'],
|
|
['user2, expiring user token >30 days, secure only', '2025-01-01 00:00:00', '2025-05-29 00:00:00', '0', '1'],
|
|
['user2, expiring user token >30 days, not secure only', '2025-01-01 00:00:00', '2025-05-29 00:00:00', '0', '0'],
|
|
['user2, expiring system token >30 days, secure only', '2025-01-01 00:00:00', '2025-05-29 00:00:00', '1', '1'],
|
|
['user2, expiring system token >30 days, not secure only', '2025-01-01 00:00:00', '2025-05-29 00:00:00', '1', '0'],
|
|
['user2, expired user token, secure only', '2025-01-01 00:00:00', '2025-02-01 00:00:00', '0', '1'],
|
|
['user2, expired user token, not secure only', '2025-01-01 00:00:00', '2025-02-01 00:00:00', '0', '0'],
|
|
['user2, expired system token, secure only', '2025-01-01 00:00:00', '2025-02-01 00:00:00', '1', '1'],
|
|
['user2, expired system token, not secure only', '2025-01-01 00:00:00', '2025-02-01 00:00:00', '1', '0'],
|
|
],
|
|
];
|
|
|
|
public function setUp(): void
|
|
{
|
|
Fixture::createWebsite('2020-01-11 00:00:00');
|
|
|
|
$this->setUpUsersAndTokens();
|
|
}
|
|
|
|
private function setUpUsersAndTokens()
|
|
{
|
|
$api = API::getInstance();
|
|
$api->addUser('user1', 'password1', 'user1@example.com');
|
|
$api->addUser('user2', 'password2', 'user2@example.com');
|
|
$api->setUserAccess('user2', 'view', [1]);
|
|
|
|
$model = new UsersManagerModel();
|
|
foreach ($this->expiringTokens as $user => $tokens) {
|
|
foreach ($tokens as $token) {
|
|
$model->addTokenAuth($user, $model->generateRandomTokenAuth(), ...$token);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function resetTsExpirationNotification()
|
|
{
|
|
Db::get()->query("UPDATE " . Common::prefixTable('user_token_auth') . " SET ts_expiration_warning_notified = NULL");
|
|
}
|
|
}
|