1<?php 2 3namespace dokuwiki\test\Remote; 4 5use dokuwiki\Remote\Api; 6 7/** 8 * Class remoteapicore_test 9 */ 10class 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('wiki.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('wiki.aclCheck', $params)); 91 92 $params = [ 93 'nice_page', 94 'mwuser' // member of group 'more' 95 ]; 96 $this->assertEquals(AUTH_CREATE, $this->remote->call('wiki.aclCheck', $params)); 97 98 $params = [ 99 'nice_page', 100 'mwuser', 101 [] //groups not retrieved 102 ]; 103 $this->assertEquals(AUTH_NONE, $this->remote->call('wiki.aclCheck', $params)); 104 105 $params = [ 106 'nice_page', 107 'notexistinguser', 108 ['more'] 109 ]; 110 $this->assertEquals(AUTH_CREATE, $this->remote->call('wiki.aclCheck', $params)); 111 112 $params = [ 113 'nice_page', 114 'user2' 115 ]; 116 $this->assertEquals(AUTH_UPLOAD, $this->remote->call('wiki.aclCheck', $params)); 117 118 $params = [ 119 'nice_page', 120 'user2', 121 [] //groups not retrieved 122 ]; 123 $this->assertEquals(AUTH_UPLOAD, $this->remote->call('wiki.aclCheck', $params)); 124 125 $params = [ 126 'unknown_page', 127 'user2' 128 ]; 129 $this->assertEquals(AUTH_EDIT, $this->remote->call('wiki.aclCheck', $params)); 130 131 $params = [ 132 'unknown_page', 133 'user2', 134 [] //groups not retrieved 135 ]; 136 $this->assertEquals(AUTH_NONE, $this->remote->call('wiki.aclCheck', $params)); 137 138 $params = array( 139 'nice_page', 140 'testuser' // superuser set via conf 141 ); 142 $this->assertEquals(AUTH_ADMIN, $this->remote->call('wiki.aclCheck', $params)); 143 } 144 145} 146