enableBc(); $GLOBALS['server'] = 0; $this->object = new AuthenticationCookie(null); } /** * tearDown for test cases * * @return void */ public function tearDown() { unset($this->object); } /** * Test for AuthenticationConfig::auth * * @return void */ public function testAuth() { $restoreInstance = PMA_Response::getInstance(); // Case 1 $mockResponse = $this->getMockBuilder('PMA_Response') ->disableOriginalConstructor() ->setMethods(array('isAjax', 'isSuccess', 'addJSON')) ->getMock(); $mockResponse->expects($this->once()) ->method('isAjax') ->with() ->will($this->returnValue(true)); $mockResponse->expects($this->once()) ->method('isSuccess') ->with(false); $mockResponse->expects($this->once()) ->method('addJSON') ->with( 'message', PMA_Message::error( '1

[ Log in ]' ) ); $attrInstance = new ReflectionProperty('PMA_Response', '_instance'); $attrInstance->setAccessible(true); $attrInstance->setValue(null, $mockResponse); $GLOBALS['conn_error'] = true; $GLOBALS['cfg']['PmaAbsoluteUri'] = 'https://phpmyadmin.net/'; $this->assertTrue( $this->object->auth() ); // Case 2 $mockResponse = $this->getMockBuilder('PMA_Response') ->disableOriginalConstructor() ->setMethods(array('isAjax', 'isSuccess', 'addJSON')) ->getMock(); $mockResponse->expects($this->once()) ->method('isAjax') ->with() ->will($this->returnValue(true)); $mockResponse->expects($this->once()) ->method('isSuccess') ->with(false); $mockResponse->expects($this->once()) ->method('addJSON') ->with( 'message', PMA_Message::error( 'Your session has expired. Please log in again.' . '

[ Log in ]' ) ); $attrInstance = new ReflectionProperty('PMA_Response', '_instance'); $attrInstance->setAccessible(true); $attrInstance->setValue(null, $mockResponse); $GLOBALS['conn_error'] = ''; $this->assertTrue( $this->object->auth() ); // case 3 $mockResponse = $this->getMockBuilder('PMA_Response') ->disableOriginalConstructor() ->setMethods(array('isAjax', 'getFooter', 'getHeader')) ->getMock(); $mockResponse->expects($this->once()) ->method('isAjax') ->with() ->will($this->returnValue(false)); $_REQUEST['old_usr'] = ''; $GLOBALS['cfg']['LoginCookieRecall'] = true; $GLOBALS['cfg']['blowfish_secret'] = 'secret'; $GLOBALS['PHP_AUTH_USER'] = 'pmauser'; $GLOBALS['pma_auth_server'] = 'localhost'; // mock footer $mockFooter = $this->getMockBuilder('PMA_Footer') ->disableOriginalConstructor() ->setMethods(array('setMinimal')) ->getMock(); $mockFooter->expects($this->once()) ->method('setMinimal') ->with(); // mock header $mockHeader = $this->getMockBuilder('PMA_Header') ->disableOriginalConstructor() ->setMethods( array('setBodyId', 'setTitle', 'disableMenu', 'disableWarnings') ) ->getMock(); $mockHeader->expects($this->once()) ->method('setBodyId') ->with('loginform'); $mockHeader->expects($this->once()) ->method('setTitle') ->with('phpMyAdmin'); $mockHeader->expects($this->once()) ->method('disableMenu') ->with(); $mockHeader->expects($this->once()) ->method('disableWarnings') ->with(); // set mocked headers and footers $mockResponse->expects($this->once()) ->method('getFooter') ->with() ->will($this->returnValue($mockFooter)); $mockResponse->expects($this->once()) ->method('getHeader') ->with() ->will($this->returnValue($mockHeader)); $attrInstance = new ReflectionProperty('PMA_Response', '_instance'); $attrInstance->setAccessible(true); $attrInstance->setValue(null, $mockResponse); $GLOBALS['pmaThemeImage'] = 'test'; $GLOBALS['conn_error'] = true; $GLOBALS['cfg']['Lang'] = 'en'; $GLOBALS['cfg']['AllowArbitraryServer'] = true; $GLOBALS['cfg']['Servers'] = array(1, 2); $_SESSION['last_valid_captcha'] = true; $GLOBALS['target'] = 'testTarget'; $GLOBALS['db'] = 'testDb'; $GLOBALS['table'] = 'testTable'; file_put_contents('testlogo_right.png', ''); // mock error handler $mockErrorHandler = $this->getMockBuilder('PMA_Error_Handler') ->disableOriginalConstructor() ->setMethods(array('hasDisplayErrors', 'dispErrors')) ->getMock(); $mockErrorHandler->expects($this->once()) ->method('hasDisplayErrors') ->with() ->will($this->returnValue(true)); $mockErrorHandler->expects($this->once()) ->method('dispErrors') ->with(); $GLOBALS['error_handler'] = $mockErrorHandler; ob_start(); $this->object->auth(); $result = ob_get_clean(); // assertions $this->assertTag( PMA_getTagArray( 'assertTag( PMA_getTagArray( '
' ), $result ); $this->assertTag( PMA_getTagArray( '
' ), $result ); $this->assertTag( PMA_getTagArray( 'assertTag( PMA_getTagArray( '' ), $result ); $this->assertTag( PMA_getTagArray( '' ), $result ); $this->assertTag( PMA_getTagArray( '' ), $result ); $this->assertTag( PMA_getTagArray( '' ), $result ); $this->assertTag( PMA_getTagArray( '' ), $result ); @unlink('testlogo_right.png'); // case 4 $mockResponse = $this->getMockBuilder('PMA_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_Footer())); $mockResponse->expects($this->once()) ->method('getHeader') ->with() ->will($this->returnValue(new PMA_Header())); $_REQUEST['old_usr'] = ''; $GLOBALS['cfg']['LoginCookieRecall'] = false; $attrInstance = new ReflectionProperty('PMA_Response', '_instance'); $attrInstance->setAccessible(true); $attrInstance->setValue(null, $mockResponse); $GLOBALS['pmaThemeImage'] = 'test'; $GLOBALS['cfg']['Lang'] = ''; $GLOBALS['cfg']['AllowArbitraryServer'] = false; $GLOBALS['cfg']['Servers'] = array(1); $_SESSION['last_valid_captcha'] = false; $GLOBALS['cfg']['CaptchaLoginPrivateKey'] = 'testprivkey'; $GLOBALS['cfg']['CaptchaLoginPublicKey'] = 'testpubkey'; $GLOBALS['server'] = 0; $GLOBALS['error_handler'] = new PMA_Error_Handler; ob_start(); $this->object->auth(); $result = ob_get_clean(); // assertions $this->assertTag( PMA_getTagArray( 'assertTag( PMA_getTagArray( '' ), $result ); $this->assertContains( 'src="https://www.google.com/recaptcha/api/challenge?k=testpubkey">', $result ); $this->assertContains( 'iframe src="https://www.google.com/recaptcha/api/noscript' . '?k=testpubkey"', $result ); $this->assertContains( '