Upgrade 1-11.38

This commit is contained in:
xesmyd
2026-03-30 14:10:30 +02:00
parent f2a7e6d1fc
commit ac648ef29d
24665 changed files with 69682 additions and 2205004 deletions
+83 -29
View File
@@ -29,7 +29,7 @@ class StoreTest extends TestCase
protected function setUp()
{
$this->request = Request::create('/');
$this->response = new Response('hello world', 200, array());
$this->response = new Response('hello world', 200, []);
HttpCacheTestCase::clearDirectory(sys_get_temp_dir().'/http_cache');
@@ -52,7 +52,7 @@ class StoreTest extends TestCase
public function testUnlockFileThatDoesExist()
{
$cacheKey = $this->storeSimpleEntry();
$this->storeSimpleEntry();
$this->store->lock($this->request);
$this->assertTrue($this->store->unlock($this->request));
@@ -92,11 +92,65 @@ class StoreTest extends TestCase
{
$cacheKey = $this->storeSimpleEntry();
$entries = $this->getStoreMetadata($cacheKey);
list($req, $res) = $entries[0];
list(, $res) = $entries[0];
$this->assertEquals('en9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08', $res['x-content-digest'][0]);
}
public function testDoesNotTrustXContentDigestFromUpstream()
{
$response = new Response('test', 200, ['X-Content-Digest' => 'untrusted-from-elsewhere']);
$cacheKey = $this->store->write($this->request, $response);
$entries = $this->getStoreMetadata($cacheKey);
list(, $res) = $entries[0];
$this->assertEquals('en9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08', $res['x-content-digest'][0]);
$this->assertEquals('en9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08', $response->headers->get('X-Content-Digest'));
}
public function testWritesResponseEvenIfXContentDigestIsPresent()
{
// Prime the store
$this->store->write($this->request, new Response('test', 200, ['X-Content-Digest' => 'untrusted-from-elsewhere']));
$response = $this->store->lookup($this->request);
$this->assertNotNull($response);
}
public function testWritingARestoredResponseDoesNotCorruptCache()
{
/*
* This covers the regression reported in https://github.com/symfony/symfony/issues/37174.
*
* A restored response does *not* load the body, but only keep the file path in a special X-Body-File
* header. For reasons (?), the file path was also used as the restored response body.
* It would be up to others (HttpCache...?) to honor this header and actually load the response content
* from there.
*
* When a restored response was stored again, the Store itself would ignore the header. In the first
* step, this would compute a new Content Digest based on the file path in the restored response body;
* this is covered by "Checkpoint 1" below. But, since the X-Body-File header was left untouched (Checkpoint 2), downstream
* code (HttpCache...) would not immediately notice.
*
* Only upon performing the lookup for a second time, we'd get a Response where the (wrong) Content Digest
* is also reflected in the X-Body-File header, this time also producing wrong content when the downstream
* evaluates it.
*/
$this->store->write($this->request, $this->response);
$digest = $this->response->headers->get('X-Content-Digest');
$path = $this->getStorePath($digest);
$response = $this->store->lookup($this->request);
$this->store->write($this->request, $response);
$this->assertEquals($digest, $response->headers->get('X-Content-Digest')); // Checkpoint 1
$this->assertEquals($path, $response->headers->get('X-Body-File')); // Checkpoint 2
$response = $this->store->lookup($this->request);
$this->assertEquals($digest, $response->headers->get('X-Content-Digest'));
$this->assertEquals($path, $response->headers->get('X-Body-File'));
}
public function testFindsAStoredEntryWithLookup()
{
$this->storeSimpleEntry();
@@ -108,7 +162,7 @@ class StoreTest extends TestCase
public function testDoesNotFindAnEntryWithLookupWhenNoneExists()
{
$request = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar'));
$request = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar']);
$this->assertNull($this->store->lookup($request));
}
@@ -137,7 +191,7 @@ class StoreTest extends TestCase
$this->storeSimpleEntry();
$response = $this->store->lookup($this->request);
$this->assertEquals($response->headers->all(), array_merge(array('content-length' => 4, 'x-body-file' => array($this->getStorePath($response->headers->get('X-Content-Digest')))), $this->response->headers->all()));
$this->assertEquals($response->headers->all(), array_merge(['content-length' => 4, 'x-body-file' => [$this->getStorePath($response->headers->get('X-Content-Digest'))]], $this->response->headers->all()));
}
public function testRestoresResponseContentFromEntityStoreWithLookup()
@@ -165,9 +219,9 @@ class StoreTest extends TestCase
public function testDoesNotReturnEntriesThatVaryWithLookup()
{
$req1 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar'));
$req2 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Bling', 'HTTP_BAR' => 'Bam'));
$res = new Response('test', 200, array('Vary' => 'Foo Bar'));
$req1 = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar']);
$req2 = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Bling', 'HTTP_BAR' => 'Bam']);
$res = new Response('test', 200, ['Vary' => 'Foo Bar']);
$this->store->write($req1, $res);
$this->assertNull($this->store->lookup($req2));
@@ -175,9 +229,9 @@ class StoreTest extends TestCase
public function testDoesNotReturnEntriesThatSlightlyVaryWithLookup()
{
$req1 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar'));
$req2 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bam'));
$res = new Response('test', 200, array('Vary' => array('Foo', 'Bar')));
$req1 = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar']);
$req2 = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bam']);
$res = new Response('test', 200, ['Vary' => ['Foo', 'Bar']]);
$this->store->write($req1, $res);
$this->assertNull($this->store->lookup($req2));
@@ -185,16 +239,16 @@ class StoreTest extends TestCase
public function testStoresMultipleResponsesForEachVaryCombination()
{
$req1 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar'));
$res1 = new Response('test 1', 200, array('Vary' => 'Foo Bar'));
$req1 = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar']);
$res1 = new Response('test 1', 200, ['Vary' => 'Foo Bar']);
$key = $this->store->write($req1, $res1);
$req2 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Bling', 'HTTP_BAR' => 'Bam'));
$res2 = new Response('test 2', 200, array('Vary' => 'Foo Bar'));
$req2 = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Bling', 'HTTP_BAR' => 'Bam']);
$res2 = new Response('test 2', 200, ['Vary' => 'Foo Bar']);
$this->store->write($req2, $res2);
$req3 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Baz', 'HTTP_BAR' => 'Boom'));
$res3 = new Response('test 3', 200, array('Vary' => 'Foo Bar'));
$req3 = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Baz', 'HTTP_BAR' => 'Boom']);
$res3 = new Response('test 3', 200, ['Vary' => 'Foo Bar']);
$this->store->write($req3, $res3);
$this->assertEquals($this->getStorePath('en'.hash('sha256', 'test 3')), $this->store->lookup($req3)->getContent());
@@ -206,18 +260,18 @@ class StoreTest extends TestCase
public function testOverwritesNonVaryingResponseWithStore()
{
$req1 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar'));
$res1 = new Response('test 1', 200, array('Vary' => 'Foo Bar'));
$key = $this->store->write($req1, $res1);
$req1 = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar']);
$res1 = new Response('test 1', 200, ['Vary' => 'Foo Bar']);
$this->store->write($req1, $res1);
$this->assertEquals($this->getStorePath('en'.hash('sha256', 'test 1')), $this->store->lookup($req1)->getContent());
$req2 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Bling', 'HTTP_BAR' => 'Bam'));
$res2 = new Response('test 2', 200, array('Vary' => 'Foo Bar'));
$req2 = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Bling', 'HTTP_BAR' => 'Bam']);
$res2 = new Response('test 2', 200, ['Vary' => 'Foo Bar']);
$this->store->write($req2, $res2);
$this->assertEquals($this->getStorePath('en'.hash('sha256', 'test 2')), $this->store->lookup($req2)->getContent());
$req3 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar'));
$res3 = new Response('test 3', 200, array('Vary' => 'Foo Bar'));
$req3 = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar']);
$res3 = new Response('test 3', 200, ['Vary' => 'Foo Bar']);
$key = $this->store->write($req3, $res3);
$this->assertEquals($this->getStorePath('en'.hash('sha256', 'test 3')), $this->store->lookup($req3)->getContent());
@@ -226,10 +280,10 @@ class StoreTest extends TestCase
public function testLocking()
{
$req = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar'));
$req = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar']);
$this->assertTrue($this->store->lock($req));
$path = $this->store->lock($req);
$this->store->lock($req);
$this->assertTrue($this->store->isLocked($req));
$this->store->unlock($req);
@@ -263,14 +317,14 @@ class StoreTest extends TestCase
$this->assertEmpty($this->getStoreMetadata($requestHttps));
}
protected function storeSimpleEntry($path = null, $headers = array())
protected function storeSimpleEntry($path = null, $headers = [])
{
if (null === $path) {
$path = '/test';
}
$this->request = Request::create($path, 'get', array(), array(), array(), $headers);
$this->response = new Response('test', 200, array('Cache-Control' => 'max-age=420'));
$this->request = Request::create($path, 'get', [], [], [], $headers);
$this->response = new Response('test', 200, ['Cache-Control' => 'max-age=420']);
return $this->store->write($this->request, $this->response);
}