Welcome to mirror list, hosted at ThFree Co, Russian Federation.

NonceTest.php « Core « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9d0d8ef37db27d36f36679623a45e8d64ad2946e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
use Piwik\Config;
use Piwik\Nonce;

/**
 * Piwik - free/libre analytics platform
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */
class NonceTest extends PHPUnit_Framework_TestCase
{
    /**
     * Dataprovider for acceptable origins test
     */
    public function getAcceptableOriginsTestData()
    {
        return array(
            // HTTP_HOST => expected
            array('example.com', array('http://example.com', 'https://example.com')),
            array('example.com:80', array('http://example.com', 'https://example.com')),
            array('example.com:443', array('http://example.com', 'https://example.com')),
            array('example.com:8080', array('http://example.com', 'https://example.com', 'http://example.com:8080', 'https://example.com:8080')),
        );
    }

    /**
     * @dataProvider getAcceptableOriginsTestData
     * @group Core
     */
    public function test_getAcceptableOrigins($host, $expected)
    {
        Config::getInstance()->General['enable_trusted_host_check'] = 0;
        $_SERVER['HTTP_HOST'] = $host;
        Config::getInstance()->General['trusted_hosts'] = array('example.com');
        $this->assertEquals($expected, Nonce::getAcceptableOrigins(), $host);
    }
}