Skip to content

Commit

Permalink
Tests for new Sabre Plugins, FileService and RollbackService
Browse files Browse the repository at this point in the history
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
  • Loading branch information
georgehrke committed Jul 8, 2020
1 parent 5a3f667 commit beca6b7
Show file tree
Hide file tree
Showing 6 changed files with 791 additions and 3 deletions.
15 changes: 13 additions & 2 deletions lib/Connector/Sabre/RedirectRequestPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ public function initialize(Server $server) {
*/
public function httpCopyMove(RequestInterface $request): void {
$node = $this->getNode($request->getPath(), $request->getMethod());
if (!$this->isFile($request->getPath(), $node)) {
return;
}
/** @var File|Directory $node */
if (!$this->isE2EEnabledPath($node->getPath())) {
return;
}
Expand All @@ -104,6 +108,10 @@ public function httpCopyMove(RequestInterface $request): void {
*/
public function httpDelete(RequestInterface $request, ResponseInterface $response): bool {
$node = $this->getNode($request->getPath(), $request->getMethod());
if (!$this->isFile($request->getPath(), $node)) {
return true;
}
/** @var File|Directory $node */
if (!$this->isE2EEnabledPath($node->getPath())) {
// If this is no e2e-enabled path, return true to continue up in the event chain
return true;
Expand All @@ -119,7 +127,6 @@ public function httpDelete(RequestInterface $request, ResponseInterface $respons
$subRequest->setHeader('X-Nc-Sabre-Original-Method', 'DELETE');
$subRequest->setHeader('Destination', $path);

// TODO: wrap in try catch?
$this->server->invokeMethod($subRequest, $response);
// Return false to break the event chain
return false;
Expand All @@ -131,6 +138,10 @@ public function httpDelete(RequestInterface $request, ResponseInterface $respons
*/
public function httpMkColPut(RequestInterface $request): void {
$node = $this->getNode($request->getPath(), $request->getMethod());
if (!$this->isFile($request->getPath(), $node)) {
return;
}
/** @var File|Directory $node */
if (!$this->isE2EEnabledPath($node->getPath())) {
return;
}
Expand Down Expand Up @@ -163,7 +174,7 @@ public function httpGetHead(RequestInterface $request): void {
* @throws \Sabre\DAV\Exception\Conflict
*/
public function propFind(PropFind $propFind, INode $node): bool {
if (!$this->isFile($node->getName(), $node)) {
if (!$this->isFile($propFind->getPath(), $node)) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/RollbackService.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
namespace OCA\EndToEndEncryption;

use OC\Files\Node\Folder;
use OCP\Files\Folder;
use OCA\EndToEndEncryption\AppInfo\Application;
use OCA\EndToEndEncryption\Db\Lock;
use OCA\EndToEndEncryption\Db\LockMapper;
Expand Down
48 changes: 48 additions & 0 deletions tests/Unit/CapabilitiesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Georg Ehrke <georg-nextcloud@ehrke.email>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace OCA\EndToEndEncryption\Tests\Unit;

use OCA\EndToEndEncryption\Capabilities;
use Test\TestCase;

class CapabilitiesTest extends TestCase {

/** @var Capabilities */
private $capabilities;

protected function setUp(): void {
parent::setUp();

$this->capabilities = new Capabilities();
}

public function testGetCapabilities() {
$this->assertEquals([
'end-to-end-encryption' => [
'enabled' => true,
'api-version' => '1.0'
]
], $this->capabilities->getCapabilities());
}
}
Loading

0 comments on commit beca6b7

Please sign in to comment.