|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @author Lukas Reschke <[email protected]> |
| 4 | + * |
| 5 | + * @copyright Copyright (c) 2015, ownCloud, Inc. |
| 6 | + * @license AGPL-3.0 |
| 7 | + * |
| 8 | + * This code is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU Affero General Public License, version 3, |
| 10 | + * as published by the Free Software Foundation. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU Affero General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU Affero General Public License, version 3, |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/> |
| 19 | + * |
| 20 | + */ |
| 21 | + |
| 22 | +namespace Test\Connector\Sabre; |
| 23 | + |
| 24 | +use OC\Connector\Sabre\BlockLegacyClientPlugin; |
| 25 | +use Test\TestCase; |
| 26 | +use OCP\IConfig; |
| 27 | + |
| 28 | +/** |
| 29 | + * Class BlockLegacyClientPluginTest |
| 30 | + * |
| 31 | + * @package Test\Connector\Sabre |
| 32 | + */ |
| 33 | +class BlockLegacyClientPluginTest extends TestCase { |
| 34 | + /** @var IConfig */ |
| 35 | + private $config; |
| 36 | + /** @var BlockLegacyClientPlugin */ |
| 37 | + private $blockLegacyClientVersionPlugin; |
| 38 | + |
| 39 | + public function setUp() { |
| 40 | + parent::setUp(); |
| 41 | + |
| 42 | + $this->config = $this->getMock('\OCP\IConfig'); |
| 43 | + $this->blockLegacyClientVersionPlugin = new BlockLegacyClientPlugin($this->config); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * @return array |
| 48 | + */ |
| 49 | + public function oldDesktopClientProvider() { |
| 50 | + return [ |
| 51 | + ['Mozilla/5.0 (1.5.0) mirall/1.5.0'], |
| 52 | + ['mirall/1.5.0'], |
| 53 | + ['mirall/1.5.4'], |
| 54 | + ['mirall/1.6.0'], |
| 55 | + ['Mozilla/5.0 (Bogus Text) mirall/1.6.9'], |
| 56 | + ]; |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * @dataProvider oldDesktopClientProvider |
| 61 | + * @param string $userAgent |
| 62 | + * @expectedException \Sabre\DAV\Exception\Forbidden |
| 63 | + * @expectedExceptionMessage Unsupported client version. |
| 64 | + */ |
| 65 | + public function testBeforeHandlerException($userAgent) { |
| 66 | + /** @var \Sabre\HTTP\RequestInterface $request */ |
| 67 | + $request = $this->getMock('\Sabre\HTTP\RequestInterface'); |
| 68 | + $request |
| 69 | + ->expects($this->once()) |
| 70 | + ->method('getHeader') |
| 71 | + ->with('User-Agent') |
| 72 | + ->will($this->returnValue($userAgent)); |
| 73 | + |
| 74 | + $this->config |
| 75 | + ->expects($this->once()) |
| 76 | + ->method('getSystemValue') |
| 77 | + ->with('minimum.supported.desktop.version', '1.7.0') |
| 78 | + ->will($this->returnValue('1.7.0')); |
| 79 | + |
| 80 | + $this->blockLegacyClientVersionPlugin->beforeHandler($request); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * @return array |
| 85 | + */ |
| 86 | + public function newAndAlternateDesktopClientProvider() { |
| 87 | + return [ |
| 88 | + ['Mozilla/5.0 (1.7.0) mirall/1.7.0'], |
| 89 | + ['mirall/1.8.3'], |
| 90 | + ['mirall/1.7.2'], |
| 91 | + ['mirall/1.7.0'], |
| 92 | + ['Mozilla/5.0 (Bogus Text) mirall/1.9.3'], |
| 93 | + ]; |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * @dataProvider newAndAlternateDesktopClientProvider |
| 98 | + * @param string $userAgent |
| 99 | + */ |
| 100 | + public function testBeforeHandlerSuccess($userAgent) { |
| 101 | + /** @var \Sabre\HTTP\RequestInterface $request */ |
| 102 | + $request = $this->getMock('\Sabre\HTTP\RequestInterface'); |
| 103 | + $request |
| 104 | + ->expects($this->once()) |
| 105 | + ->method('getHeader') |
| 106 | + ->with('User-Agent') |
| 107 | + ->will($this->returnValue($userAgent)); |
| 108 | + |
| 109 | + $this->config |
| 110 | + ->expects($this->once()) |
| 111 | + ->method('getSystemValue') |
| 112 | + ->with('minimum.supported.desktop.version', '1.7.0') |
| 113 | + ->will($this->returnValue('1.7.0')); |
| 114 | + |
| 115 | + $this->blockLegacyClientVersionPlugin->beforeHandler($request); |
| 116 | + } |
| 117 | + |
| 118 | + public function testBeforeHandlerNoUserAgent() { |
| 119 | + /** @var \Sabre\HTTP\RequestInterface $request */ |
| 120 | + $request = $this->getMock('\Sabre\HTTP\RequestInterface'); |
| 121 | + $request |
| 122 | + ->expects($this->once()) |
| 123 | + ->method('getHeader') |
| 124 | + ->with('User-Agent') |
| 125 | + ->will($this->returnValue(null)); |
| 126 | + $this->blockLegacyClientVersionPlugin->beforeHandler($request); |
| 127 | + } |
| 128 | + |
| 129 | +} |
0 commit comments