Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken caching system when array of allowed parameters used #6410

Closed
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
152767d
fix: add a new param in processRules and getErrorMessage function to …
ping-yee Aug 15, 2022
9888bba
add : add a description to the changelog in v4.2.5.
ping-yee Aug 15, 2022
574feb7
changelog: change changelog
ping-yee Aug 16, 2022
964fe71
test: add test for validation error with asterisk field.
ping-yee Aug 19, 2022
8b4b16a
Update Table.php
sclubricants Aug 20, 2022
1cc0f9b
test: refactor tests for getFieldData()
kenjis Aug 20, 2022
e48296e
Exclude non-monolithic files from CS
paulbalandan Aug 21, 2022
66af822
Update system/Database/SQLite3/Table.php
sclubricants Aug 22, 2022
b6751aa
Fix broken caching system when array of allowed parameters configurat…
JavaDeveloperKiev Aug 22, 2022
80eb987
docs : fix typo in "General Topics » Managing your Applications"
cijagani Aug 22, 2022
40c69f0
Merge pull request #6411 from cijagani/develop
samsonasik Aug 22, 2022
512f253
fix: cs-fix
ping-yee Aug 22, 2022
071cd04
Merge pull request #6378 from ping-yee/fix-validation-custom-error-as…
kenjis Aug 22, 2022
9546098
Merge pull request #6401 from paulbalandan/cs-exclude
paulbalandan Aug 23, 2022
1760b09
docs: update about test database
kenjis Aug 23, 2022
7100bc6
docs: update test database config sample in .env
kenjis Aug 23, 2022
fa474ad
config: change commented database.tests.database value
kenjis Aug 23, 2022
a04b27d
Fix coding style
JavaDeveloperKiev Aug 23, 2022
0fc684e
docs: restore phpunit.xml
kenjis Aug 23, 2022
7b4f482
Created 3 tests for caching with different cacheQueryString options
JavaDeveloperKiev Aug 23, 2022
8adacb0
Refactoring syntax edits to pass Rector 7.4 and 8.0 check
JavaDeveloperKiev Aug 23, 2022
b2ad447
Add testDropColumnDropCompositeKey()
sclubricants Aug 23, 2022
7717097
Fix test
sclubricants Aug 23, 2022
9a4ee1b
fix
sclubricants Aug 23, 2022
7824a20
Updating the Cache test to use data provider
JavaDeveloperKiev Aug 23, 2022
3bcc652
Merge pull request #6417 from kenjis/fix-docs-test-database
kenjis Aug 24, 2022
70d27e0
docs: fix by proofreading
kenjis Aug 24, 2022
39d1162
docs: add Backward Compatibility Notes
kenjis Aug 24, 2022
ac68aad
Use parameter type declaration instead of doc comment | Change mixed …
JavaDeveloperKiev Aug 24, 2022
fb042fc
[Rector] Clean up skip UnwrapFutureCompatibleIfPhpVersionRector
samsonasik Aug 24, 2022
31c9296
run rector.php
samsonasik Aug 24, 2022
8ffd54d
run rector.php
samsonasik Aug 24, 2022
9e1b87a
Merge pull request #6420 from samsonasik/rector-cleanup
samsonasik Aug 24, 2022
86f0746
Merge pull request #6418 from kenjis/docs-backward_compatibility_notes
kenjis Aug 25, 2022
c3aa797
Merge pull request #6416 from kenjis/fix-tests-README
kenjis Aug 25, 2022
b0da9eb
Merge pull request #6396 from sclubricants/SqliteTable
kenjis Aug 25, 2022
7acd0fe
docs: fix git command example
kenjis Aug 25, 2022
f92de2c
Merge pull request #6422 from kenjis/fix-contributing/workflow.md
kenjis Aug 25, 2022
45025a1
Merge pull request #6400 from kenjis/refactor-ForgeTest-getFieldData
kenjis Aug 26, 2022
2f244e3
docs: replace mixed in Database doc comments
kenjis Aug 26, 2022
0454d73
docs: update the reference to Time, and make it a note
kenjis Aug 26, 2022
f9f606d
docs: fix text decoration
kenjis Aug 26, 2022
90dda25
docs: Correct the explanation of now()
kenjis Aug 26, 2022
1e0ea34
refactor: remove unused key '_parent_name'
kenjis Aug 26, 2022
6234f0e
Merge pull request #6427 from kenjis/remove-_parent_name
samsonasik Aug 26, 2022
b53d482
fix: remove harmful @mixin in RequestInterface
kenjis Aug 24, 2022
dff94db
fix: add missing get*() methods in CLIRequest
kenjis Aug 24, 2022
873f616
fix: Honeypot filter causes error
kenjis Aug 24, 2022
8c37dd1
test: update NegotiateTest
kenjis Aug 25, 2022
42ac32d
test: remove unneeded tearDown()
kenjis Aug 25, 2022
5d7f529
fix: return type of added get*() methods
kenjis Aug 27, 2022
b8e0e64
docs: add explanation about a shared instance and parameters
kenjis Aug 27, 2022
210b60f
docs: add @method groupBy() in Model
kenjis Aug 27, 2022
f46d24b
Merge pull request #6433 from kenjis/fix-Model-doc-comment
kenjis Aug 27, 2022
f160747
Merge pull request #6432 from kenjis/fix-docs-services.rst
kenjis Aug 27, 2022
0d90f84
Merge pull request #6424 from kenjis/remove-mixed-in-db
kenjis Aug 27, 2022
e686a14
Merge pull request #6421 from kenjis/fix-RequestInterface-mixin
kenjis Aug 27, 2022
1621263
docs: fix by proofreading
kenjis Aug 27, 2022
7cc7283
Remove unneeded abstract `handle()` method
paulbalandan Aug 27, 2022
799d655
Merge pull request #6426 from kenjis/fix-docs-date_helper
kenjis Aug 27, 2022
7ec384b
chore: update Kint to 4.2.0
kenjis Aug 27, 2022
97605f4
docs: add changelog
kenjis Aug 27, 2022
e215d66
docs: remove description on squashing commits
kenjis Aug 28, 2022
122133b
docs: add explanation on commits and commit messages
kenjis Aug 28, 2022
55fd7f0
docs: update wording
kenjis Aug 28, 2022
2e95625
docs: move description from signing to workflow
kenjis Aug 28, 2022
c382096
docs: add link to detailed explanation
kenjis Aug 28, 2022
622f829
Merge pull request #6434 from codeigniter4/paulbalandan-patch-1
paulbalandan Aug 28, 2022
596b629
chore: update kint vertion to ^4.2
kenjis Aug 28, 2022
53e1483
docs: $db->getFieldData() data explanation is not complete
naente Aug 28, 2022
a65e57a
Merge pull request #6437 from kenjis/add-docs-on-PR-commits
kenjis Aug 28, 2022
6a31be4
Merge pull request #6436 from kenjis/update-kint-to-420
kenjis Aug 28, 2022
b6d9f91
docs: fix incorrect links to the spark page
kenjis Aug 28, 2022
5e7b4fe
test: fix incorrect assertions
kenjis Aug 28, 2022
6aafff0
fix: add missing CLIRequest::getLocale()
kenjis Aug 28, 2022
31aab61
Merge pull request #6442 from kenjis/fix-CLIRequest-getLocale-error
MGatner Aug 29, 2022
d800a75
Merge pull request #6441 from kenjis/fix-docs-link-to-spark
MGatner Aug 29, 2022
cd450e7
Prep for 4.2.5 release
MGatner Aug 29, 2022
800c2c1
Merge pull request #6443 from codeigniter4/release-4.2.5
MGatner Aug 29, 2022
d51d4e9
Merge pull request #6445 from codeigniter4/develop
MGatner Aug 29, 2022
2e3dd46
chore: add `rector process --dry-run` to `composer analyze`
kenjis Aug 29, 2022
cb60d93
chore: add composer script aliaes
kenjis Aug 29, 2022
a589af0
docs: update pull_request.md
kenjis Aug 29, 2022
14bfd1f
docs: add Changing a commit message
kenjis Aug 29, 2022
71a4bed
docs: change letter cases in titles
kenjis Aug 29, 2022
2788a49
Merge pull request #6440 from naente/develop
MGatner Aug 29, 2022
bae9665
Merge pull request #6446 from kenjis/update-composer-scripts
kenjis Aug 29, 2022
f1862a0
Merge pull request #6447 from kenjis/update-contributing/workflow.md
kenjis Aug 29, 2022
536e5b1
docs: add about controllers namespace in routing
kenjis Aug 29, 2022
a8c69e8
- FIX: in command prompt
daycry Aug 29, 2022
8e1e695
Update FileRules.php
daycry Aug 30, 2022
9e34a8f
Update FileRules.php
daycry Aug 30, 2022
426873f
Update FileRules.php
daycry Aug 30, 2022
cd4bc83
Merge pull request #6452 from daycry/patch-1
MGatner Aug 30, 2022
e046890
docs: improve sample code
kenjis Aug 30, 2022
a51b07c
Merge pull request #6451 from kenjis/fix-docs-routing-namespace
kenjis Aug 30, 2022
1aeb5b3
test: restore changed locale in tearDown()
kenjis Aug 31, 2022
69c407b
docs: update PHPDoc in Entity
kenjis Aug 31, 2022
528eed7
test: fix invalid locale value
kenjis Aug 31, 2022
5b396db
Merge pull request #6462 from kenjis/fix-Entity-phpdoc
kenjis Aug 31, 2022
57385ea
Merge pull request #6460 from kenjis/fix-test-restore-locales
kenjis Aug 31, 2022
3b8ee4f
Fix broken caching system when array of allowed parameters configurat…
JavaDeveloperKiev Aug 22, 2022
6460513
Fix coding style
JavaDeveloperKiev Aug 23, 2022
903b78d
Created 3 tests for caching with different cacheQueryString options
JavaDeveloperKiev Aug 23, 2022
2a4a990
Refactoring syntax edits to pass Rector 7.4 and 8.0 check
JavaDeveloperKiev Aug 23, 2022
5237e30
Updating the Cache test to use data provider
JavaDeveloperKiev Aug 23, 2022
48d2dc6
Use parameter type declaration instead of doc comment | Change mixed …
JavaDeveloperKiev Aug 24, 2022
512d9ae
Merge branch 'patch-1' of https://github.com/JavaDeveloperKiev/CodeIg…
JavaDeveloperKiev Sep 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -730,9 +730,12 @@ protected function generateCacheName(Cache $config): string
}

