Initial commit

This commit is contained in:
2022-11-21 09:47:28 +01:00
commit 76cec83d26
11652 changed files with 1980467 additions and 0 deletions

View File

@ -0,0 +1,150 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA\libraries\plugins\auth\AuthenticationConfig class
*
* @package PhpMyAdmin-test
*/
use PMA\libraries\plugins\auth\AuthenticationConfig;
require_once 'libraries/config.default.php';
require_once 'libraries/js_escape.lib.php';
require_once 'test/PMATestCase.php';
/**
* tests for PMA\libraries\plugins\auth\AuthenticationConfig class
*
* @package PhpMyAdmin-test
*/
class AuthenticationConfigTest extends PMATestCase
{
protected $object;
/**
* Configures global environment.
*
* @return void
*/
function setup()
{
$GLOBALS['PMA_Config'] = new PMA\libraries\Config();
$GLOBALS['PMA_Config']->enableBc();
$GLOBALS['server'] = 0;
$GLOBALS['token_provided'] = true;
$GLOBALS['token_mismatch'] = false;
$this->object = new AuthenticationConfig();
}
/**
* tearDown for test cases
*
* @return void
*/
public function tearDown()
{
unset($this->object);
}
/**
* Test for PMA\libraries\plugins\auth\AuthenticationConfig::auth
*
* @return void
*/
public function testAuth()
{
$this->assertTrue(
$this->object->auth()
);
}
/**
* Test for PMA\libraries\plugins\auth\AuthenticationConfig::authCheck
*
* @return void
*/
public function testAuthCheck()
{
$this->assertTrue(
$this->object->authCheck()
);
}
/**
* Test for PMA\libraries\plugins\auth\AuthenticationConfig::authSetUser
*
* @return void
*/
public function testAuthSetUser()
{
$this->assertTrue(
$this->object->authSetUser()
);
}
/**
* Test for PMA\libraries\plugins\auth\AuthenticationConfig::authFails
*
* @return void
*/
public function testAuthFails()
{
$removeConstant = false;
$GLOBALS['error_handler'] = new PMA\libraries\ErrorHandler;
$GLOBALS['cfg']['Servers'] = array(1);
$GLOBALS['allowDeny_forbidden'] = false;
$GLOBALS['collation_connection'] = 'utf-8';
if (!defined('PMA_USR_BROWSER_AGENT')) {
define('PMA_USR_BROWSER_AGENT', 'chrome');
$removeConstant = true;
if (! PMA_HAS_RUNKIT) {
$this->markTestSkipped('Cannot remove constant');
}
}
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$GLOBALS['dbi'] = $dbi;
ob_start();
$result = $this->object->authFails();
$html = ob_get_clean();
$this->assertTrue(
$result
);
$this->assertContains(
'You probably did not create a configuration file. You might want ' .
'to use the <a href="setup/">setup script</a> to create one.',
$html
);
$this->assertContains(
'<strong>MySQL said: </strong><a href="./url.php?url=https%3A%2F%2F' .
'dev.mysql.com%2Fdoc%2Frefman%2F5.7%2Fen%2Ferror-messages-server.html"' .
' target="mysql_doc">' .
'<img src="themes/dot.gif" title="Documentation" alt="Documentation" ' .
'class="icon ic_b_help" /></a>',
$html
);
$this->assertContains(
'Cannot connect: invalid settings.',
$html
);
$this->assertContains(
'<a href="index.php?server=0&amp;lang=en'
. '&amp;collation_connection=utf-8&amp;token=token" '
. 'class="button disableAjax">Retry to connect</a>',
$html
);
if ($removeConstant) {
runkit_constant_remove('PMA_USR_BROWSER_AGENT');
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,463 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA\libraries\plugins\auth\AuthenticationHttp class
*
* @package PhpMyAdmin-test
*/
use PMA\libraries\plugins\auth\AuthenticationHttp;
require_once 'libraries/config.default.php';
require_once 'libraries/sanitizing.lib.php';
require_once 'test/PMATestCase.php';
/**
* tests for PMA\libraries\plugins\auth\AuthenticationHttp class
*
* @package PhpMyAdmin-test
*/
class AuthenticationHttpTest extends PMATestCase
{
/**
* @var AuthenticationHttp
*/
protected $object;
/**
* Configures global environment.
*
* @return void
*/
function setup()
{
$GLOBALS['PMA_Config'] = new PMA\libraries\Config;
$GLOBALS['PMA_Config']->enableBc();
$GLOBALS['server'] = 0;
$GLOBALS['lang'] = "en";
$GLOBALS['text_dir'] = "ltr";
$GLOBALS['token_provided'] = true;
$GLOBALS['token_mismatch'] = false;
$this->object = new AuthenticationHttp();
}
/**
* tearDown for test cases
*
* @return void
*/
public function tearDown()
{
unset($this->object);
}
public function doMockResponse($set_minimal, $body_id, $set_title)
{
$restoreInstance = PMA\libraries\Response::getInstance();
// mock footer
$mockFooter = $this->getMockBuilder('PMA\libraries\Footer')
->disableOriginalConstructor()
->setMethods(array('setMinimal'))
->getMock();
$mockFooter->expects($this->exactly($set_minimal))
->method('setMinimal')
->with();
// mock header
$mockHeader = $this->getMockBuilder('PMA\libraries\Header')
->disableOriginalConstructor()
->setMethods(
array('setBodyId', 'setTitle', 'disableMenuAndConsole', 'addHTML')
)
->getMock();
$mockHeader->expects($this->exactly($body_id))
->method('setBodyId')
->with('loginform');
$mockHeader->expects($this->exactly($set_title))
->method('setTitle')
->with('Access denied!');
$mockHeader->expects($this->exactly($set_title))
->method('disableMenuAndConsole')
->with();
// set mocked headers and footers
$mockResponse = $this->getMockBuilder('PMA\libraries\Response')
->disableOriginalConstructor()
->setMethods(array('getHeader', 'getFooter', 'addHTML', 'header', 'headersSent'))
->getMock();
$mockResponse->expects($this->exactly($set_title))
->method('getFooter')
->with()
->will($this->returnValue($mockFooter));
$mockResponse->expects($this->exactly($set_title))
->method('getHeader')
->with()
->will($this->returnValue($mockHeader));
$mockResponse->expects($this->any())
->method('headersSent')
->with()
->will($this->returnValue(false));
$mockResponse->expects($this->exactly($set_title * 6))
->method('addHTML')
->with();
$attrInstance = new ReflectionProperty('PMA\libraries\Response', '_instance');
$attrInstance->setAccessible(true);
$attrInstance->setValue($mockResponse);
$headers = array_slice(func_get_args(), 3);
$header_method = $mockResponse->expects($this->exactly(count($headers)))
->method('header');
call_user_func_array(array($header_method, 'withConsecutive'), $headers);
try {
if (!empty($_REQUEST['old_usr'])) {
$this->object->logOut();
} else {
$this->assertFalse(
$this->object->auth()
);
}
} finally {
$attrInstance->setValue($restoreInstance);
}
}
/**
* Test for PMA\libraries\plugins\auth\AuthenticationHttp::auth
*
* @return void
*/
public function testAuthLogoutUrl()
{
$_REQUEST['old_usr'] = '1';
$GLOBALS['cfg']['Server']['LogoutURL'] = 'https://example.com/logout';
$this->doMockResponse(
0, 0, 0,
array('Location: https://example.com/logout')
);
}
public function testAuthVerbose()
{
$_REQUEST['old_usr'] = '';
$GLOBALS['cfg']['Server']['verbose'] = 'verboseMessagê';
$this->doMockResponse(
1, 1, 1,
array('WWW-Authenticate: Basic realm="phpMyAdmin verboseMessag"'),
array('HTTP/1.0 401 Unauthorized'),
array('status: 401 Unauthorized')
);
}
public function testAuthHost()
{
$GLOBALS['cfg']['Server']['verbose'] = '';
$GLOBALS['cfg']['Server']['host'] = 'hòst';
$this->doMockResponse(
1, 1, 1,
array('WWW-Authenticate: Basic realm="phpMyAdmin hst"'),
array('HTTP/1.0 401 Unauthorized'),
array('status: 401 Unauthorized')
);
}
public function testAuthRealm()
{
$GLOBALS['cfg']['Server']['host'] = '';
$GLOBALS['cfg']['Server']['auth_http_realm'] = 'rêäealmmessage';
$this->doMockResponse(
1, 1, 1,
array('WWW-Authenticate: Basic realm="realmmessage"'),
array('HTTP/1.0 401 Unauthorized'),
array('status: 401 Unauthorized')
);
}
/**
* Test for PMA\libraries\plugins\auth\AuthenticationHttp::authCheck
*
* @param string $user test username
* @param string $pass test password
* @param string $userIndex index to test username against
* @param string $passIndex index to test username against
* @param string $expectedReturn expected return value from test
* @param string $expectedUser expected username to be set
* @param string $expectedPass expected password to be set
* @param string $old_usr value for $_REQUEST['old_usr']
*
* @return void
* @dataProvider authCheckProvider
*/
public function testAuthCheck($user, $pass, $userIndex, $passIndex,
$expectedReturn, $expectedUser, $expectedPass, $old_usr = ''
) {
$GLOBALS['PHP_AUTH_USER'] = '';
$GLOBALS['PHP_AUTH_PW'] = '';
$_SERVER[$userIndex] = $user;
$_SERVER[$passIndex] = $pass;
$_REQUEST['old_usr'] = $old_usr;
$this->assertEquals(
$expectedReturn,
$this->object->authCheck()
);
$this->assertEquals(
$expectedUser,
$GLOBALS['PHP_AUTH_USER']
);
$this->assertEquals(
$expectedPass,
$GLOBALS['PHP_AUTH_PW']
);
$_SERVER[$userIndex] = null;
$_SERVER[$passIndex] = null;
}
/**
* Data provider for testAuthCheck
*
* @return array Test data
*/
public function authCheckProvider()
{
return array(
array(
'Basic ' . base64_encode('foo:bar'),
'pswd',
'PHP_AUTH_USER',
'PHP_AUTH_PW',
false,
'',
'bar',
'foo'
),
array(
'Basic ' . base64_encode('foobar'),
'pswd',
'REMOTE_USER',
'REMOTE_PASSWORD',
true,
'Basic Zm9vYmFy',
'pswd'
),
array(
'Basic ' . base64_encode('foobar:'),
'pswd',
'AUTH_USER',
'AUTH_PASSWORD',
true,
'foobar',
false
),
array(
'Basic ' . base64_encode(':foobar'),
'pswd',
'HTTP_AUTHORIZATION',
'AUTH_PASSWORD',
true,
'Basic OmZvb2Jhcg==',
'pswd'
),
array(
'BasicTest',
'pswd',
'Authorization',
'AUTH_PASSWORD',
true,
'BasicTest',
'pswd'
),
);
}
/**
* Test for PMA\libraries\plugins\auth\AuthenticationHttp::authSetUser
*
* @return void
*/
public function testAuthSetUser()
{
// case 1
$GLOBALS['PHP_AUTH_USER'] = 'testUser';
$GLOBALS['PHP_AUTH_PW'] = 'testPass';
$GLOBALS['server'] = 2;
$GLOBALS['cfg']['Server']['user'] = 'testUser';
$this->assertTrue(
$this->object->authSetUser()
);
$this->assertEquals(
'testUser',
$GLOBALS['cfg']['Server']['user']
);
$this->assertEquals(
'testPass',
$GLOBALS['cfg']['Server']['password']
);
$this->assertFalse(
isset($GLOBALS['PHP_AUTH_PW'])
);
$this->assertFalse(
isset($_SERVER['PHP_AUTH_PW'])
);
$this->assertEquals(
2,
$GLOBALS['server']
);
// case 2
$GLOBALS['PHP_AUTH_USER'] = 'testUser';
$GLOBALS['PHP_AUTH_PW'] = 'testPass';
$GLOBALS['cfg']['Servers'][1] = array(
'host' => 'a',
'user' => 'testUser',
'foo' => 'bar'
);
$GLOBALS['cfg']['Server']= array(
'host' => 'a',
'user' => 'user2'
);
$this->assertTrue(
$this->object->authSetUser()
);
$this->assertEquals(
array(
'user' => 'testUser',
'password' => 'testPass',
'host' => 'a',
'foo' => 'bar'
),
$GLOBALS['cfg']['Server']
);
$this->assertEquals(
1,
$GLOBALS['server']
);
// case 3
$GLOBALS['server'] = 3;
$GLOBALS['PHP_AUTH_USER'] = 'testUser';
$GLOBALS['PHP_AUTH_PW'] = 'testPass';
$GLOBALS['cfg']['Servers'][1] = array(
'host' => 'a',
'user' => 'testUsers',
'foo' => 'bar'
);
$GLOBALS['cfg']['Server']= array(
'host' => 'a',
'user' => 'user2'
);
$this->assertTrue(
$this->object->authSetUser()
);
$this->assertEquals(
array(
'user' => 'testUser',
'password' => 'testPass',
'host' => 'a'
),
$GLOBALS['cfg']['Server']
);
$this->assertEquals(
3,
$GLOBALS['server']
);
}
/**
* Test for PMA\libraries\plugins\auth\AuthenticationHttp::authSetFails
*
* @return void
*
* @group medium
*/
public function testAuthFails()
{
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->at(0))
->method('getError')
->will($this->returnValue('error 123'));
$dbi->expects($this->at(1))
->method('getError')
->will($this->returnValue('error 321'));
$dbi->expects($this->at(2))
->method('getError')
->will($this->returnValue(null));
$GLOBALS['dbi'] = $dbi;
$GLOBALS['errno'] = 31;
ob_start();
$this->object->authFails();
$result = ob_get_clean();
$this->assertContains(
'<p>error 123</p>',
$result
);
$this->object = $this->getMockBuilder('PMA\libraries\plugins\auth\AuthenticationHttp')
->disableOriginalConstructor()
->setMethods(array('authForm'))
->getMock();
$this->object->expects($this->exactly(2))
->method('authForm');
// case 2
$GLOBALS['cfg']['Server']['host'] = 'host';
$GLOBALS['errno'] = 1045;
$this->assertTrue(
$this->object->authFails()
);
// case 3
$GLOBALS['errno'] = 1043;
$this->assertTrue(
$this->object->authFails()
);
}
}

View File

@ -0,0 +1,480 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA\libraries\plugins\auth\AuthenticationSignon class
*
* @package PhpMyAdmin-test
*/
use PMA\libraries\plugins\auth\AuthenticationSignon;
require_once 'libraries/config.default.php';
require_once 'libraries/sanitizing.lib.php';
require_once 'test/PMATestCase.php';
/**
* tests for PMA\libraries\plugins\auth\AuthenticationSignon class
*
* @package PhpMyAdmin-test
*/
class AuthenticationSignonTest extends PMATestCase
{
protected $object;
/**
* Configures global environment.
*
* @return void
*/
function setup()
{
$GLOBALS['PMA_Config'] = new PMA\libraries\Config;
$GLOBALS['PMA_Config']->enableBc();
$GLOBALS['server'] = 0;
$this->object = new AuthenticationSignon();
}
/**
* tearDown for test cases
*
* @return void
*/
public function tearDown()
{
unset($this->object);
}
/**
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::auth
*
* @return void
*/
public function testAuth()
{
$GLOBALS['cfg']['Server']['SignonURL'] = '';
ob_start();
$this->object->auth();
$result = ob_get_clean();
$this->assertContains(
'You must set SignonURL!',
$result
);
}
/**
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::auth
*
* @return void
*/
public function testAuthLogoutURL()
{
$restoreInstance = PMA\libraries\Response::getInstance();
$mockResponse = $this->getMockBuilder('PMA\libraries\Response')
->disableOriginalConstructor()
->setMethods(array('isAjax', 'headersSent', 'header'))
->getMock();
$mockResponse->expects($this->any())
->method('headersSent')
->with()
->will($this->returnValue(false));
$mockResponse->expects($this->once())
->method('header')
->with('Location: https://example.com/logoutURL');
$attrInstance = new ReflectionProperty('PMA\libraries\Response', '_instance');
$attrInstance->setAccessible(true);
$attrInstance->setValue($mockResponse);
$GLOBALS['cfg']['Server']['SignonURL'] = 'https://example.com/SignonURL';
$GLOBALS['cfg']['Server']['LogoutURL'] = 'https://example.com/logoutURL';
$this->object->logOut();
$attrInstance->setValue($restoreInstance);
}
/**
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::auth
*
* @return void
*/
public function testAuthLogout()
{
$restoreInstance = PMA\libraries\Response::getInstance();
$mockResponse = $this->getMockBuilder('PMA\libraries\Response')
->disableOriginalConstructor()
->setMethods(array('isAjax', 'headersSent', 'header'))
->getMock();
$mockResponse->expects($this->any())
->method('headersSent')
->with()
->will($this->returnValue(false));
$mockResponse->expects($this->once())
->method('header')
->with('Location: https://example.com/SignonURL');
$attrInstance = new ReflectionProperty('PMA\libraries\Response', '_instance');
$attrInstance->setAccessible(true);
$attrInstance->setValue($mockResponse);
$GLOBALS['header'] = array();
$GLOBALS['cfg']['Server']['SignonURL'] = 'https://example.com/SignonURL';
$GLOBALS['cfg']['Server']['LogoutURL'] = '';
$this->object->logOut();
$attrInstance->setValue($restoreInstance);
}
/**
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::authCheck
*
* @return void
*/
public function testAuthCheckEmpty()
{
$GLOBALS['cfg']['Server']['SignonURL'] = 'https://example.com/SignonURL';
$_SESSION['LAST_SIGNON_URL'] = 'https://example.com/SignonDiffURL';
$this->assertFalse(
$this->object->authCheck()
);
}
/**
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::authCheck
*
* @return void
*/
public function testAuthCheckSession()
{
$GLOBALS['cfg']['Server']['SignonURL'] = 'https://example.com/SignonURL';
$_SESSION['LAST_SIGNON_URL'] = 'https://example.com/SignonURL';
$GLOBALS['cfg']['Server']['SignonScript'] = './examples/signon-script.php';
$GLOBALS['cfg']['Server']['SignonSession'] = 'session123';
$GLOBALS['cfg']['Server']['host'] = 'localhost';
$GLOBALS['cfg']['Server']['port'] = '80';
$GLOBALS['cfg']['Server']['user'] = 'user';
$this->assertTrue(
$this->object->authCheck()
);
$this->assertEquals(
'user',
$GLOBALS['PHP_AUTH_USER']
);
$this->assertEquals(
'password',
$GLOBALS['PHP_AUTH_PW']
);
$this->assertEquals(
'https://example.com/SignonURL',
$_SESSION['LAST_SIGNON_URL']
);
}
/**
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::authCheck
*
* @return void
*/
public function testAuthCheckToken()
{
$restoreInstance = PMA\libraries\Response::getInstance();
$mockResponse = $this->getMockBuilder('PMA\libraries\Response')
->disableOriginalConstructor()
->setMethods(array('isAjax', 'headersSent', 'header'))
->getMock();
$mockResponse->expects($this->any())
->method('headersSent')
->with()
->will($this->returnValue(false));
$mockResponse->expects($this->once())
->method('header')
->with('Location: https://example.com/SignonURL');
$attrInstance = new ReflectionProperty('PMA\libraries\Response', '_instance');
$attrInstance->setAccessible(true);
$attrInstance->setValue($mockResponse);
$GLOBALS['cfg']['Server']['SignonURL'] = 'https://example.com/SignonURL';
$GLOBALS['cfg']['Server']['SignonSession'] = 'session123';
$GLOBALS['cfg']['Server']['host'] = 'localhost';
$GLOBALS['cfg']['Server']['port'] = '80';
$GLOBALS['cfg']['Server']['user'] = 'user';
$GLOBALS['cfg']['Server']['SignonScript'] = '';
$_COOKIE['session123'] = true;
$_SESSION['PMA_single_signon_user'] = 'user123';
$_SESSION['PMA_single_signon_password'] = 'pass123';
$_SESSION['PMA_single_signon_host'] = 'local';
$_SESSION['PMA_single_signon_port'] = '12';
$_SESSION['PMA_single_signon_cfgupdate'] = array('foo' => 'bar');
$_SESSION['PMA_single_signon_token'] = 'pmaToken';
$sessionName = session_name();
$sessionID = session_id();
$this->object->logOut();
$this->assertEquals(
array(
'SignonURL' => 'https://example.com/SignonURL',
'SignonScript' => '',
'SignonSession' => 'session123',
'host' => 'localhost',
'port' => '80',
'user' => 'user',
),
$GLOBALS['cfg']['Server']
);
$this->assertEquals(
$sessionName,
session_name()
);
$this->assertEquals(
$sessionID,
session_id()
);
$this->assertFalse(
isset($_SESSION['LAST_SIGNON_URL'])
);
$attrInstance->setValue($restoreInstance);
}
/**
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::authCheck
*
* @return void
*/
public function testAuthCheckKeep()
{
$GLOBALS['cfg']['Server']['SignonURL'] = 'https://example.com/SignonURL';
$GLOBALS['cfg']['Server']['SignonSession'] = 'session123';
$GLOBALS['cfg']['Server']['host'] = 'localhost';
$GLOBALS['cfg']['Server']['port'] = '80';
$GLOBALS['cfg']['Server']['user'] = 'user';
$GLOBALS['cfg']['Server']['SignonScript'] = '';
$_COOKIE['session123'] = true;
$_REQUEST['old_usr'] = '';
$_SESSION['PMA_single_signon_user'] = 'user123';
$_SESSION['PMA_single_signon_password'] = 'pass123';
$_SESSION['PMA_single_signon_host'] = 'local';
$_SESSION['PMA_single_signon_port'] = '12';
$_SESSION['PMA_single_signon_cfgupdate'] = array('foo' => 'bar');
$_SESSION['PMA_single_signon_token'] = 'pmaToken';
$this->assertTrue(
$this->object->authCheck()
);
$this->assertEquals(
'user123',
$GLOBALS['PHP_AUTH_USER']
);
$this->assertEquals(
'pass123',
$GLOBALS['PHP_AUTH_PW']
);
}
/**
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::authSetUser
*
* @return void
*/
public function testAuthSetUser()
{
$GLOBALS['PHP_AUTH_USER'] = 'testUser123';
$GLOBALS['PHP_AUTH_PW'] = 'testPass123';
$this->assertTrue(
$this->object->authSetUser()
);
$this->assertEquals(
'testUser123',
$GLOBALS['cfg']['Server']['user']
);
$this->assertEquals(
'testPass123',
$GLOBALS['cfg']['Server']['password']
);
}
/**
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::authFails
*
* @return void
*/
public function testAuthFailsForbidden()
{
$GLOBALS['cfg']['Server']['SignonSession'] = 'newSession';
$_COOKIE['newSession'] = '42';
$this->object = $this->getMockBuilder('PMA\libraries\plugins\auth\AuthenticationSignon')
->disableOriginalConstructor()
->setMethods(array('auth'))
->getMock();
$this->object->expects($this->exactly(1))
->method('auth');
$GLOBALS['login_without_password_is_forbidden'] = true;
$this->object->authFails();
$this->assertEquals(
'Login without a password is forbidden by configuration '
. '(see AllowNoPassword)',
$_SESSION['PMA_single_signon_error_message']
);
}
/**
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::authFails
*
* @return void
*/
public function testAuthFailsDeny()
{
$GLOBALS['cfg']['Server']['SignonSession'] = 'newSession';
$_COOKIE['newSession'] = '42';
$this->object = $this->getMockBuilder('PMA\libraries\plugins\auth\AuthenticationSignon')
->disableOriginalConstructor()
->setMethods(array('auth'))
->getMock();
$this->object->expects($this->exactly(1))
->method('auth');
$GLOBALS['login_without_password_is_forbidden'] = null;
$GLOBALS['allowDeny_forbidden'] = true;
$this->object->authFails();
$this->assertEquals(
'Access denied!',
$_SESSION['PMA_single_signon_error_message']
);
}
/**
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::authFails
*
* @return void
*/
public function testAuthFailsTimeout()
{
$GLOBALS['cfg']['Server']['SignonSession'] = 'newSession';
$_COOKIE['newSession'] = '42';
$this->object = $this->getMockBuilder('PMA\libraries\plugins\auth\AuthenticationSignon')
->disableOriginalConstructor()
->setMethods(array('auth'))
->getMock();
$this->object->expects($this->exactly(1))
->method('auth');
$GLOBALS['allowDeny_forbidden'] = null;
$GLOBALS['no_activity'] = true;
$GLOBALS['cfg']['LoginCookieValidity'] = '1440';
$this->object->authFails();
$this->assertEquals(
'No activity within 1440 seconds; please log in again.',
$_SESSION['PMA_single_signon_error_message']
);
}
/**
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::authFails
*
* @return void
*/
public function testAuthFailsMySQLError()
{
$GLOBALS['cfg']['Server']['SignonSession'] = 'newSession';
$_COOKIE['newSession'] = '42';
$this->object = $this->getMockBuilder('PMA\libraries\plugins\auth\AuthenticationSignon')
->disableOriginalConstructor()
->setMethods(array('auth'))
->getMock();
$this->object->expects($this->exactly(1))
->method('auth');
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->at(0))
->method('getError')
->will($this->returnValue('error<123>'));
$GLOBALS['dbi'] = $dbi;
$GLOBALS['no_activity'] = null;
$this->object->authFails();
$this->assertEquals(
'error&lt;123&gt;',
$_SESSION['PMA_single_signon_error_message']
);
}
/**
* Test for PMA\libraries\plugins\auth\AuthenticationSignon::authFails
*
* @return void
*/
public function testAuthFailsConnect()
{
$GLOBALS['cfg']['Server']['SignonSession'] = 'newSession';
$_COOKIE['newSession'] = '42';
$this->object = $this->getMockBuilder('PMA\libraries\plugins\auth\AuthenticationSignon')
->disableOriginalConstructor()
->setMethods(array('auth'))
->getMock();
$this->object->expects($this->exactly(1))
->method('auth');
$dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->at(0))
->method('getError')
->will($this->returnValue(null));
$GLOBALS['dbi'] = $dbi;
$this->object->authFails();
$this->assertEquals(
'Cannot log in to the MySQL server',
$_SESSION['PMA_single_signon_error_message']
);
}
}