1<?php 2/** 3 * auth_loadACL carries out the user & group substitutions 4 * 5 * @author Chris Smith <chris@jalakai.co.uk> 6 */ 7 8class auth_loadacl_test extends DokuWikiTest { 9 10 function setUp() { 11 global $USERINFO; 12 parent::setUp(); 13 $_SERVER['REMOTE_USER'] = 'testuser'; 14 $USERINFO['grps'] = array('foo','bar'); 15 } 16 17 function tearDown() { 18 parent::tearDown(); 19 } 20 21 function auth_loadACL_testwrapper($acls) { 22 global $config_cascade; 23 $acl_file = $config_cascade['acl']['default']; 24 25 $config_cascade['acl']['default'] .= '.test'; 26 file_put_contents($config_cascade['acl']['default'],$acls); 27 28 $result = auth_loadACL(); 29 30 unlink($config_cascade['acl']['default']); 31 $config_cascade['acl']['default'] = $acl_file; 32 33 return $result; 34 } 35 36 function test_simple() { 37 $acls = <<<ACL 38* @ALL 2 39ACL; 40 $expect = array("*\t@ALL 2"); 41 $this->assertEquals($expect, $this->auth_loadACL_testwrapper($acls)); 42 } 43 44 function test_user_substitution() { 45 $acls = <<<ACL 46%USER% %USER% 2 47ACL; 48 $expect = array( 49 "testuser\ttestuser 2", 50 ); 51 $this->assertEquals($expect, $this->auth_loadACL_testwrapper($acls)); 52 } 53 54 function test_group_substitution() { 55 $acls = <<<ACL 56%GROUP% %GROUP% 2 57ACL; 58 $expect = array( 59 "foo\t@foo 2", 60 "bar\t@bar 2", 61 ); 62 $this->assertEquals($expect, $this->auth_loadACL_testwrapper($acls)); 63 } 64 65 function test_both_substitution() { 66 $acls = <<<ACL 67%GROUP%:%USER% %USER% 2 68%GROUP%:%USER% %GROUP% 2 69ACL; 70 $expect = array( 71 "foo:testuser\ttestuser 2", 72 "bar:testuser\ttestuser 2", 73 "foo:testuser\t@foo 2", 74 "bar:testuser\t@bar 2", 75 ); 76 $this->assertEquals($expect, $this->auth_loadACL_testwrapper($acls)); 77 } 78 79 // put it all together - read the standard acl provided with the test suite 80 function test_standardtestacls(){ 81 $expect = array( 82 "*\t@ALL 8", 83 "private:*\t@ALL 0", 84 "users:*\t@ALL 1", 85 "users:testuser:*\ttestuser 16", 86 "groups:*\t@ALL 1", 87 "groups:foo:*\t@foo 16", 88 "groups:bar:*\t@bar 16", 89 ); 90 $this->assertEquals($expect, auth_loadACL()); 91 } 92 93 // FS#2867, '\s' in php regular expressions may match non-space characters utf8 strings 94 // this is due to locale setting on the server, which may match bytes '\xA0' and '\x85' 95 // these two bytes are present in valid multi-byte UTF-8 characters. 96 // this test will use one, 'ठ' (DEVANAGARI LETTER TTHA, e0 a4 a0). There are many others. 97 function test_FS2867() { 98 global $USERINFO; 99 100 setlocale(LC_ALL, "English_United States.1252"); // should only succeed on windows systems 101 setlocale(LC_ALL, "en_US.UTF-8"); // should succeed on other systems 102 103 // no point continuing with this test if \s doesn't match A0 104 if (!preg_match('/\s/',"\xa0")) { 105 $this->markTestSkipped('Unable to change locale.'); 106 } 107 108 $_SERVER['REMOTE_USER'] = 'utfठ8'; 109 $USERINFO['grps'] = array('utfठ16','utfठa'); 110 111 $acls = <<<ACL 112%GROUP%:%USER% %USER% 2 113%GROUP%:* %GROUP% 4 114devangariठttha @ALL 2 115ACL; 116 $expect = array( 117 "utfठ16:utfठ8\tutfठ8 2", 118 "utfठa:utfठ8\tutfठ8 2", 119 "utfठ16:*\t@utfठ16 4", 120 "utfठa:*\t@utfठa 4", 121 "devangariठttha\t@ALL 2", 122 ); 123 $this->assertEquals($expect, $this->auth_loadACL_testwrapper($acls)); 124 } 125} 126 127//Setup VIM: ex: et ts=4 : 128