/** * Test for PMA\libraries\plugins\auth\AuthenticationConfig::authCheck (mocking the object itself) * * @return void */ public function testAuthCheckAuthFails() { $GLOBALS['server'] = 1; $_REQUEST['old_usr'] = ''; $_REQUEST['pma_username'] = ''; $_COOKIE['pmaServer-1'] = 'pmaServ1'; $_COOKIE['pmaUser-1'] = 'pmaUser1'; $_COOKIE['pma_iv-1'] = base64_encode('testiv09testiv09'); $GLOBALS['cfg']['blowfish_secret'] = 'secret'; $_SESSION['last_access_time'] = 1; $GLOBALS['cfg']['CaptchaLoginPrivateKey'] = ''; $GLOBALS['cfg']['CaptchaLoginPublicKey'] = ''; $GLOBALS['cfg']['LoginCookieValidity'] = 0; $_SESSION['last_access_time'] = -1; // mock for blowfish function $this->object = $this->getMockBuilder('PMA\\libraries\\plugins\\auth\\AuthenticationCookie')->disableOriginalConstructor()->setMethods(array('authFails'))->getMock(); $this->object->expects($this->once())->method('authFails'); $this->assertFalse($this->object->authCheck()); $this->assertTrue($GLOBALS['no_activity']); }
/** * Test for PMA\libraries\plugins\auth\AuthenticationConfig::authFails * * @return void */ public function testAuthFails() { if (!defined('PMA_TEST_HEADERS')) { $this->markTestSkipped('Cannot redefine constant/function - missing runkit extension'); } $this->object = $this->getMockBuilder('PMA\\libraries\\plugins\\auth\\AuthenticationCookie')->disableOriginalConstructor()->setMethods(array('auth'))->getMock(); $this->object->expects($this->exactly(5))->method('auth'); $GLOBALS['server'] = 2; $_COOKIE['pmaPass-2'] = 'pass'; // case 1 $GLOBALS['login_without_password_is_forbidden'] = '1'; $this->object->authFails(); $this->assertEquals($GLOBALS['conn_error'], 'Login without a password is forbidden by configuration' . ' (see AllowNoPassword)'); $this->assertEquals($GLOBALS['header'], array('Cache-Control: no-store, no-cache, must-revalidate', 'Pragma: no-cache')); // case 2 $GLOBALS['login_without_password_is_forbidden'] = ''; $GLOBALS['allowDeny_forbidden'] = '1'; $this->object->authFails(); $this->assertEquals($GLOBALS['conn_error'], 'Access denied!'); // case 3 $GLOBALS['allowDeny_forbidden'] = ''; $GLOBALS['no_activity'] = '1'; $GLOBALS['cfg']['LoginCookieValidity'] = 10; $this->object->authFails(); $this->assertEquals($GLOBALS['conn_error'], 'No activity within 10 seconds; please log in again.'); // case 4 $dbi = $this->getMockBuilder('PMA\\libraries\\DatabaseInterface')->disableOriginalConstructor()->getMock(); $dbi->expects($this->at(0))->method('getError')->will($this->returnValue(false)); $dbi->expects($this->at(1))->method('getError')->will($this->returnValue(false)); $GLOBALS['dbi'] = $dbi; $GLOBALS['no_activity'] = ''; $GLOBALS['errno'] = 42; $this->object->authFails(); $this->assertEquals($GLOBALS['conn_error'], '#42 Cannot log in to the MySQL server'); // case 5 unset($GLOBALS['errno']); $this->object->authFails(); $this->assertEquals($GLOBALS['conn_error'], 'Cannot log in to the MySQL server'); }