$uri = $this->request->getUri();

if ($config->cacheQueryString) {
$name = URI::createURIString($uri->getScheme(), $uri->getAuthority(), $uri->getPath(), $uri->getQuery());
if (is_array($config->cacheQueryString)) {
$name = URI::createURIString($uri->getScheme(), $uri->getAuthority(), $uri->getPath(), $uri->getQuery(['only' => $config->cacheQueryString]));
} else {
$name = URI::createURIString($uri->getScheme(), $uri->getAuthority(), $uri->getPath(), $uri->getQuery());
}
} else {
$name = URI::createURIString($uri->getScheme(), $uri->getAuthority(), $uri->getPath());
}
Expand Down
80 changes: 80 additions & 0 deletions tests/system/CodeIgniterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use CodeIgniter\Test\Filters\CITestStreamFilter;
use CodeIgniter\Test\Mock\MockCodeIgniter;
use Config\App;
use Config\Cache;
use Config\Filters;
use Config\Modules;
use Tests\Support\Filters\Customfilter;
Expand Down Expand Up @@ -622,4 +623,83 @@ public function testPageCacheSendSecureHeaders()
stream_filter_remove($outputStreamFilter);
stream_filter_remove($errorStreamFilter);
}

/**
* @param mixed $cacheQueryStringValue
kenjis marked this conversation as resolved.
Show resolved Hide resolved
* @param int $expectedPagesInCache
* @param array $testingUrls
kenjis marked this conversation as resolved.
Show resolved Hide resolved
* @dataProvider cacheQueryStringProvider
*
* @see https://github.com/codeigniter4/CodeIgniter4/pull/6410
*/
public function testPageCacheWithCacheQueryString($cacheQueryStringValue, $expectedPagesInCache, $testingUrls)
{
// Suppress command() output
CITestStreamFilter::$buffer = '';
$outputStreamFilter = stream_filter_append(STDOUT, 'CITestStreamFilter');
$errorStreamFilter = stream_filter_append(STDERR, 'CITestStreamFilter');

// Create cache config with cacheQueryString value from the dataProvider
$cacheConfig = new Cache();
$cacheConfig->cacheQueryString = $cacheQueryStringValue;

// Clear cache before starting the test
command('cache:clear');

// Calculate amount of items in the cache before the test
$cache = \Config\Services::cache();
$cacheStartCounter = count($cache->getCacheInfo());

// Generate request to each URL from the testing array
foreach ($testingUrls as $testingUrl) {
$_SERVER['REQUEST_URI'] = '/' . $testingUrl;
$routes = Services::routes(true);
$routes->add($testingUrl, static function () {
CodeIgniter::cache(0); // Dont cache the page in the run() function because CodeIgniter class will create default $cacheConfig and overwrite settings from the dataProvider
$response = Services::response();
$string = 'This is a test page, to check cache configuration';

return $response->setBody($string);
});

// Inject router
$router = Services::router($routes, Services::request(null, false));
Services::injectMock('router', $router);

// Cache the page output using default caching function and $cacheConfig with value from the data provider
$this->codeigniter->useSafeOutput(true)->run();
$this->codeigniter->cachePage($cacheConfig); // Cache the page using our own $cacheConfig confugration
}

// Calculate how much cached items exist in the cache after the test requests
$cacheEndCounter = count($cache->getCacheInfo());
$newPagesCached = $cacheEndCounter - $cacheStartCounter;

// Clear cache after the test
command('cache:clear');

// Check that amount of new items created in the cache matching expected value from the data provider
$this->assertSame($expectedPagesInCache, $newPagesCached);

// Remove stream filters
stream_filter_remove($outputStreamFilter);
stream_filter_remove($errorStreamFilter);
}

public function cacheQueryStringProvider(): array
{
$testingUrls = [
'test', // URL #1
'test?important_parameter=1', // URL #2
'test?important_parameter=2', // URL #3
'test?important_parameter=1&not_important_parameter=2', // URL #4
'test?important_parameter=1&not_important_parameter=2&another_not_important_parameter=3', // URL #5
];

return [
'$cacheQueryString=false' => [false, 1, $testingUrls], // We expect only 1 page in the cache, because when cacheQueryString is set to false, all GET parameter should be ignored, and page URI will be absolutely same "/test" string for all 5 requests
'$cacheQueryString=true' => [true, 5, $testingUrls], // We expect all 5 pages in the cache, because when cacheQueryString is set to true, all GET parameter should be processed as unique requests
'$cacheQueryString=array' => [['important_parameter'], 3, $testingUrls], // We expect only 3 pages in the cache, because when cacheQueryString is set to array with important parameters, we should ignore all parameters thats not in the array. Only URL #1, URL #2 and URL #3 should be cached. URL #4 and URL #5 is duplication of URL #2 (with value ?important_parameter=1), so they should not be processed as new unique requests and application should return already cached page for URL #2
];
}
}