[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/_test/tests/inc/ -> remoteapicore_aclcheck.test.php (source)

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