diff options
-rw-r--r-- | _test/cases/inc/remote.test.php | 46 | ||||
-rw-r--r-- | inc/remote.php | 13 |
2 files changed, 54 insertions, 5 deletions
diff --git a/_test/cases/inc/remote.test.php b/_test/cases/inc/remote.test.php index 23186344b..b6a683f45 100644 --- a/_test/cases/inc/remote.test.php +++ b/_test/cases/inc/remote.test.php @@ -99,12 +99,15 @@ class remote_plugin_testplugin extends DokuWiki_Remote_Plugin { class remote_test extends UnitTestCase { var $originalConf; + var $userinfo; var $remote; function setUp() { global $plugin_controller; global $conf; + global $USERINFO; + parent::setUp(); $pluginManager = new MockDoku_Plugin_Controller(); $pluginManager->setReturnValue('getList', array('testplugin')); @@ -112,13 +115,19 @@ class remote_test extends UnitTestCase { $plugin_controller = $pluginManager; $this->originalConf = $conf; + $conf['remote'] = 1; + $conf['useacl'] = 0; + $this->userinfo = $USERINFO; $this->remote = new RemoteAPI(); } function tearDown() { global $conf; + global $USERINFO; $conf = $this->originalConf; + $USERINFO = $this->userinfo; + } function test_pluginMethods() { @@ -131,8 +140,6 @@ class remote_test extends UnitTestCase { } function test_hasAccessSuccess() { - global $conf; - $conf['remote'] = 1; $this->assertTrue($this->remote->hasAccess()); } @@ -142,6 +149,41 @@ class remote_test extends UnitTestCase { $this->assertFalse($this->remote->hasAccess()); } + function test_hasAccessFailAcl() { + global $conf; + $conf['useacl'] = 1; + $this->assertFalse($this->remote->hasAccess()); + } + + function test_hasAccessSuccessAclEmptyRemoteUser() { + global $conf; + $conf['useacl'] = 1; + $conf['remoteuser'] = ''; + + $this->assertTrue($this->remote->hasAccess()); + } + + function test_hasAccessSuccessAcl() { + global $conf; + global $USERINFO; + $conf['useacl'] = 1; + $conf['remoteuser'] = '@grp,@grp2'; + $USERINFO['grps'] = array('grp'); + + $this->assertTrue($this->remote->hasAccess()); + } + + function test_hasAccessFailAcl2() { + global $conf; + global $USERINFO; + $conf['useacl'] = 1; + $conf['remoteuser'] = '@grp'; + $USERINFO['grps'] = array('grp1'); + + $this->assertFalse($this->remote->hasAccess()); + } + + function test_forceAccessSuccess() { global $conf; $conf['remote'] = 1; diff --git a/inc/remote.php b/inc/remote.php index e18c71092..94d428e8c 100644 --- a/inc/remote.php +++ b/inc/remote.php @@ -71,7 +71,6 @@ class RemoteAPI { * @return array with information to all available methods */ public function getMethods() { - $this->forceAccess(); return array_merge($this->getCoreMethods(), $this->getPluginMethods()); } @@ -122,10 +121,18 @@ class RemoteAPI { */ public function hasAccess() { global $conf; - if (!isset($conf['remote'])) { + global $USERINFO; + if (!$conf['remote']) { return false; } - return $conf['remote']; + if(!$conf['useacl']) { + return true; + } + if(trim($conf['remoteuser']) == '') { + return true; + } + + return auth_isMember($conf['remoteuser'], $_SERVER['REMOTE_USER'], (array) $USERINFO['grps']); } /** |