Skip to content

Commit

Permalink
bug #22079 [HttpKernel] Fixed bug with purging of HTTPS URLs (ausi)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 2.7 branch (closes #22079).

Discussion
----------

[HttpKernel] Fixed bug with purging of HTTPS URLs

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

I found two bugs in `HttpCache\Store::purge()` with HTTPS URLs:

1. `->purge('https://example.com/')` only purges the `http` version not the `https` one.
2. If a cache entry exists for both `http` and `https`, only the `http` version gets purged, the `https` version stays in the cache.

I think this issues were introduced with #21582.

This pull request fixes both issues and adds tests for them.

Commits
-------

f509150 [HttpKernel] Fixed bug with purging of HTTPS URLs
  • Loading branch information
fabpot committed Mar 21, 2017
2 parents 2ba564d + f509150 commit 35e66ae
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Symfony/Component/HttpKernel/HttpCache/Store.php
Expand Up @@ -325,10 +325,13 @@ private function getMetadata($key)
*/
public function purge($url)
{
$http = preg_replace('#^https#', 'http', $url);
$https = preg_replace('#^http#', 'https', $url);
$http = preg_replace('#^https:#', 'http:', $url);
$https = preg_replace('#^http:#', 'https:', $url);

return $this->doPurge($http) || $this->doPurge($https);
$purgedHttp = $this->doPurge($http);
$purgedHttps = $this->doPurge($https);

return $purgedHttp || $purgedHttps;
}

/**
Expand Down
27 changes: 27 additions & 0 deletions src/Symfony/Component/HttpKernel/Tests/HttpCache/StoreTest.php
Expand Up @@ -236,6 +236,33 @@ public function testLocking()
$this->assertFalse($this->store->isLocked($req));
}

public function testPurgeHttps()
{
$request = Request::create('https://example.com/foo');
$this->store->write($request, new Response('foo'));

$this->assertNotEmpty($this->getStoreMetadata($request));

$this->assertTrue($this->store->purge('https://example.com/foo'));
$this->assertEmpty($this->getStoreMetadata($request));
}

public function testPurgeHttpAndHttps()
{
$requestHttp = Request::create('https://example.com/foo');
$this->store->write($requestHttp, new Response('foo'));

$requestHttps = Request::create('http://example.com/foo');
$this->store->write($requestHttps, new Response('foo'));

$this->assertNotEmpty($this->getStoreMetadata($requestHttp));
$this->assertNotEmpty($this->getStoreMetadata($requestHttps));

$this->assertTrue($this->store->purge('http://example.com/foo'));
$this->assertEmpty($this->getStoreMetadata($requestHttp));
$this->assertEmpty($this->getStoreMetadata($requestHttps));
}

protected function storeSimpleEntry($path = null, $headers = array())
{
if (null === $path) {
Expand Down

0 comments on commit 35e66ae

Please sign in to comment.