[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

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

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