summaryrefslogtreecommitdiff
path: root/_test/tests/inc/auth_loadacl.test.php
blob: 5e7ac3acf5e9540c79845fbe6b2e02cf8da84f64 (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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/**
 *  auth_loadACL carries out the user & group substitutions
 *
 */

class auth_loadacl_test extends DokuWikiTest {

    function setUp() {
        global $USERINFO;
        parent::setUp();
        $_SERVER['REMOTE_USER'] = 'testuser';
        $USERINFO['grps'] = array('foo','bar');
    }

    function tearDown() {
        parent::tearDown();
    }

    function auth_loadACL_testwrapper($acls) {
        global $config_cascade;
        $acl_file = $config_cascade['acl']['default'];

        $config_cascade['acl']['default'] .= '.test';
        file_put_contents($config_cascade['acl']['default'],$acls);

        $result = auth_loadACL();

        unlink($config_cascade['acl']['default']);
        $config_cascade['acl']['default'] = $acl_file;

        return $result;
    }

    function test_simple() {
        $acls = <<<ACL
* @ALL 2
ACL;
        $expect = array("*\t@ALL 2");
        $this->assertEquals($expect, $this->auth_loadACL_testwrapper($acls));
    }

    function test_user_substitution() {
        $acls = <<<ACL
%USER% %USER% 2
ACL;
        $expect = array(
            "testuser\ttestuser 2",
        );
        $this->assertEquals($expect, $this->auth_loadACL_testwrapper($acls));
    }

    function test_group_substitution() {
        $acls = <<<ACL
%GROUP% %GROUP% 2
ACL;
        $expect = array(
            "foo\t@foo 2",
            "bar\t@bar 2",
        );
        $this->assertEquals($expect, $this->auth_loadACL_testwrapper($acls));
    }

    function test_both_substitution() {
        $acls = <<<ACL
%GROUP%:%USER% %USER% 2
%GROUP%:%USER% %GROUP% 2
ACL;
        $expect = array(
            "foo:testuser\ttestuser 2",
            "bar:testuser\ttestuser 2",
            "foo:testuser\t@foo 2",
            "bar:testuser\t@bar 2",
        );
        $this->assertEquals($expect, $this->auth_loadACL_testwrapper($acls));
    }

    // put it all together - read the standard acl provided with the test suite
    function test_standardtestacls(){
        $expect = array(
            "*\t@ALL        8",
            "private:*\t@ALL        0",
            "users:*\t@ALL         1",
            "users:testuser:*\ttestuser       16",
            "groups:*\t@ALL         1",
            "groups:foo:*\t@foo      16",
            "groups:bar:*\t@bar      16",
        );
        $this->assertEquals($expect, auth_loadACL());
    }

    // FS#2867, '\s' in php regular expressions may match non-space characters utf8 strings
    // this is due to locale setting on the server, which may match bytes '\xA0' and '\x85'
    // these two bytes are present in valid multi-byte UTF-8 characters.
    // this test will use one, 'ठ' (DEVANAGARI LETTER TTHA, e0 a4 a0).  There are many others. 
    function test_FS2867() {
        global $USERINFO;

        setlocale(LC_ALL, "English_United States.1252");  // should only succeed on windows systems
        setlocale(LC_ALL, "en_US.UTF-8");                 // should succeed on other systems

        $_SERVER['REMOTE_USER'] = 'utfठ8';
        $USERINFO['grps'] = array('utfठ16','utfठa');

        $acls = <<<ACL
%GROUP%:%USER% %USER% 2
%GROUP%:* %GROUP% 4
devangariठttha @ALL 2
ACL;
        $expect = array(
            "utfठ16:utfठ8\tutfठ8 2",
            "utfठa:utfठ8\tutfठ8 2",
            "utfठ16:*\t@utfठ16 4",
            "utfठa:*\t@utfठa 4",
            "devangariठttha\t@ALL 2",
        );
        $this->assertEquals($expect, $this->auth_loadACL_testwrapper($acls));
    }
}

//Setup VIM: ex: et ts=4 :