Skip to content

Commit 6cbcd83

Browse files
committed
Merge pull request #180 from FriendsOfSymfony/test-user-context-anonymous
Test user without credentials
2 parents 2623071 + fbaa336 commit 6cbcd83

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSHttpCache package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
header('X-Cache-Debug: 1');
13+
14+
header('Cache-Control: max-age=3600');
15+
header('Vary: X-User-Context-Hash');
16+
17+
if (!isset($_COOKIE[0])) {
18+
header('X-HashTest: anonymous');
19+
echo "anonymous";
20+
} elseif ($_COOKIE[0] == "foo") {
21+
header('X-HashTest: foo');
22+
echo "foo";
23+
} else {
24+
header('X-HashTest: bar');
25+
echo "bar";
26+
}

tests/Functional/Varnish/UserContextTestCase.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,29 @@ public function testUserContextHash()
6868
$this->assertHit($headResponse2);
6969
}
7070

71+
/**
72+
* Making sure that non-authenticated and authenticated cache are not mixed up.
73+
*/
74+
public function testUserContextNoAuth()
75+
{
76+
$response1 = $this->getResponse('/user_context_anon.php');
77+
$this->assertEquals('anonymous', $response1->getBody(true));
78+
$this->assertEquals('MISS', $response1->getHeader('X-HashCache'));
79+
80+
$response1 = $this->getResponse('/user_context_anon.php', array(), array('cookies' => array('foo')));
81+
$this->assertEquals('foo', $response1->getBody(true));
82+
$this->assertEquals('MISS', $response1->getHeader('X-HashCache'));
83+
84+
$cachedResponse1 = $this->getResponse('/user_context_anon.php');
85+
$this->assertEquals('anonymous', $cachedResponse1->getBody(true));
86+
$this->assertHit($cachedResponse1);
87+
88+
$cachedResponse1 = $this->getResponse('/user_context_anon.php', array(), array('cookies' => array('foo')));
89+
$this->assertEquals('foo', $cachedResponse1->getBody(true));
90+
$this->assertContextCache($cachedResponse1->getHeader('X-HashCache'));
91+
$this->assertHit($cachedResponse1);
92+
}
93+
7194
public function testAcceptHeader()
7295
{
7396
$response1 = $this->getResponse(

0 commit comments

Comments
 (0)