diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2021-03-08 15:05:28 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2021-03-09 09:17:30 +0100 |
commit | 30e096f3f5d8be5644b50cd45adca1fbe429a8aa (patch) | |
tree | 6687e8321456ef51c26ff0c3e60a50b6c2578192 /tests | |
parent | 7198bed22d07493f7d5b98e0a0525e8c22b8361f (diff) | |
download | nextcloud-server-30e096f3f5d8be5644b50cd45adca1fbe429a8aa.tar.gz nextcloud-server-30e096f3f5d8be5644b50cd45adca1fbe429a8aa.zip |
Allow overwriting isAuthenticated
* Some implementations might check for different things
* IT will not change how the current ones work
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/AppFramework/Controller/PublicShareControllerTest.php | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/tests/lib/AppFramework/Controller/PublicShareControllerTest.php b/tests/lib/AppFramework/Controller/PublicShareControllerTest.php index f2a60a574af..deffedcec05 100644 --- a/tests/lib/AppFramework/Controller/PublicShareControllerTest.php +++ b/tests/lib/AppFramework/Controller/PublicShareControllerTest.php @@ -27,6 +27,34 @@ use OCP\AppFramework\PublicShareController; use OCP\IRequest; use OCP\ISession; +class TestController extends PublicShareController { + + /** @var string */ + private $hash; + + /** @var bool */ + private $isProtected; + + public function __construct(string $appName, IRequest $request, ISession $session, string $hash, bool $isProtected) { + parent::__construct($appName, $request, $session); + + $this->hash = $hash; + $this->isProtected = $isProtected; + } + + protected function getPasswordHash(): string { + return $this->hash; + } + + public function isValidToken(): bool { + return false; + } + + protected function isPasswordProtected(): bool { + return $this->isProtected; + } +} + class PublicShareControllerTest extends \Test\TestCase { /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */ @@ -34,27 +62,18 @@ class PublicShareControllerTest extends \Test\TestCase { /** @var ISession|\PHPUnit\Framework\MockObject\MockObject */ private $session; - /** @var PublicShareController|\PHPUnit\Framework\MockObject\MockObject */ - private $controller; - - protected function setUp(): void { parent::setUp(); $this->request = $this->createMock(IRequest::class); $this->session = $this->createMock(ISession::class); - - $this->controller = $this->getMockBuilder(PublicShareController::class) - ->setConstructorArgs([ - 'app', - $this->request, - $this->session - ])->getMock(); } public function testGetToken() { - $this->controller->setToken('test'); - $this->assertEquals('test', $this->controller->getToken()); + $controller = new TestController('app', $this->request, $this->session, 'hash', false); + + $controller->setToken('test'); + $this->assertEquals('test', $controller->getToken()); } public function dataIsAuthenticated() { @@ -74,8 +93,7 @@ class PublicShareControllerTest extends \Test\TestCase { * @dataProvider dataIsAuthenticated */ public function testIsAuthenticatedNotPasswordProtected(bool $protected, string $token1, string $token2, string $hash1, string $hash2, bool $expected) { - $this->controller->method('isPasswordProtected') - ->willReturn($protected); + $controller = new TestController('app', $this->request, $this->session, $hash2, $protected); $this->session->method('get') ->willReturnMap([ @@ -83,10 +101,8 @@ class PublicShareControllerTest extends \Test\TestCase { ['public_link_authenticated_password_hash', $hash1], ]); - $this->controller->setToken($token2); - $this->controller->method('getPasswordHash') - ->willReturn($hash2); + $controller->setToken($token2); - $this->assertEquals($expected, $this->controller->isAuthenticated()); + $this->assertEquals($expected, $controller->isAuthenticated()); } } |