TYPO3 CMS  TYPO3_7-6
IpAnonymizationUtilityTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
18 
23 {
24 
31  {
32  return [
33  'empty address' => ['', 1, ''],
34  'IPv4 address with mask 0' => ['192.158.130.10', 0, '192.158.130.10'],
35  'IPv4 address with mask 1' => ['192.158.130.10', 1, '192.158.130.0'],
36  'IPv4 address with mask 2' => ['192.158.130.10', 2, '192.158.0.0'],
37  'IPv4 address with fallback' => ['192.158.130.10', null, '192.158.130.0'],
38  'IPv6 address with mask 0' => ['0064:ff9b:0000:0000:0000:0000:18.52.86.120', 0, '0064:ff9b:0000:0000:0000:0000:18.52.86.120'],
39  'IPv6 address with mask 1' => ['2002:6dcd:8c74:6501:fb2:61c:ac98:6bea', 1, '2002:6dcd:8c74:6501::'],
40  'IPv6 address with mask 2' => ['2002:6dcd:8c74:6501:fb2:61c:ac98:6bea', 2, '2002:6dcd:8c74::'],
41  'IPv6 address with fallback' => ['2002:6dcd:8c74:6501:fb2:61c:ac98:6bea', null, '2002:6dcd:8c74:6501::'],
42  'IPv4-Embedded IPv6 Address' => ['::ffff:18.52.86.120', 1, '::'],
43  'anonymized IPv4 address' => ['192.158.0.0', 1, '192.158.0.0'],
44  ];
45  }
46 
54  public function anonymizeIpReturnsCorrectValue($address, $mask = null, $expected)
55  {
56  // set the default if $mask is null
57  $GLOBALS['TYPO3_CONF_VARS']['SYS']['ipAnonymization'] = 1;
58  $this->assertEquals($expected, IpAnonymizationUtility::anonymizeIp($address, $mask));
59  }
60 
67  {
69  }
70 }
static static static anonymizeIp($address, $mask=null)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']