File: SimpleTest.php

package info (click to toggle)
simplesamlphp 1.16.3-1%2Bdeb10u2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 21,036 kB
  • sloc: php: 73,175; ansic: 875; sh: 83; perl: 82; xml: 52; makefile: 46
file content (89 lines) | stat: -rw-r--r-- 3,344 bytes parent folder | download
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php

namespace SimpleSAML\Test\Auth;

/**
 * Tests for \SimpleSAML\Auth\Simple
 *
 */
class SimpleTest extends \SimpleSAML\Test\Utils\ClearStateTestCase
{

    /**
     * @test
     */
    public function testGetProcessedURL()
    {
        $class = new \ReflectionClass('\SimpleSAML\Auth\Simple');
        $method = $class->getMethod('getProcessedURL');
        $method->setAccessible(true);

        // fool the routines to make them believe we are running in a web server
        $_SERVER['REQUEST_URI'] = '/';

        // test merging configuration option with passed URL
        \SimpleSAML_Configuration::loadFromArray(array(
            'application' => array(
                'baseURL' => 'https://example.org'
            )
        ), '[ARRAY]', 'simplesaml');

        $s = new \SimpleSAML\Auth\Simple('');

        $this->assertEquals('https://example.org/', $method->invokeArgs($s, array(null)));

        // test a full URL passed as parameter
        $this->assertEquals(
            'https://example.org/foo/bar?a=b#fragment',
            $method->invokeArgs(
                $s,
                array('http://some.overridden.host/foo/bar?a=b#fragment')
            )
        );

        // test a full, current URL with no parameters
        $_SERVER['REQUEST_URI'] = '/foo/bar?a=b#fragment';
        $this->assertEquals('https://example.org/foo/bar?a=b#fragment', $method->invokeArgs($s, array(null)));

        // test ports are overridden by configuration
        $_SERVER['SERVER_PORT'] = '1234';
        $this->assertEquals('https://example.org/foo/bar?a=b#fragment', $method->invokeArgs($s, array(null)));

        // test config option with ending with / and port
        \SimpleSAML_Configuration::loadFromArray(array(
            'application' => array(
                'baseURL' => 'http://example.org:8080/'
            )
        ), '[ARRAY]', 'simplesaml');
        $s = new \SimpleSAML\Auth\Simple('');
        $this->assertEquals('http://example.org:8080/foo/bar?a=b#fragment', $method->invokeArgs($s, array(null)));

        // test again with a relative URL as a parameter
        $this->assertEquals(
            'http://example.org:8080/something?foo=bar#something',
            $method->invokeArgs($s, array('/something?foo=bar#something'))
        );

        // now test with no configuration
        $_SERVER['SERVER_NAME'] = 'example.org';
        \SimpleSAML_Configuration::loadFromArray(array(), '[ARRAY]', 'simplesaml');
        $s = new \SimpleSAML\Auth\Simple('');
        $this->assertEquals('http://example.org:1234/foo/bar?a=b#fragment', $method->invokeArgs($s, array(null)));

        // no configuration, https and port
        $_SERVER['HTTPS'] = 'on';
        $this->assertEquals('https://example.org:1234/foo/bar?a=b#fragment', $method->invokeArgs($s, array(null)));

        // no configuration and a relative URL as a parameter
        $this->assertEquals(
            'https://example.org:1234/something?foo=bar#something',
            $method->invokeArgs($s, array('/something?foo=bar#something'))
        );

        // finally, no configuration and full URL as a parameter
        $this->assertEquals(
            'https://example.org/one/two/three?foo=bar#fragment',
            $method->invokeArgs($s, array('https://example.org/one/two/three?foo=bar#fragment'))
        );
    }
}