|
|
|
|
@ -1,4 +1,6 @@ |
|
|
|
|
<?php |
|
|
|
|
|
|
|
|
|
declare(strict_types=1); |
|
|
|
|
/** |
|
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
|
|
|
* |
|
|
|
|
@ -28,7 +30,9 @@ namespace OCA\DAV\Tests\unit\Connector\Sabre; |
|
|
|
|
|
|
|
|
|
use OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin; |
|
|
|
|
use OCP\IConfig; |
|
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
|
|
|
use Test\TestCase; |
|
|
|
|
use Sabre\HTTP\RequestInterface; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Class BlockLegacyClientPluginTest |
|
|
|
|
@ -36,7 +40,7 @@ use Test\TestCase; |
|
|
|
|
* @package OCA\DAV\Tests\unit\Connector\Sabre |
|
|
|
|
*/ |
|
|
|
|
class BlockLegacyClientPluginTest extends TestCase { |
|
|
|
|
/** @var IConfig | \PHPUnit\Framework\MockObject\MockObject */ |
|
|
|
|
/** @var IConfig|MockObject */ |
|
|
|
|
private $config; |
|
|
|
|
/** @var BlockLegacyClientPlugin */ |
|
|
|
|
private $blockLegacyClientVersionPlugin; |
|
|
|
|
@ -44,34 +48,25 @@ class BlockLegacyClientPluginTest extends TestCase { |
|
|
|
|
protected function setUp(): void { |
|
|
|
|
parent::setUp(); |
|
|
|
|
|
|
|
|
|
$this->config = $this->getMockBuilder(IConfig::class) |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$this->config = $this->createMock(IConfig::class); |
|
|
|
|
$this->blockLegacyClientVersionPlugin = new BlockLegacyClientPlugin($this->config); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public function oldDesktopClientProvider() { |
|
|
|
|
public function oldDesktopClientProvider(): array { |
|
|
|
|
return [ |
|
|
|
|
['Mozilla/5.0 (1.5.0) mirall/1.5.0'], |
|
|
|
|
['mirall/1.5.0'], |
|
|
|
|
['mirall/1.5.4'], |
|
|
|
|
['mirall/1.6.0'], |
|
|
|
|
['Mozilla/5.0 (Windows) mirall/1.5.0'], |
|
|
|
|
['Mozilla/5.0 (Bogus Text) mirall/1.6.9'], |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @dataProvider oldDesktopClientProvider |
|
|
|
|
* @param string $userAgent |
|
|
|
|
*/ |
|
|
|
|
public function testBeforeHandlerException($userAgent): void { |
|
|
|
|
public function testBeforeHandlerException(string $userAgent): void { |
|
|
|
|
$this->expectException(\Sabre\DAV\Exception\Forbidden::class); |
|
|
|
|
$this->expectExceptionMessage('Unsupported client version.'); |
|
|
|
|
|
|
|
|
|
/** @var \Sabre\HTTP\RequestInterface | \PHPUnit\Framework\MockObject\MockObject $request */ |
|
|
|
|
/** @var RequestInterface|MockObject $request */ |
|
|
|
|
$request = $this->createMock('\Sabre\HTTP\RequestInterface'); |
|
|
|
|
$request |
|
|
|
|
->expects($this->once()) |
|
|
|
|
@ -88,26 +83,20 @@ class BlockLegacyClientPluginTest extends TestCase { |
|
|
|
|
$this->blockLegacyClientVersionPlugin->beforeHandler($request); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public function newAndAlternateDesktopClientProvider() { |
|
|
|
|
public function newAndAlternateDesktopClientProvider(): array { |
|
|
|
|
return [ |
|
|
|
|
['Mozilla/5.0 (1.7.0) mirall/1.7.0'], |
|
|
|
|
['mirall/1.8.3'], |
|
|
|
|
['mirall/1.7.2'], |
|
|
|
|
['mirall/1.7.0'], |
|
|
|
|
['Mozilla/5.0 (Windows) mirall/1.7.0'], |
|
|
|
|
['Mozilla/5.0 (Bogus Text) mirall/1.9.3'], |
|
|
|
|
['Mozilla/5.0 (Not Our Client But Old Version) LegacySync/1.1.0'], |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @dataProvider newAndAlternateDesktopClientProvider |
|
|
|
|
* @param string $userAgent |
|
|
|
|
*/ |
|
|
|
|
public function testBeforeHandlerSuccess($userAgent): void { |
|
|
|
|
/** @var \Sabre\HTTP\RequestInterface | \PHPUnit\Framework\MockObject\MockObject $request */ |
|
|
|
|
$request = $this->createMock('\Sabre\HTTP\RequestInterface'); |
|
|
|
|
public function testBeforeHandlerSuccess(string $userAgent): void { |
|
|
|
|
/** @var RequestInterface|MockObject $request */ |
|
|
|
|
$request = $this->createMock(RequestInterface::class); |
|
|
|
|
$request |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('getHeader') |
|
|
|
|
@ -124,8 +113,8 @@ class BlockLegacyClientPluginTest extends TestCase { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testBeforeHandlerNoUserAgent(): void { |
|
|
|
|
/** @var \Sabre\HTTP\RequestInterface | \PHPUnit\Framework\MockObject\MockObject $request */ |
|
|
|
|
$request = $this->createMock('\Sabre\HTTP\RequestInterface'); |
|
|
|
|
/** @var RequestInterface|MockObject $request */ |
|
|
|
|
$request = $this->createMock(RequestInterface::class); |
|
|
|
|
$request |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('getHeader') |
|
|
|
|
|