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