-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow storage wrappers to through a forbidden exception with retry in…
…formation
- Loading branch information
1 parent
705d208
commit e2cfcd9
Showing
12 changed files
with
270 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/** | ||
* @author Joas Schilling <nickvergessen@owncloud.com> | ||
* | ||
* @copyright Copyright (c) 2015, ownCloud, Inc. | ||
* @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/> | ||
* | ||
*/ | ||
|
||
namespace OCA\DAV\Connector\Sabre\Exception; | ||
|
||
class Forbidden extends \Sabre\DAV\Exception\Forbidden { | ||
|
||
const NS_OWNCLOUD = 'http://owncloud.org/ns'; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private $retry; | ||
|
||
/** | ||
* @param string $message | ||
* @param bool $retry | ||
* @param \Exception $previous | ||
*/ | ||
public function __construct($message, $retry = false, \Exception $previous = null) { | ||
parent::__construct($message, 0, $previous); | ||
$this->retry = $retry; | ||
} | ||
|
||
/** | ||
* This method allows the exception to include additional information | ||
* into the WebDAV error response | ||
* | ||
* @param \Sabre\DAV\Server $server | ||
* @param \DOMElement $errorNode | ||
* @return void | ||
*/ | ||
public function serialize(\Sabre\DAV\Server $server,\DOMElement $errorNode) { | ||
|
||
// set ownCloud namespace | ||
$errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD); | ||
|
||
// adding the retry node | ||
$error = $errorNode->ownerDocument->createElementNS('o:','o:retry', var_export($this->retry, true)); | ||
$errorNode->appendChild($error); | ||
|
||
// adding the message node | ||
$error = $errorNode->ownerDocument->createElementNS('o:','o:reason', $this->getMessage()); | ||
$errorNode->appendChild($error); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
apps/dav/tests/unit/connector/sabre/exception/forbiddentest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/** | ||
* Copyright (c) 2015 Thomas Müller <deepdiver@owncloud.com> | ||
* This file is licensed under the Affero General Public License version 3 or | ||
* later. | ||
* See the COPYING-README file. | ||
*/ | ||
|
||
namespace OCA\DAV\Tests\Unit\Connector\Sabre\Exception; | ||
|
||
use OCA\DAV\Connector\Sabre\Exception\Forbidden; | ||
|
||
class ForbiddenTest extends \Test\TestCase { | ||
|
||
public function testSerialization() { | ||
|
||
// create xml doc | ||
$DOM = new \DOMDocument('1.0','utf-8'); | ||
$DOM->formatOutput = true; | ||
$error = $DOM->createElementNS('DAV:','d:error'); | ||
$error->setAttribute('xmlns:s', \Sabre\DAV\Server::NS_SABREDAV); | ||
$DOM->appendChild($error); | ||
|
||
// serialize the exception | ||
$message = "1234567890"; | ||
$retry = false; | ||
$expectedXml = <<<EOD | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:o="http://owncloud.org/ns"> | ||
<o:retry xmlns:o="o:">false</o:retry> | ||
<o:reason xmlns:o="o:">1234567890</o:reason> | ||
</d:error> | ||
EOD; | ||
|
||
$ex = new Forbidden($message, $retry); | ||
$server = $this->getMock('Sabre\DAV\Server'); | ||
$ex->serialize($server, $error); | ||
|
||
// assert | ||
$xml = $DOM->saveXML(); | ||
$this->assertEquals($expectedXml, $xml); | ||
} | ||
} |
10 changes: 5 additions & 5 deletions
10
apps/dav/tests/unit/connector/sabre/exception/invalidpathtest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.