TYPO3 CMS  TYPO3_6-2
CacheHashCalculatorTest.php
Go to the documentation of this file.
1 <?php
3 
23 
27  protected $fixture;
28 
32  protected $confCache = array();
33 
34  public function setUp() {
35  $this->confCache = array(
36  'encryptionKey' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']
37  );
38  $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = 't3lib_cacheHashTest';
39  $this->fixture = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\CacheHashCalculator', array('foo'));
40  $this->fixture->setConfiguration(array(
41  'excludedParameters' => array('exclude1', 'exclude2'),
42  'cachedParametersWhiteList' => array(),
43  'requireCacheHashPresenceParameters' => array('req1', 'req2'),
44  'excludedParametersIfEmpty' => array(),
45  'includePageId' => TRUE,
46  'excludeAllEmptyParameters' => FALSE
47  ));
48  }
49 
54  public function cacheHashCalculationWorks($params, $expected) {
55  $this->assertEquals($expected, $this->fixture->calculateCacheHash($params));
56  }
57 
62  return array(
63  'Empty parameters should not return a hash' => array(
64  array(),
65  ''
66  ),
67  'Trivial key value combination should generate hash' => array(
68  array(
69  'encryptionKey' => 't3lib_cacheHashTest',
70  'key' => 'value'
71  ),
72  '5cfdcf826275558b3613dd51714a0a17'
73  ),
74  'Multiple parameters should generate hash' => array(
75  array(
76  'a' => 'v',
77  'b' => 'v',
78  'encryptionKey' => 't3lib_cacheHashTest'
79  ),
80  '0f40b089cdad149aea99e9bf4badaa93'
81  )
82  );
83  }
84 
89  public function getRelevantParametersWorks($params, $expected) {
90  $actual = $this->fixture->getRelevantParameters($params);
91  $this->assertEquals($expected, array_keys($actual));
92  }
93 
98  return array(
99  'Empty list should be passed through' => array('', array()),
100  'Simple parameter should be passed through and the encryptionKey should be added' => array(
101  'key=v&id=42',
102  array('encryptionKey', 'id', 'key')
103  ),
104  'Simple parameter should be passed through' => array(
105  'key1=v&key2=v&id=42',
106  array('encryptionKey', 'id', 'key1', 'key2')
107  ),
108  'System and exclude parameters should be omitted' => array(
109  'id=1&type=3&exclude1=x&no_cache=1',
110  array()
111  ),
112  'System and exclude parameters (except id) should be omitted, others should stay' => array(
113  'id=1&type=3&key=x&no_cache=1',
114  array('encryptionKey', 'id', 'key')
115  ),
116  'System and exclude parameters should be omitted and id is not required to be specified' => array(
117  '&type=3&no_cache=1',
118  array()
119  )
120  );
121  }
122 
127  public function canGenerateForParameters($params, $expected) {
128  $this->assertEquals($expected, $this->fixture->generateForParameters($params));
129  }
130 
137  $this->fixture->generateForParameters('&key=x');
138  }
139 
144  $knowHash = 'fac112f7e662c83c19b57142c3a921f5';
145  return array(
146  'Empty parameters should not return an hash' => array('&id=42', ''),
147  'Querystring has no relevant parameters so we should not have a cacheHash' => array('&exclude1=val', ''),
148  'Querystring has only system parameters so we should not have a cacheHash' => array('&id=42&type=val', ''),
149  'Trivial key value combination should generate hash' => array('&id=42&key=value', $knowHash),
150  'Only the relevant parts should be taken into account' => array('&id=42&key=value&exclude1=val', $knowHash),
151  'Only the relevant parts should be taken into account(exclude2 before key)' => array('&id=42&exclude2=val&key=value', $knowHash),
152  'System parameters should not be taken into account (except id)' => array('&id=42&type=23&key=value', $knowHash),
153  'Admin panel parameters should not be taken into account' => array('&id=42&TSFE_ADMIN_PANEL[display]=7&key=value', $knowHash),
154  'Trivial hash for sorted parameters should be right' => array('&id=42&a=v&b=v', '52c8a1299e20324f90377c43153c4987'),
155  'Parameters should be sorted before cHash is created' => array('&id=42&b=v&a=v', '52c8a1299e20324f90377c43153c4987'),
156  'Empty argument names are filtered out before cHash calculation' => array('&id=42&b=v&a=v&=dummy', '52c8a1299e20324f90377c43153c4987')
157  );
158  }
159 
164  public function parametersRequireCacheHashWorks($params, $expected) {
165  $this->assertEquals($expected, $this->fixture->doParametersRequireCacheHash($params));
166  }
167 
172  return array(
173  'Empty parameter strings should not require anything.' => array('', FALSE),
174  'Normal parameters aren\'t required.' => array('key=value', FALSE),
175  'Configured "req1" to be required.' => array('req1=value', TRUE),
176  'Configured "req1" to be required, should also work in combined context' => array('&key=value&req1=value', TRUE),
177  'Configured "req1" to be required, should also work in combined context (key at the end)' => array('req1=value&key=value', TRUE)
178  );
179  }
180 
188  public function canWhitelistParameters($params, $expected) {
189  $method = new \ReflectionMethod('TYPO3\\CMS\\Frontend\\Page\\CacheHashCalculator', 'setCachedParametersWhiteList');
190  $method->setAccessible(TRUE);
191  $method->invoke($this->fixture, array('whitep1', 'whitep2'));
192  $this->assertEquals($expected, $this->fixture->generateForParameters($params));
193  }
194 
199  $oneParamHash = 'eae50a13101afd53a9d2c543230eb5bb';
200  $twoParamHash = '701e2d2f1becc9d1b71d327e5cb1c3ed';
201  return array(
202  'Even with the whitelist enabled, empty parameters should not return an hash.' => array('', ''),
203  'Whitelisted parameters should have a hash.' => array('&id=42&whitep1=value', $oneParamHash),
204  'Blacklisted parameter should not influence hash.' => array('&id=42&whitep1=value&black=value', $oneParamHash),
205  'Multiple whitelisted parameters should work' => array('&id=42&whitep1=value&whitep2=value', $twoParamHash),
206  'The order should not influce the hash.' => array('&id=42&whitep2=value&black=value&whitep1=value', $twoParamHash)
207  );
208  }
209 
214  public function canSkipParametersWithEmptyValues($params, $settings, $expected) {
215  $this->fixture->setConfiguration($settings);
216  $actual = $this->fixture->getRelevantParameters($params);
217  $this->assertEquals($expected, array_keys($actual));
218  }
219 
224  return array(
225  'The default configuration does not allow to skip an empty key.' => array(
226  '&id=42&key1=v&key2=&key3=',
227  array('excludedParametersIfEmpty' => array(), 'excludeAllEmptyParameters' => FALSE),
228  array('encryptionKey', 'id', 'key1', 'key2', 'key3')
229  ),
230  'Due to the empty value, "key2" should be skipped(with equals sign' => array(
231  '&id=42&key1=v&key2=&key3=',
232  array('excludedParametersIfEmpty' => array('key2'), 'excludeAllEmptyParameters' => FALSE),
233  array('encryptionKey', 'id', 'key1', 'key3')
234  ),
235  'Due to the empty value, "key2" should be skipped(without equals sign)' => array(
236  '&id=42&key1=v&key2&key3',
237  array('excludedParametersIfEmpty' => array('key2'), 'excludeAllEmptyParameters' => FALSE),
238  array('encryptionKey', 'id', 'key1', 'key3')
239  ),
240  'Due to the empty value, "key2" and "key3" should be skipped' => array(
241  '&id=42&key1=v&key2=&key3=',
242  array('excludedParametersIfEmpty' => array(), 'excludeAllEmptyParameters' => TRUE),
243  array('encryptionKey', 'id', 'key1')
244  )
245  );
246  }
247 
248 }
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]