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