From 2ce7aa70c4896c10c46a5579106cbba647f26b76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 1 Dec 2014 09:50:16 +0100 Subject: [PATCH 1/6] Move storing password/username after checking password MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cookie encryption is quite expensive, so let's move it after we check password validity. Signed-off-by: Michal Čihař --- libraries/common.inc.php | 2 ++ libraries/plugins/AuthenticationPlugin.class.php | 9 +++++++++ libraries/plugins/auth/AuthenticationCookie.class.php | 10 ++++++++++ 3 files changed, 21 insertions(+) diff --git a/libraries/common.inc.php b/libraries/common.inc.php index 15b028e0e4..504218c05f 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -988,6 +988,8 @@ if (! defined('PMA_MINIMUM_COMMON')) { $controllink = $userlink; } + $auth_plugin->storeUserCredentials(); + /* Log success */ PMA_logUser($cfg['Server']['user']); diff --git a/libraries/plugins/AuthenticationPlugin.class.php b/libraries/plugins/AuthenticationPlugin.class.php index 8ba6679c39..457de4ca71 100644 --- a/libraries/plugins/AuthenticationPlugin.class.php +++ b/libraries/plugins/AuthenticationPlugin.class.php @@ -38,6 +38,15 @@ abstract class AuthenticationPlugin */ abstract public function authSetUser(); + /** + * Stores user credentials after successful login. + * + * @return void + */ + public function storeUserCredentials() + { + } + /** * User is not allowed to login to MySQL -> authentication failed * diff --git a/libraries/plugins/auth/AuthenticationCookie.class.php b/libraries/plugins/auth/AuthenticationCookie.class.php index dd315b42f7..9f67209da0 100644 --- a/libraries/plugins/auth/AuthenticationCookie.class.php +++ b/libraries/plugins/auth/AuthenticationCookie.class.php @@ -560,6 +560,16 @@ class AuthenticationCookie extends AuthenticationPlugin } else { $_SESSION['last_access_time'] = time(); } + } + + /** + * Stores user credentials after successful login. + * + * @return void + */ + public function storeUserCredentials() + { + global $cfg; $this->createIV(); From 94baaba666a93b65c9f56ab35d7a39c238efa627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 1 Dec 2014 10:42:11 +0100 Subject: [PATCH 2/6] Adjust testcase to new split methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- test/classes/plugin/auth/PMA_AuthenticationCookie_test.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/classes/plugin/auth/PMA_AuthenticationCookie_test.php b/test/classes/plugin/auth/PMA_AuthenticationCookie_test.php index d77bd7b389..7f59954253 100644 --- a/test/classes/plugin/auth/PMA_AuthenticationCookie_test.php +++ b/test/classes/plugin/auth/PMA_AuthenticationCookie_test.php @@ -803,6 +803,8 @@ class PMA_AuthenticationCookie_Test extends PHPUnit_Framework_TestCase isset($_SERVER['PHP_AUTH_PW']) ); + $this->object->storeUserCredentials(); + $this->assertTrue( isset($_COOKIE['pmaUser-1']) ); From baa922e9021c7e179e885505cf6020f49c05b11b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 1 Dec 2014 10:43:03 +0100 Subject: [PATCH 3/6] Define missing variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- test/classes/plugin/auth/PMA_AuthenticationHttp_test.php | 1 + 1 file changed, 1 insertion(+) diff --git a/test/classes/plugin/auth/PMA_AuthenticationHttp_test.php b/test/classes/plugin/auth/PMA_AuthenticationHttp_test.php index e898d7713f..036084c42e 100644 --- a/test/classes/plugin/auth/PMA_AuthenticationHttp_test.php +++ b/test/classes/plugin/auth/PMA_AuthenticationHttp_test.php @@ -40,6 +40,7 @@ class PMA_AuthenticationHttp_Test extends PHPUnit_Framework_TestCase $GLOBALS['PMA_Config']->enableBc(); $GLOBALS['server'] = 0; $GLOBALS['lang'] = "en"; + $GLOBALS['text_dir'] = "ltr"; $GLOBALS['available_languages'] = array( "en" => array("English", "US-ENGLISH"), "ch" => array("Chinese", "TW-Chinese") From a6764bab9b86cb6cf92661725386d7a1dcfd445f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 1 Dec 2014 11:12:54 +0100 Subject: [PATCH 4/6] Always restore mocked instance after test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- test/libraries/PMA_insert_edit_test.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/libraries/PMA_insert_edit_test.php b/test/libraries/PMA_insert_edit_test.php index 9be5bdb28d..8de6ac52c5 100644 --- a/test/libraries/PMA_insert_edit_test.php +++ b/test/libraries/PMA_insert_edit_test.php @@ -217,6 +217,7 @@ class PMA_InsertEditTest extends PHPUnit_Framework_TestCase ->setMethods(array('addHtml')) ->getMock(); + $restoreInstance = PMA_Response::getInstance(); $response = new ReflectionProperty('PMA_Response', '_instance'); $response->setAccessible(true); $response->setValue($responseMock); @@ -225,6 +226,8 @@ class PMA_InsertEditTest extends PHPUnit_Framework_TestCase array(false), 0, array('1'), 'SELECT', array('1' => 'result1') ); + $attrInstance->setValue($restoreInstance); + $this->assertFalse($result); } @@ -1926,12 +1929,15 @@ class PMA_InsertEditTest extends PHPUnit_Framework_TestCase ->method('getHeader') ->will($this->returnValue($headerMock)); + $restoreInstance = PMA_Response::getInstance(); $response = new ReflectionProperty('PMA_Response', '_instance'); $response->setAccessible(true); $response->setValue($responseMock); PMA_isInsertRow(); + $attrInstance->setValue($restoreInstance); + $this->assertEquals(5, $GLOBALS['cfg']['InsertRows']); } @@ -2765,6 +2771,7 @@ class PMA_InsertEditTest extends PHPUnit_Framework_TestCase ->setMethods(array('addHtml')) ->getMock(); + $restoreInstance = PMA_Response::getInstance(); $response = new ReflectionProperty('PMA_Response', '_instance'); $response->setAccessible(true); $response->setValue($responseMock); @@ -2792,6 +2799,8 @@ class PMA_InsertEditTest extends PHPUnit_Framework_TestCase $result = PMA_determineInsertOrEdit(null, 'db', 'table'); + $attrInstance->setValue($restoreInstance); + $this->assertEquals( array( true, From 2502375982247d21303f87ddf4e0cf1a5ef8a33c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 1 Dec 2014 11:56:03 +0100 Subject: [PATCH 5/6] Add missing call to test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- test/classes/plugin/auth/PMA_AuthenticationCookie_test.php | 1 + 1 file changed, 1 insertion(+) diff --git a/test/classes/plugin/auth/PMA_AuthenticationCookie_test.php b/test/classes/plugin/auth/PMA_AuthenticationCookie_test.php index 7f59954253..30bee3566c 100644 --- a/test/classes/plugin/auth/PMA_AuthenticationCookie_test.php +++ b/test/classes/plugin/auth/PMA_AuthenticationCookie_test.php @@ -874,6 +874,7 @@ class PMA_AuthenticationCookie_Test extends PHPUnit_Framework_TestCase $attrInstance->setValue($mockResponse); $this->object->authSetUser(); + $this->object->storeUserCredentials(); $this->assertTrue( isset($_COOKIE['pmaServer-2']) From b7e17814c1baa3d4623e130de764d218bb60c5ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 1 Dec 2014 11:59:07 +0100 Subject: [PATCH 6/6] Fix variable name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- test/libraries/PMA_insert_edit_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/libraries/PMA_insert_edit_test.php b/test/libraries/PMA_insert_edit_test.php index 8de6ac52c5..137016870c 100644 --- a/test/libraries/PMA_insert_edit_test.php +++ b/test/libraries/PMA_insert_edit_test.php @@ -226,7 +226,7 @@ class PMA_InsertEditTest extends PHPUnit_Framework_TestCase array(false), 0, array('1'), 'SELECT', array('1' => 'result1') ); - $attrInstance->setValue($restoreInstance); + $response->setValue($restoreInstance); $this->assertFalse($result); } @@ -1936,7 +1936,7 @@ class PMA_InsertEditTest extends PHPUnit_Framework_TestCase PMA_isInsertRow(); - $attrInstance->setValue($restoreInstance); + $response->setValue($restoreInstance); $this->assertEquals(5, $GLOBALS['cfg']['InsertRows']); } @@ -2799,7 +2799,7 @@ class PMA_InsertEditTest extends PHPUnit_Framework_TestCase $result = PMA_determineInsertOrEdit(null, 'db', 'table'); - $attrInstance->setValue($restoreInstance); + $response->setValue($restoreInstance); $this->assertEquals( array(