Merge pull request #26004 from nextcloud/enh/publicsharecontroller/isauthenticatedoverwrite
Allow overwriting isAuthenticated
This commit is contained in:
commit
8985290cd2
|
@ -109,7 +109,7 @@ abstract class PublicShareController extends Controller {
|
||||||
*
|
*
|
||||||
* @since 14.0.0
|
* @since 14.0.0
|
||||||
*/
|
*/
|
||||||
final public function isAuthenticated(): bool {
|
public function isAuthenticated(): bool {
|
||||||
// Always authenticated against non password protected shares
|
// Always authenticated against non password protected shares
|
||||||
if (!$this->isPasswordProtected()) {
|
if (!$this->isPasswordProtected()) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -27,6 +27,34 @@ use OCP\AppFramework\PublicShareController;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\ISession;
|
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 {
|
class PublicShareControllerTest extends \Test\TestCase {
|
||||||
|
|
||||||
/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
|
/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
|
||||||
|
@ -34,27 +62,18 @@ class PublicShareControllerTest extends \Test\TestCase {
|
||||||
/** @var ISession|\PHPUnit\Framework\MockObject\MockObject */
|
/** @var ISession|\PHPUnit\Framework\MockObject\MockObject */
|
||||||
private $session;
|
private $session;
|
||||||
|
|
||||||
/** @var PublicShareController|\PHPUnit\Framework\MockObject\MockObject */
|
|
||||||
private $controller;
|
|
||||||
|
|
||||||
|
|
||||||
protected function setUp(): void {
|
protected function setUp(): void {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->request = $this->createMock(IRequest::class);
|
$this->request = $this->createMock(IRequest::class);
|
||||||
$this->session = $this->createMock(ISession::class);
|
$this->session = $this->createMock(ISession::class);
|
||||||
|
|
||||||
$this->controller = $this->getMockBuilder(PublicShareController::class)
|
|
||||||
->setConstructorArgs([
|
|
||||||
'app',
|
|
||||||
$this->request,
|
|
||||||
$this->session
|
|
||||||
])->getMock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetToken() {
|
public function testGetToken() {
|
||||||
$this->controller->setToken('test');
|
$controller = new TestController('app', $this->request, $this->session, 'hash', false);
|
||||||
$this->assertEquals('test', $this->controller->getToken());
|
|
||||||
|
$controller->setToken('test');
|
||||||
|
$this->assertEquals('test', $controller->getToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataIsAuthenticated() {
|
public function dataIsAuthenticated() {
|
||||||
|
@ -74,8 +93,7 @@ class PublicShareControllerTest extends \Test\TestCase {
|
||||||
* @dataProvider dataIsAuthenticated
|
* @dataProvider dataIsAuthenticated
|
||||||
*/
|
*/
|
||||||
public function testIsAuthenticatedNotPasswordProtected(bool $protected, string $token1, string $token2, string $hash1, string $hash2, bool $expected) {
|
public function testIsAuthenticatedNotPasswordProtected(bool $protected, string $token1, string $token2, string $hash1, string $hash2, bool $expected) {
|
||||||
$this->controller->method('isPasswordProtected')
|
$controller = new TestController('app', $this->request, $this->session, $hash2, $protected);
|
||||||
->willReturn($protected);
|
|
||||||
|
|
||||||
$this->session->method('get')
|
$this->session->method('get')
|
||||||
->willReturnMap([
|
->willReturnMap([
|
||||||
|
@ -83,10 +101,8 @@ class PublicShareControllerTest extends \Test\TestCase {
|
||||||
['public_link_authenticated_password_hash', $hash1],
|
['public_link_authenticated_password_hash', $hash1],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->controller->setToken($token2);
|
$controller->setToken($token2);
|
||||||
$this->controller->method('getPasswordHash')
|
|
||||||
->willReturn($hash2);
|
|
||||||
|
|
||||||
$this->assertEquals($expected, $this->controller->isAuthenticated());
|
$this->assertEquals($expected, $controller->isAuthenticated());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue