2015-04-16 23:39:44 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2015-04-16 23:39:44 +03:00
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
2015-04-20 13:53:40 +03:00
|
|
|
|
2016-05-25 17:04:15 +03:00
|
|
|
namespace OCA\DAV\Tests\unit\Connector\Sabre;
|
2015-04-16 23:39:44 +03:00
|
|
|
|
2015-08-30 20:13:01 +03:00
|
|
|
use OCA\DAV\Connector\Sabre\BlockLegacyClientPlugin;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\IConfig;
|
2016-10-24 23:38:22 +03:00
|
|
|
use PHPUnit_Framework_MockObject_MockObject;
|
2015-04-16 23:39:44 +03:00
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class BlockLegacyClientPluginTest
|
|
|
|
*
|
2016-05-25 17:04:15 +03:00
|
|
|
* @package OCA\DAV\Tests\unit\Connector\Sabre
|
2015-04-16 23:39:44 +03:00
|
|
|
*/
|
|
|
|
class BlockLegacyClientPluginTest extends TestCase {
|
2016-10-24 23:38:22 +03:00
|
|
|
/** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
|
2015-04-16 23:39:44 +03:00
|
|
|
private $config;
|
|
|
|
/** @var BlockLegacyClientPlugin */
|
|
|
|
private $blockLegacyClientVersionPlugin;
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
public function setUp(): void {
|
2015-04-16 23:39:44 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$this->config = $this->getMockBuilder(IConfig::class)
|
2016-07-15 10:52:46 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-04-16 23:39:44 +03:00
|
|
|
$this->blockLegacyClientVersionPlugin = new BlockLegacyClientPlugin($this->config);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function oldDesktopClientProvider() {
|
|
|
|
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 (Bogus Text) mirall/1.6.9'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider oldDesktopClientProvider
|
|
|
|
* @param string $userAgent
|
2015-04-20 13:53:40 +03:00
|
|
|
* @expectedException \Sabre\DAV\Exception\Forbidden
|
2015-04-16 23:39:44 +03:00
|
|
|
* @expectedExceptionMessage Unsupported client version.
|
|
|
|
*/
|
|
|
|
public function testBeforeHandlerException($userAgent) {
|
2016-10-24 23:38:22 +03:00
|
|
|
/** @var \Sabre\HTTP\RequestInterface | PHPUnit_Framework_MockObject_MockObject $request */
|
|
|
|
$request = $this->createMock('\Sabre\HTTP\RequestInterface');
|
2015-04-16 23:39:44 +03:00
|
|
|
$request
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getHeader')
|
|
|
|
->with('User-Agent')
|
|
|
|
->will($this->returnValue($userAgent));
|
|
|
|
|
|
|
|
$this->config
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSystemValue')
|
2016-10-24 23:38:22 +03:00
|
|
|
->with('minimum.supported.desktop.version', '2.0.0')
|
2015-04-16 23:39:44 +03:00
|
|
|
->will($this->returnValue('1.7.0'));
|
|
|
|
|
|
|
|
$this->blockLegacyClientVersionPlugin->beforeHandler($request);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function newAndAlternateDesktopClientProvider() {
|
|
|
|
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 (Bogus Text) mirall/1.9.3'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider newAndAlternateDesktopClientProvider
|
|
|
|
* @param string $userAgent
|
|
|
|
*/
|
2015-04-23 17:33:51 +03:00
|
|
|
public function testBeforeHandlerSuccess($userAgent) {
|
2016-10-24 23:38:22 +03:00
|
|
|
/** @var \Sabre\HTTP\RequestInterface | PHPUnit_Framework_MockObject_MockObject $request */
|
|
|
|
$request = $this->createMock('\Sabre\HTTP\RequestInterface');
|
2015-04-16 23:39:44 +03:00
|
|
|
$request
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getHeader')
|
|
|
|
->with('User-Agent')
|
|
|
|
->will($this->returnValue($userAgent));
|
|
|
|
|
|
|
|
$this->config
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSystemValue')
|
2016-10-24 23:38:22 +03:00
|
|
|
->with('minimum.supported.desktop.version', '2.0.0')
|
2015-04-16 23:39:44 +03:00
|
|
|
->will($this->returnValue('1.7.0'));
|
|
|
|
|
|
|
|
$this->blockLegacyClientVersionPlugin->beforeHandler($request);
|
|
|
|
}
|
|
|
|
|
2015-04-23 17:33:51 +03:00
|
|
|
public function testBeforeHandlerNoUserAgent() {
|
2016-10-24 23:38:22 +03:00
|
|
|
/** @var \Sabre\HTTP\RequestInterface | PHPUnit_Framework_MockObject_MockObject $request */
|
|
|
|
$request = $this->createMock('\Sabre\HTTP\RequestInterface');
|
2015-04-23 17:33:51 +03:00
|
|
|
$request
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getHeader')
|
|
|
|
->with('User-Agent')
|
|
|
|
->will($this->returnValue(null));
|
|
|
|
$this->blockLegacyClientVersionPlugin->beforeHandler($request);
|
|
|
|
}
|
|
|
|
|
2015-04-16 23:39:44 +03:00
|
|
|
}
|