File: StateTest.php

package info (click to toggle)
simplesamlphp 1.14.11-1%2Bdeb9u2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 15,024 kB
  • sloc: php: 72,337; xml: 1,078; python: 376; sh: 220; perl: 185; makefile: 57
file content (81 lines) | stat: -rw-r--r-- 2,517 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
<?php


/**
 * Tests for SimpleSAML_Auth_State
 */
class Auth_StateTest extends PHPUnit_Framework_TestCase
{


    /**
     * Test the getPersistentAuthData() function.
     */
    public function testGetPersistentAuthData()
    {

        $mandatory = array(
            'Attributes' => array(),
            'Expire' => 1234,
            'LogoutState' => 'logoutState',
            'AuthInstant' => 123456,
            'RememberMe' => true,
            'saml:sp:NameID' => 'nameID',
        );

        // check just mandatory parameters
        $state = $mandatory;
        $expected = $mandatory;
        $this->assertEquals(
            $expected,
            SimpleSAML_Auth_State::getPersistentAuthData($state),
            'Mandatory state attributes did not survive as expected'.print_r($expected, true)
        );

        // check missing mandatory parameters
        unset($state['LogoutState']);
        unset($state['RememberMe']);
        $expected = $state;
        $this->assertEquals(
            $expected,
            SimpleSAML_Auth_State::getPersistentAuthData($state),
            'Some error occurred with missing mandatory parameters'
        );

        // check additional non-persistent parameters
        $additional = array(
            'additional1' => 1,
            'additional2' => 2,
        );
        $state = array_merge($mandatory, $additional);
        $expected = $mandatory;
        $this->assertEquals(
            $expected,
            SimpleSAML_Auth_State::getPersistentAuthData($state),
            'Additional parameters survived'
        );

        // check additional persistent parameters
        $additional['PersistentAuthData'] = array('additional1');
        $state = array_merge($mandatory, $additional);
        $expected = $state;
        unset($expected['additional2']);
        unset($expected['PersistentAuthData']);
        $this->assertEquals(
            $expected,
            SimpleSAML_Auth_State::getPersistentAuthData($state),
            'Some error occurred with additional, persistent parameters'
        );

        // check only additional persistent parameters
        $state = $additional;
        $expected = $state;
        unset($expected['additional2']);
        unset($expected['PersistentAuthData']);
        $this->assertEquals(
            $expected,
            SimpleSAML_Auth_State::getPersistentAuthData($state),
            'Some error occurred with additional, persistent parameters, and no mandatory ones'
        );
    }
}