/** * Test for PMA\libraries\plugins\auth\AuthenticationConfig::auth * * @return void * @group medium */ public function testAuthCaptcha() { $restoreInstance = PMA\libraries\Response::getInstance(); $mockResponse = $this->getMockBuilder('PMA\\libraries\\Response')->disableOriginalConstructor()->setMethods(array('isAjax', 'getFooter', 'getHeader'))->getMock(); $mockResponse->expects($this->once())->method('isAjax')->with()->will($this->returnValue(false)); $mockResponse->expects($this->once())->method('getFooter')->with()->will($this->returnValue(new PMA\libraries\Footer())); $mockResponse->expects($this->once())->method('getHeader')->with()->will($this->returnValue(new PMA\libraries\Header())); $_REQUEST['old_usr'] = ''; $GLOBALS['cfg']['LoginCookieRecall'] = false; $attrInstance = new ReflectionProperty('PMA\\libraries\\Response', '_instance'); $attrInstance->setAccessible(true); $attrInstance->setValue($mockResponse); $GLOBALS['pmaThemeImage'] = 'test'; $GLOBALS['cfg']['Lang'] = ''; $GLOBALS['cfg']['AllowArbitraryServer'] = false; $GLOBALS['cfg']['Servers'] = array(1); $GLOBALS['cfg']['CaptchaLoginPrivateKey'] = 'testprivkey'; $GLOBALS['cfg']['CaptchaLoginPublicKey'] = 'testpubkey'; $GLOBALS['server'] = 0; $GLOBALS['error_handler'] = new PMA\libraries\ErrorHandler(); ob_start(); $this->object->auth(); $result = ob_get_clean(); // assertions $this->assertContains('<img name="imLogo" id="imLogo" src="testpma_logo.png"', $result); $this->assertContains('<select name="lang" class="autosubmit" lang="en" dir="ltr" ' . 'id="sel-lang">', $result); $this->assertContains('<form method="post" action="index.php" name="login_form" ' . 'autocomplete="off" class="disableAjax login hide js-show">', $result); $this->assertContains('<input type="hidden" name="server" value="0" />', $result); $this->assertContains('<script src="https://www.google.com/recaptcha/api.js?hl=en"' . ' async defer></script>', $result); $this->assertContains('<div class="g-recaptcha" data-sitekey="testpubkey">', $result); $attrInstance->setValue($restoreInstance); }
/** * Test for PMA\libraries\plugins\auth\AuthenticationConfig::auth with headers * * @return void */ public function testAuthHeader() { if (!defined('PMA_TEST_HEADERS')) { $this->markTestSkipped('Cannot redefine constant/function - missing runkit extension'); } $restoreInstance = PMA\libraries\Response::getInstance(); $mockResponse = $this->getMockBuilder('PMA\\libraries\\Response')->disableOriginalConstructor()->setMethods(array('isAjax'))->getMock(); $mockResponse->expects($this->once())->method('isAjax')->with()->will($this->returnValue(false)); $attrInstance = new ReflectionProperty('PMA\\libraries\\Response', '_instance'); $attrInstance->setAccessible(true); $attrInstance->setValue($mockResponse); $_REQUEST['old_usr'] = '******'; $GLOBALS['cfg']['Server']['LogoutURL'] = 'http://www.phpmyadmin.net/logout'; $this->assertTrue($this->object->auth()); $this->assertContains('Location: http://www.phpmyadmin.net/logout?PHPSESSID=', $GLOBALS['header'][0]); $attrInstance->setValue($restoreInstance); }