-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30597 from owncloud/master-d7ba3f5b7f8878189a3717…
…236a4aa515a80cd279 Fixing logout for app password scenario
- Loading branch information
Showing
3 changed files
with
42 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
|
||
use OC\User\BasicAuthModule; | ||
use OCP\IRequest; | ||
use OCP\ISession; | ||
use OCP\IUser; | ||
use OCP\IUserManager; | ||
use Test\TestCase; | ||
|
@@ -37,11 +38,14 @@ class BasicAuthModuleTest extends TestCase { | |
private $request; | ||
/** @var IUser | \PHPUnit_Framework_MockObject_MockObject */ | ||
private $user; | ||
/** @var ISession | \PHPUnit_Framework_MockObject_MockObject */ | ||
private $session; | ||
|
||
public function setUp() { | ||
parent::setUp(); | ||
$this->manager = $this->createMock(IUserManager::class); | ||
$this->request = $this->createMock(IRequest::class); | ||
$this->session = $this->createMock(ISession::class); | ||
|
||
$this->user = $this->createMock(IUser::class); | ||
$this->user->expects($this->any())->method('getUID')->willReturn('user1'); | ||
|
@@ -61,6 +65,7 @@ public function setUp() { | |
['[email protected]', [$this->user]], | ||
['user2', []] | ||
]); | ||
|
||
} | ||
|
||
/** | ||
|
@@ -69,7 +74,13 @@ public function setUp() { | |
* @param string $userId | ||
*/ | ||
public function testAuth($expectedResult, $userId) { | ||
$module = new BasicAuthModule($this->manager); | ||
|
||
$this->session | ||
->method('exists') | ||
->with('app_password') | ||
->willReturn(false); | ||
|
||
$module = new BasicAuthModule($this->manager, $this->session); | ||
$this->request->server = [ | ||
'PHP_AUTH_USER' => $userId, | ||
'PHP_AUTH_PW' => '123456', | ||
|
@@ -81,8 +92,28 @@ public function testAuth($expectedResult, $userId) { | |
$this->assertEquals($expectedResult ? $this->user : null, $module->auth($this->request)); | ||
} | ||
|
||
public function testAppPassword() { | ||
|
||
$this->session | ||
->expects($this->once()) | ||
->method('exists') | ||
->with('app_password') | ||
->willReturn(true); | ||
|
||
$this->manager | ||
->expects($this->never()) | ||
->method('checkPassword'); | ||
|
||
$module = new BasicAuthModule($this->manager, $this->session); | ||
$this->request->server = [ | ||
'PHP_AUTH_USER' => 'user', | ||
'PHP_AUTH_PW' => 'app-pass-word', | ||
]; | ||
$this->assertEquals(null, $module->auth($this->request)); | ||
} | ||
|
||
public function testGetUserPassword() { | ||
$module = new BasicAuthModule($this->manager); | ||
$module = new BasicAuthModule($this->manager, $this->session); | ||
$this->request->server = [ | ||
'PHP_AUTH_USER' => 'user1', | ||
'PHP_AUTH_PW' => '123456', | ||
|