1*98640fd3SAndreas Gohr<?php 2*98640fd3SAndreas Gohr 3*98640fd3SAndreas Gohrnamespace dokuwiki\test\Action; 4*98640fd3SAndreas Gohr 5*98640fd3SAndreas Gohruse dokuwiki\Action\AbstractAclAction; 6*98640fd3SAndreas Gohruse dokuwiki\Action\AbstractUserAction; 7*98640fd3SAndreas Gohruse dokuwiki\Action\Exception\ActionAclRequiredException; 8*98640fd3SAndreas Gohruse dokuwiki\Action\Exception\ActionDisabledException; 9*98640fd3SAndreas Gohruse dokuwiki\Action\Exception\ActionUserRequiredException; 10*98640fd3SAndreas Gohr 11*98640fd3SAndreas Gohrclass ActionTest extends \DokuWikiTest 12*98640fd3SAndreas Gohr{ 13*98640fd3SAndreas Gohr 14*98640fd3SAndreas Gohr public function dataProvider() 15*98640fd3SAndreas Gohr { 16*98640fd3SAndreas Gohr return array( 17*98640fd3SAndreas Gohr array('Login', AUTH_NONE, array('exists' => true, 'ismanager' => false)), 18*98640fd3SAndreas Gohr array('Logout', AUTH_NONE, array('exists' => true, 'ismanager' => false)), 19*98640fd3SAndreas Gohr array('Search', AUTH_NONE, array('exists' => true, 'ismanager' => false)), 20*98640fd3SAndreas Gohr array('Recent', AUTH_NONE, array('exists' => true, 'ismanager' => false)), 21*98640fd3SAndreas Gohr array('Profile', AUTH_NONE, array('exists' => true, 'ismanager' => false)), 22*98640fd3SAndreas Gohr array('ProfileDelete', AUTH_NONE, array('exists' => true, 'ismanager' => false)), 23*98640fd3SAndreas Gohr array('Index', AUTH_NONE, array('exists' => true, 'ismanager' => false)), 24*98640fd3SAndreas Gohr array('Sitemap', AUTH_NONE, array('exists' => true, 'ismanager' => false)), 25*98640fd3SAndreas Gohr array('Denied', AUTH_NONE, array('exists' => true, 'ismanager' => false)), 26*98640fd3SAndreas Gohr array('Register', AUTH_NONE, array('exists' => true, 'ismanager' => false)), 27*98640fd3SAndreas Gohr array('Resendpwd', AUTH_NONE, array('exists' => true, 'ismanager' => false)), 28*98640fd3SAndreas Gohr array('Backlink', AUTH_NONE, array('exists' => true, 'ismanager' => false)), 29*98640fd3SAndreas Gohr 30*98640fd3SAndreas Gohr array('Revert', AUTH_EDIT, array('exists' => true, 'ismanager' => false)), 31*98640fd3SAndreas Gohr array('Revert', AUTH_EDIT, array('exists' => true, 'ismanager' => true)), 32*98640fd3SAndreas Gohr 33*98640fd3SAndreas Gohr array('Admin', AUTH_READ, array('exists' => true, 'ismanager' => false)), // let in, check later again 34*98640fd3SAndreas Gohr array('Admin', AUTH_READ, array('exists' => true, 'ismanager' => true)), // let in, check later again 35*98640fd3SAndreas Gohr 36*98640fd3SAndreas Gohr array('Check', AUTH_READ, array('exists' => true, 'ismanager' => false)), // sensible? 37*98640fd3SAndreas Gohr array('Diff', AUTH_READ, array('exists' => true, 'ismanager' => false)), 38*98640fd3SAndreas Gohr array('Show', AUTH_READ, array('exists' => true, 'ismanager' => false)), 39*98640fd3SAndreas Gohr array('Subscribe', AUTH_READ, array('exists' => true, 'ismanager' => false)), 40*98640fd3SAndreas Gohr array('Locked', AUTH_READ, array('exists' => true, 'ismanager' => false)), 41*98640fd3SAndreas Gohr array('Source', AUTH_READ, array('exists' => true, 'ismanager' => false)), 42*98640fd3SAndreas Gohr array('Export', AUTH_READ, array('exists' => true, 'ismanager' => false)), 43*98640fd3SAndreas Gohr array('Media', AUTH_READ, array('exists' => true, 'ismanager' => false)), 44*98640fd3SAndreas Gohr array('Revisions', AUTH_READ, array('exists' => true, 'ismanager' => false)), 45*98640fd3SAndreas Gohr 46*98640fd3SAndreas Gohr array('Draftdel', AUTH_EDIT, array('exists' => true, 'ismanager' => false)), 47*98640fd3SAndreas Gohr 48*98640fd3SAndreas Gohr // aliases 49*98640fd3SAndreas Gohr array('Cancel', AUTH_NONE, array('exists' => true, 'ismanager' => false)), 50*98640fd3SAndreas Gohr array('Recover', AUTH_NONE, array('exists' => true, 'ismanager' => false)), 51*98640fd3SAndreas Gohr 52*98640fd3SAndreas Gohr // EDITING existing page 53*98640fd3SAndreas Gohr array('Save', AUTH_EDIT, array('exists' => true, 'ismanager' => false)), 54*98640fd3SAndreas Gohr array('Conflict', AUTH_EDIT, array('exists' => true, 'ismanager' => false)), 55*98640fd3SAndreas Gohr array('Draft', AUTH_EDIT, array('exists' => true, 'ismanager' => false)), 56*98640fd3SAndreas Gohr //the edit function will check again and do a source show 57*98640fd3SAndreas Gohr //when no AUTH_EDIT available: 58*98640fd3SAndreas Gohr array('Edit', AUTH_READ, array('exists' => true, 'ismanager' => false)), 59*98640fd3SAndreas Gohr array('Preview', AUTH_READ, array('exists' => true, 'ismanager' => false)), 60*98640fd3SAndreas Gohr 61*98640fd3SAndreas Gohr // EDITING new page 62*98640fd3SAndreas Gohr array('Save', AUTH_CREATE, array('exists' => false, 'ismanager' => false)), 63*98640fd3SAndreas Gohr array('Conflict', AUTH_CREATE, array('exists' => false, 'ismanager' => false)), 64*98640fd3SAndreas Gohr array('Draft', AUTH_CREATE, array('exists' => false, 'ismanager' => false)), 65*98640fd3SAndreas Gohr array('Edit', AUTH_CREATE, array('exists' => false, 'ismanager' => false)), 66*98640fd3SAndreas Gohr array('Preview', AUTH_CREATE, array('exists' => false, 'ismanager' => false)), 67*98640fd3SAndreas Gohr ); 68*98640fd3SAndreas Gohr } 69*98640fd3SAndreas Gohr 70*98640fd3SAndreas Gohr /** 71*98640fd3SAndreas Gohr * @dataProvider dataProvider 72*98640fd3SAndreas Gohr * @param $name 73*98640fd3SAndreas Gohr * @param $expected 74*98640fd3SAndreas Gohr * @param $info 75*98640fd3SAndreas Gohr */ 76*98640fd3SAndreas Gohr public function testMinimumPermissions($name, $expected, $info) 77*98640fd3SAndreas Gohr { 78*98640fd3SAndreas Gohr global $INFO; 79*98640fd3SAndreas Gohr $INFO = $info; 80*98640fd3SAndreas Gohr 81*98640fd3SAndreas Gohr $classname = 'dokuwiki\\Action\\' . $name; 82*98640fd3SAndreas Gohr /** @var \dokuwiki\Action\AbstractAction $class */ 83*98640fd3SAndreas Gohr $class = new $classname(); 84*98640fd3SAndreas Gohr 85*98640fd3SAndreas Gohr $this->assertSame($expected, $class->minimumPermission()); 86*98640fd3SAndreas Gohr } 87*98640fd3SAndreas Gohr 88*98640fd3SAndreas Gohr /** 89*98640fd3SAndreas Gohr * All actions should handle the disableactions setting 90*98640fd3SAndreas Gohr * 91*98640fd3SAndreas Gohr * @dataProvider dataProvider 92*98640fd3SAndreas Gohr * @param $name 93*98640fd3SAndreas Gohr */ 94*98640fd3SAndreas Gohr public function testBaseClassActionOkPermission($name) 95*98640fd3SAndreas Gohr { 96*98640fd3SAndreas Gohr $this->assertTrue(true); // mark as not risky 97*98640fd3SAndreas Gohr if ($name == 'Show') return; // disabling show does not work 98*98640fd3SAndreas Gohr 99*98640fd3SAndreas Gohr $classname = 'dokuwiki\\Action\\' . $name; 100*98640fd3SAndreas Gohr /** @var \dokuwiki\Action\AbstractAction $class */ 101*98640fd3SAndreas Gohr $class = new $classname(); 102*98640fd3SAndreas Gohr 103*98640fd3SAndreas Gohr global $conf; 104*98640fd3SAndreas Gohr $conf['useacl'] = 1; 105*98640fd3SAndreas Gohr $conf['subscribers'] = 1; 106*98640fd3SAndreas Gohr $conf['disableactions'] = ''; 107*98640fd3SAndreas Gohr $_SERVER['REMOTE_USER'] = 'someone'; 108*98640fd3SAndreas Gohr 109*98640fd3SAndreas Gohr try { 110*98640fd3SAndreas Gohr \dokuwiki\ActionRouter::getInstance(true)->checkAction($class); 111*98640fd3SAndreas Gohr } catch (\Exception $e) { 112*98640fd3SAndreas Gohr $this->assertNotSame(ActionDisabledException::class, get_class($e)); 113*98640fd3SAndreas Gohr } 114*98640fd3SAndreas Gohr 115*98640fd3SAndreas Gohr $conf['disableactions'] = $class->getActionName(); 116*98640fd3SAndreas Gohr 117*98640fd3SAndreas Gohr try { 118*98640fd3SAndreas Gohr \dokuwiki\ActionRouter::getInstance(true)->checkAction($class); 119*98640fd3SAndreas Gohr } catch (\Exception $e) { 120*98640fd3SAndreas Gohr $this->assertSame(ActionDisabledException::class, get_class($e), $e); 121*98640fd3SAndreas Gohr } 122*98640fd3SAndreas Gohr } 123*98640fd3SAndreas Gohr 124*98640fd3SAndreas Gohr /** 125*98640fd3SAndreas Gohr * Actions inheriting from AbstractAclAction should have an ACL enabled check 126*98640fd3SAndreas Gohr * 127*98640fd3SAndreas Gohr * @dataProvider dataProvider 128*98640fd3SAndreas Gohr * @param $name 129*98640fd3SAndreas Gohr */ 130*98640fd3SAndreas Gohr public function testBaseClassAclPermission($name) 131*98640fd3SAndreas Gohr { 132*98640fd3SAndreas Gohr $classname = 'dokuwiki\\Action\\' . $name; 133*98640fd3SAndreas Gohr /** @var \dokuwiki\Action\AbstractAction $class */ 134*98640fd3SAndreas Gohr $class = new $classname(); 135*98640fd3SAndreas Gohr $this->assertTrue(true); // mark as not risky 136*98640fd3SAndreas Gohr if (!is_a($class, AbstractAclAction::class)) return; 137*98640fd3SAndreas Gohr 138*98640fd3SAndreas Gohr global $conf; 139*98640fd3SAndreas Gohr $conf['useacl'] = 1; 140*98640fd3SAndreas Gohr $conf['subscribers'] = 1; 141*98640fd3SAndreas Gohr 142*98640fd3SAndreas Gohr try { 143*98640fd3SAndreas Gohr $class->checkPreconditions(); 144*98640fd3SAndreas Gohr } catch (\Exception $e) { 145*98640fd3SAndreas Gohr $this->assertNotSame(ActionAclRequiredException::class, get_class($e)); 146*98640fd3SAndreas Gohr } 147*98640fd3SAndreas Gohr 148*98640fd3SAndreas Gohr $conf['useacl'] = 0; 149*98640fd3SAndreas Gohr 150*98640fd3SAndreas Gohr try { 151*98640fd3SAndreas Gohr $class->checkPreconditions(); 152*98640fd3SAndreas Gohr } catch (\Exception $e) { 153*98640fd3SAndreas Gohr $this->assertSame(ActionAclRequiredException::class, get_class($e)); 154*98640fd3SAndreas Gohr } 155*98640fd3SAndreas Gohr } 156*98640fd3SAndreas Gohr 157*98640fd3SAndreas Gohr /** 158*98640fd3SAndreas Gohr * Actions inheriting from AbstractUserAction should have user check 159*98640fd3SAndreas Gohr * 160*98640fd3SAndreas Gohr * @dataProvider dataProvider 161*98640fd3SAndreas Gohr * @param $name 162*98640fd3SAndreas Gohr */ 163*98640fd3SAndreas Gohr public function testBaseClassUserPermission($name) 164*98640fd3SAndreas Gohr { 165*98640fd3SAndreas Gohr $classname = 'dokuwiki\\Action\\' . $name; 166*98640fd3SAndreas Gohr /** @var \dokuwiki\Action\AbstractAction $class */ 167*98640fd3SAndreas Gohr $class = new $classname(); 168*98640fd3SAndreas Gohr $this->assertTrue(true); // mark as not risky 169*98640fd3SAndreas Gohr if (!is_a($class, AbstractUserAction::class)) return; 170*98640fd3SAndreas Gohr 171*98640fd3SAndreas Gohr global $conf; 172*98640fd3SAndreas Gohr $conf['useacl'] = 1; 173*98640fd3SAndreas Gohr $conf['subscribers'] = 1; 174*98640fd3SAndreas Gohr $_SERVER['REMOTE_USER'] = 'test'; 175*98640fd3SAndreas Gohr 176*98640fd3SAndreas Gohr try { 177*98640fd3SAndreas Gohr $class->checkPreconditions(); 178*98640fd3SAndreas Gohr } catch (\Exception $e) { 179*98640fd3SAndreas Gohr $this->assertNotSame(ActionUserRequiredException::class, get_class($e)); 180*98640fd3SAndreas Gohr } 181*98640fd3SAndreas Gohr 182*98640fd3SAndreas Gohr unset($_SERVER['REMOTE_USER']); 183*98640fd3SAndreas Gohr 184*98640fd3SAndreas Gohr try { 185*98640fd3SAndreas Gohr $class->checkPreconditions(); 186*98640fd3SAndreas Gohr } catch (\Exception $e) { 187*98640fd3SAndreas Gohr $this->assertSame(ActionUserRequiredException::class, get_class($e)); 188*98640fd3SAndreas Gohr } 189*98640fd3SAndreas Gohr } 190*98640fd3SAndreas Gohr} 191