diff options
author | diosmosis <diosmosis@users.noreply.github.com> | 2018-09-24 01:08:33 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-24 01:08:33 +0300 |
commit | faca30f23fd98143314ca89293915aca9a0325a5 (patch) | |
tree | faac2f0c21a7ee88479e2566dfc74de1569e6509 /tests/PHPUnit/Unit | |
parent | af9f44ced0a8d2e703584eaaffc210f2a1a30187 (diff) |
Remove user-agent checking code in SessionAuth. (#13470)3.6.1-b2
* Remove user-agent checking code in SessionAuth.
* Fixing test.
* Fixing couple more tests.
Diffstat (limited to 'tests/PHPUnit/Unit')
-rw-r--r-- | tests/PHPUnit/Unit/Session/SessionFingerprintTest.php | 56 | ||||
-rw-r--r-- | tests/PHPUnit/Unit/Session/SessionInitializerTest.php | 6 |
2 files changed, 4 insertions, 58 deletions
diff --git a/tests/PHPUnit/Unit/Session/SessionFingerprintTest.php b/tests/PHPUnit/Unit/Session/SessionFingerprintTest.php index 047fdd80df..e9bbdd9f38 100644 --- a/tests/PHPUnit/Unit/Session/SessionFingerprintTest.php +++ b/tests/PHPUnit/Unit/Session/SessionFingerprintTest.php @@ -43,7 +43,6 @@ class SessionFingerprintTest extends \PHPUnit_Framework_TestCase { $sessionVarValue = [ 'ip' => 'someip', - 'ua' => 'someua', ]; $_SESSION[SessionFingerprint::SESSION_INFO_SESSION_VAR_NAME] = $sessionVarValue; @@ -57,68 +56,15 @@ class SessionFingerprintTest extends \PHPUnit_Framework_TestCase public function test_initialize_SetsSessionVarsToCurrentRequest() { - $_SERVER['HTTP_USER_AGENT'] = 'test-user-agent'; $this->testInstance->initialize('testuser', self::TEST_TIME_VALUE); $this->assertEquals('testuser', $_SESSION[SessionFingerprint::USER_NAME_SESSION_VAR_NAME]); $this->assertEquals( - ['ts' => self::TEST_TIME_VALUE, 'ua' => 'test-user-agent'], + ['ts' => self::TEST_TIME_VALUE], $_SESSION[SessionFingerprint::SESSION_INFO_SESSION_VAR_NAME] ); } - public function test_initialize_DoesNotSetUserAgent_IfUserAgentIsNotInHttpRequest() - { - unset($_SERVER['HTTP_USER_AGENT']); - $this->testInstance->initialize('testuser', self::TEST_TIME_VALUE); - - $this->assertEquals('testuser', $_SESSION[SessionFingerprint::USER_NAME_SESSION_VAR_NAME]); - $this->assertEquals( - ['ts' => self::TEST_TIME_VALUE, 'ua' => null], - $_SESSION[SessionFingerprint::SESSION_INFO_SESSION_VAR_NAME] - ); - } - - /** - * @dataProvider getTestDataForIsMatchingCurrentRequest - */ - public function test_isMatchingCurrentRequest_ChecksIfSessionVarsMatchRequest( - $sessionUa, $requestUa, $expectedResult - ) { - $_SESSION[SessionFingerprint::SESSION_INFO_SESSION_VAR_NAME] = [ - 'ua' => $sessionUa, - ]; - - $_SERVER['HTTP_USER_AGENT'] = $requestUa; - - $this->assertEquals($expectedResult, $this->testInstance->isMatchingCurrentRequest()); - } - - public function getTestDataForIsMatchingCurrentRequest() - { - return [ - ['test ua', 'test ua', true], - ['nontest ua', 'test ua', false], - [null, 'test ua', false], - ]; - } - - public function test_isMatchingCurrentRequest_ReturnsFalse_IfUserInfoSessionVarDoesNotExist() - { - $_SERVER['HTTP_USER_AGENT'] = 'test-ua'; - - $this->assertEquals(false, $this->testInstance->isMatchingCurrentRequest()); - } - - public function test_isMatchingCurrentRequest_ReturnsFalse_IfRequestDetailsDoNotExist() - { - $_SESSION[SessionFingerprint::SESSION_INFO_SESSION_VAR_NAME] = [ - 'ua' => 'test-ua', - ]; - - $this->assertEquals(false, $this->testInstance->isMatchingCurrentRequest()); - } - public function test_getSessionStartTime_() { $_SESSION[SessionFingerprint::SESSION_INFO_SESSION_VAR_NAME] = [ diff --git a/tests/PHPUnit/Unit/Session/SessionInitializerTest.php b/tests/PHPUnit/Unit/Session/SessionInitializerTest.php index 7b3c2a206a..1275cb340a 100644 --- a/tests/PHPUnit/Unit/Session/SessionInitializerTest.php +++ b/tests/PHPUnit/Unit/Session/SessionInitializerTest.php @@ -40,7 +40,7 @@ class SessionInitializerTest extends \PHPUnit_Framework_TestCase public function test_initSession_Throws_IfAuthenticationFailed($rememberMe) { $sessionInitializer = new TestSessionInitializer(); - $sessionInitializer->initSession($this->makeMockAuth(AuthResult::SUCCESS), $rememberMe); + $sessionInitializer->initSession($this->makeMockAuth(AuthResult::SUCCESS)); } /** @@ -49,7 +49,7 @@ class SessionInitializerTest extends \PHPUnit_Framework_TestCase public function test_initSession_InitializesTheSessionCorrectly_IfAuthenticationSucceeds($rememberMe) { $sessionInitializer = new TestSessionInitializer(); - $sessionInitializer->initSession($this->makeMockAuth(AuthResult::SUCCESS), $rememberMe); + $sessionInitializer->initSession($this->makeMockAuth(AuthResult::SUCCESS)); $this->assertSessionCreatedCorrectly(); } @@ -72,7 +72,7 @@ class SessionInitializerTest extends \PHPUnit_Framework_TestCase $fingerprint = new SessionFingerprint(); $this->assertEquals('testlogin', $fingerprint->getUser()); $this->assertNotEmpty($fingerprint->getSessionStartTime()); - $this->assertEquals(['ts', 'ua'], array_keys($fingerprint->getUserInfo())); + $this->assertEquals(['ts'], array_keys($fingerprint->getUserInfo())); } } |