[ Index ] |
PHP Cross Reference of DokuWiki |
[Summary view] [Print] [Text view]
1 <?php 2 3 namespace dokuwiki\test\Remote; 4 5 use dokuwiki\Remote\Api; 6 7 /** 8 * Class remoteapicore_test 9 */ 10 class ApiCoreAclCheckTest extends \DokuWikiTest { 11 12 protected $userinfo; 13 protected $oldAuthAcl; 14 /** @var Api */ 15 protected $remote; 16 17 protected $pluginsEnabled = array('auth_plugin_authplain'); 18 19 protected function reloadUsers() { 20 global $auth; 21 22 /* auth caches data loaded from file, but recreated object forces reload */ 23 $auth = new \auth_plugin_authplain(); 24 } 25 26 public function setUp() : void { 27 global $config_cascade; 28 global $conf; 29 global $USERINFO; 30 global $AUTH_ACL; 31 32 parent::setUp(); 33 34 $name = $config_cascade['plainauth.users']['default']; 35 copy($name, $name . ".orig"); 36 $this->reloadUsers(); 37 38 $this->oldAuthAcl = $AUTH_ACL; 39 $this->userinfo = $USERINFO; 40 41 $conf['remote'] = 1; 42 $conf['remoteuser'] = '@user'; 43 $conf['useacl'] = 0; 44 45 $this->remote = new Api(); 46 47 } 48 49 public function tearDown() : void { 50 global $USERINFO; 51 global $AUTH_ACL; 52 global $config_cascade; 53 54 parent::tearDown(); 55 56 $USERINFO = $this->userinfo; 57 $AUTH_ACL = $this->oldAuthAcl; 58 59 $name = $config_cascade['plainauth.users']['default']; 60 copy($name . ".orig", $name); 61 } 62 63 public function testCheckacl() { 64 global $conf; 65 global $AUTH_ACL, $USERINFO; 66 /** @var auth_plugin_authplain $auth */ 67 global $auth; 68 69 $conf['useacl'] = 1; 70 $_SERVER['REMOTE_USER'] = 'john'; 71 $USERINFO['grps'] = ['user']; 72 $AUTH_ACL = [ 73 '* @ALL 0', //none 74 '* @user 2', //edit 75 '* @more 4', //create 76 'nice_page user2 8' //upload 77 ]; 78 79 $params = ['nice_page']; 80 $this->assertEquals(AUTH_EDIT, $this->remote->call('core.aclCheck', $params)); 81 82 $auth->createUser("user1", "54321", "a User", "you@example.com"); 83 $auth->createUser("user2", "543210", "You", "he@example.com"); 84 $auth->createUser("mwuser", "12345", "Wiki User", "me@example.com", ['more']); //not in default group 85 86 $params = [ 87 'nice_page', 88 'user1' 89 ]; 90 $this->assertEquals(AUTH_EDIT, $this->remote->call('core.aclCheck', $params)); 91 92 $params = [ 93 'nice_page', 94 'mwuser', 95 // member of group 'more' (automatically retrieved) 96 ]; 97 $this->assertEquals(AUTH_CREATE, $this->remote->call('core.aclCheck', $params)); 98 99 $params = [ 100 'nice_page', 101 'mwuser', 102 [] // member of group 'more' (automatically retrieved) 103 ]; 104 $this->assertEquals(AUTH_CREATE, $this->remote->call('core.aclCheck', $params)); 105 106 $params = [ 107 'nice_page', 108 'notexistinguser', 109 ['more'] 110 ]; 111 $this->assertEquals(AUTH_CREATE, $this->remote->call('core.aclCheck', $params)); 112 113 $params = [ 114 'nice_page', 115 'user2', 116 // (automatically retrieved) 117 ]; 118 $this->assertEquals(AUTH_UPLOAD, $this->remote->call('core.aclCheck', $params)); 119 120 $params = [ 121 'nice_page', 122 'user2', 123 [] // (automatically retrieved) 124 ]; 125 $this->assertEquals(AUTH_UPLOAD, $this->remote->call('core.aclCheck', $params)); 126 127 $params = [ 128 'unknown_page', 129 'user2', 130 // (automatically retrieved) 131 ]; 132 $this->assertEquals(AUTH_EDIT, $this->remote->call('core.aclCheck', $params)); 133 134 $params = [ 135 'unknown_page', 136 'user2', 137 [] // (automatically retrieved) 138 ]; 139 $this->assertEquals(AUTH_EDIT, $this->remote->call('core.aclCheck', $params)); 140 141 $params = array( 142 'nice_page', 143 'testuser', // superuser set via conf 144 // (automatically retrieved) 145 ); 146 $this->assertEquals(AUTH_ADMIN, $this->remote->call('core.aclCheck', $params)); 147 } 148 149 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body