[Pkg-owncloud-commits] [php-sabredav] 174/275: Emitting 415 now when a report is not supported.

David Prévot taffit at moszumanska.debian.org
Thu Sep 25 14:56:05 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository php-sabredav.

commit 4d84192aac7ccab6c5076d11d0a1de84b9c50d95
Author: Evert Pot <me at evertpot.com>
Date:   Thu Aug 21 19:01:44 2014 -0400

    Emitting 415 now when a report is not supported.
    
    More tests!
---
 lib/CardDAV/Plugin.php                       | 26 ++++++----
 lib/DAV/Exception/ReportNotSupported.php     |  2 +-
 tests/Sabre/CalDAV/PluginTest.php            |  2 +-
 tests/Sabre/CardDAV/AddressBookQueryTest.php | 71 ++++++++++++++++++++++++++++
 tests/Sabre/CardDAV/PluginTest.php           | 25 +++++++++-
 tests/Sabre/CardDAV/ValidateVCardTest.php    | 24 ++++++++--
 tests/Sabre/DAV/Auth/PluginTest.php          |  2 +-
 tests/Sabre/DAV/ServerSimpleTest.php         |  2 +-
 tests/Sabre/DAV/Sync/PluginTest.php          |  4 +-
 9 files changed, 138 insertions(+), 20 deletions(-)

diff --git a/lib/CardDAV/Plugin.php b/lib/CardDAV/Plugin.php
index 6602f2f..0b449b0 100644
--- a/lib/CardDAV/Plugin.php
+++ b/lib/CardDAV/Plugin.php
@@ -6,6 +6,8 @@ use Sabre\DAV;
 use Sabre\DAVACL;
 use Sabre\VObject;
 
+use Sabre\DAV\Exception\ReportNotSupported;
+
 use Sabre\HTTP;
 use Sabre\HTTP\RequestInterface;
 use Sabre\HTTP\ResponseInterface;
@@ -305,10 +307,14 @@ class Plugin extends DAV\ServerPlugin {
         $xpath->registerNameSpace('card',Plugin::NS_CARDDAV);
         $xpath->registerNameSpace('dav','urn:DAV');
 
-        $requestedContentType = $xpath->evaluate("string(/card:addressbook-multiget/dav:prop/card:address-data[@content-type])");
+        $contentType = $xpath->evaluate("string(/card:addressbook-multiget/dav:prop/card:address-data/@content-type)");
+        $version = $xpath->evaluate("string(/card:addressbook-multiget/dav:prop/card:address-data/@version)");
+        if ($version) {
+            $contentType.='; version=' . $version;
+        }
 
         $vcardType = $this->negotiateVCard(
-            $requestedContentType
+            $contentType
         );
 
         $propertyList = [];
@@ -469,10 +475,14 @@ class Plugin extends DAV\ServerPlugin {
         $xpath->registerNameSpace('card',Plugin::NS_CARDDAV);
         $xpath->registerNameSpace('dav','urn:DAV');
 
-        $requestedContentType = $xpath->evaluate("string(/card:addressbook-multiget/dav:prop/card:address-data[@content-type])");
+        $contentType = $xpath->evaluate("string(/card:addressbook-query/dav:prop/card:address-data/@content-type)");
+        $version = $xpath->evaluate("string(/card:addressbook-query/dav:prop/card:address-data/@version)");
+        if ($version) {
+            $contentType.='; version=' . $version;
+        }
 
         $vcardType = $this->negotiateVCard(
-            $requestedContentType
+            $contentType
         );
 
 
@@ -511,9 +521,9 @@ class Plugin extends DAV\ServerPlugin {
 
             list($props) = $this->server->getPropertiesForPath($href, $query->requestedProperties, 0);
 
-            if (isset($props['200']['{' . self::NS_CARDDAV . '}address-data'])) {
+            if (isset($props[200]['{' . self::NS_CARDDAV . '}address-data'])) {
 
-                $props['200']['{' . self::NS_CARDDAV . '}address-data'] = $this->convertVCard(
+                $props[200]['{' . self::NS_CARDDAV . '}address-data'] = $this->convertVCard(
                     $props[200]['{' . self::NS_CARDDAV . '}address-data'],
                     $vcardType
                 );
@@ -876,7 +886,7 @@ class Plugin extends DAV\ServerPlugin {
     protected function convertVCard($data, $target) {
 
         $data = VObject\Reader::read($data);
-        switch($data) {
+        switch($target) {
             default :
             case 'vcard3' :
                 $data = $data->convert(VObject\Document::VCARD30);
@@ -886,7 +896,7 @@ class Plugin extends DAV\ServerPlugin {
                 return $data->serialize();
             case 'jcard' :
                 $data = $data->convert(VObject\Document::VCARD40);
-                return json_encode($vcard->jsonSerialize());
+                return json_encode($data->jsonSerialize());
         }
 
     }
diff --git a/lib/DAV/Exception/ReportNotSupported.php b/lib/DAV/Exception/ReportNotSupported.php
index 8e32096..8643948 100644
--- a/lib/DAV/Exception/ReportNotSupported.php
+++ b/lib/DAV/Exception/ReportNotSupported.php
@@ -13,7 +13,7 @@ use Sabre\DAV;
  * @author Evert Pot (http://evertpot.com/)
  * @license http://sabre.io/license/ Modified BSD License
  */
-class ReportNotSupported extends Forbidden {
+class ReportNotSupported extends UnsupportedMediaType {
 
     /**
      * This method allows the exception to include additional information into the WebDAV error response
diff --git a/tests/Sabre/CalDAV/PluginTest.php b/tests/Sabre/CalDAV/PluginTest.php
index 6905ace..1140f9b 100644
--- a/tests/Sabre/CalDAV/PluginTest.php
+++ b/tests/Sabre/CalDAV/PluginTest.php
@@ -130,7 +130,7 @@ class PluginTest extends \PHPUnit_Framework_TestCase {
         $this->server->httpRequest = $request;
         $this->server->exec();
 
-        $this->assertEquals(403, $this->response->status);
+        $this->assertEquals(415, $this->response->status);
 
     }
 
diff --git a/tests/Sabre/CardDAV/AddressBookQueryTest.php b/tests/Sabre/CardDAV/AddressBookQueryTest.php
index d3c6a0c..08d248a 100644
--- a/tests/Sabre/CardDAV/AddressBookQueryTest.php
+++ b/tests/Sabre/CardDAV/AddressBookQueryTest.php
@@ -189,4 +189,75 @@ class AddressBookQueryTest extends AbstractPluginTest {
 
     }
 
+    function testJson() {
+
+        $request = new HTTP\Request(
+            'REPORT',
+            '/addressbooks/user1/book1/card1',
+            ['Depth' => '0']
+        );
+
+        $request->setBody(
+'<?xml version="1.0"?>
+<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
+    <d:prop>
+      <c:address-data content-type="application/vcard+json" />
+      <d:getetag />
+    </d:prop>
+</c:addressbook-query>'
+            );
+
+        $response = new HTTP\ResponseMock();
+
+        $this->server->httpRequest = $request;
+        $this->server->httpResponse = $response;
+
+        $this->server->exec();
+
+        $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
+
+        // using the client for parsing
+        $client = new DAV\Client(array('baseUri'=>'/'));
+
+        $result = $client->parseMultiStatus($response->body);
+
+        $this->assertEquals(array(
+            '/addressbooks/user1/book1/card1' => array(
+                200 => array(
+                    '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD"). '"',
+                    '{urn:ietf:params:xml:ns:carddav}address-data' => '["vcard",[["version",{},"text","4.0"],["prodid",{},"text","-\/\/Sabre\/\/Sabre VObject 3.3.1\/\/EN"],["uid",{},"text","12345"]]]',
+                ),
+             ),
+        ), $result);
+
+    }
+
+    function testAddressBookDepth0() {
+
+        $request = new HTTP\Request(
+            'REPORT',
+            '/addressbooks/user1/book1',
+            ['Depth' => '0']
+        );
+
+        $request->setBody(
+'<?xml version="1.0"?>
+<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
+    <d:prop>
+      <c:address-data content-type="application/vcard+json" />
+      <d:getetag />
+    </d:prop>
+</c:addressbook-query>'
+            );
+
+        $response = new HTTP\ResponseMock();
+
+        $this->server->httpRequest = $request;
+        $this->server->httpResponse = $response;
+
+        $this->server->exec();
+
+        $this->assertEquals(415, $response->status, 'Incorrect status code. Full response body:' . $response->body);
+
+    }
 }
diff --git a/tests/Sabre/CardDAV/PluginTest.php b/tests/Sabre/CardDAV/PluginTest.php
index e7f61af..4c609da 100644
--- a/tests/Sabre/CardDAV/PluginTest.php
+++ b/tests/Sabre/CardDAV/PluginTest.php
@@ -4,8 +4,6 @@ namespace Sabre\CardDAV;
 
 use Sabre\DAV;
 
-require_once 'Sabre/CardDAV/AbstractPluginTest.php';
-
 class PluginTest extends AbstractPluginTest {
 
     function testConstruct() {
@@ -140,4 +138,27 @@ class PluginTest extends AbstractPluginTest {
         );
 
     }
+
+    function testAddressbookPluginProperties() {
+
+        $ns = '{' . Plugin::NS_CARDDAV . '}';
+        $propFind = new DAV\PropFind('addressbooks/user1/book1', [
+            $ns . 'supported-address-data',
+            $ns . 'supported-collation-set',
+        ]);
+        $node = $this->server->tree->getNodeForPath('addressbooks/user1/book1');
+        $this->plugin->propFindEarly($propFind, $node);
+
+        $this->assertInstanceOf(
+            'Sabre\\CardDAV\\Property\\SupportedAddressData',
+            $propFind->get($ns . 'supported-address-data')
+        );
+        $this->assertInstanceOf(
+            'Sabre\\CardDAV\\Property\\SupportedCollationSet',
+            $propFind->get($ns . 'supported-collation-set')
+        );
+
+
+    }
+
 }
diff --git a/tests/Sabre/CardDAV/ValidateVCardTest.php b/tests/Sabre/CardDAV/ValidateVCardTest.php
index b2dccaf..ad8495c 100644
--- a/tests/Sabre/CardDAV/ValidateVCardTest.php
+++ b/tests/Sabre/CardDAV/ValidateVCardTest.php
@@ -86,10 +86,10 @@ class ValidateVCardTest extends \PHPUnit_Framework_TestCase {
 
     function testCreateFileNoUID() {
 
-        $request = HTTP\Sapi::createFromServerArray(array(
-            'REQUEST_METHOD' => 'PUT',
-            'REQUEST_URI' => '/addressbooks/admin/addressbook1/blabla.vcf',
-        ));
+        $request = new HTTP\Request(
+            'PUT',
+            '/addressbooks/admin/addressbook1/blabla.vcf'
+        );
         $request->setBody("BEGIN:VCARD\r\nEND:VCARD\r\n");
 
         $response = $this->request($request);
@@ -100,6 +100,22 @@ class ValidateVCardTest extends \PHPUnit_Framework_TestCase {
         $this->assertTrue(strpos($foo['carddata'],'UID')!==false);
     }
 
+    function testCreateFileJson() {
+
+        $request = new HTTP\Request(
+            'PUT',
+            '/addressbooks/admin/addressbook1/blabla.vcf'
+        );
+        $request->setBody('[ "vcard" , [ [ "UID" , {}, "text", "foo" ] ] ]');
+
+        $response = $this->request($request);
+
+        $this->assertEquals(201, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
+
+        $foo = $this->cardBackend->getCard('addressbook1','blabla.vcf');
+        $this->assertEquals("BEGIN:VCARD\r\nUID:foo\r\nEND:VCARD\r\n", $foo['carddata']);
+
+    }
 
     function testCreateFileVCalendar() {
 
diff --git a/tests/Sabre/DAV/Auth/PluginTest.php b/tests/Sabre/DAV/Auth/PluginTest.php
index 31e5f2c..e267abd 100644
--- a/tests/Sabre/DAV/Auth/PluginTest.php
+++ b/tests/Sabre/DAV/Auth/PluginTest.php
@@ -64,7 +64,7 @@ class PluginTest extends \PHPUnit_Framework_TestCase {
         $fakeServer->httpResponse = new HTTP\ResponseMock();
         $fakeServer->exec();
 
-        $this->assertEquals(403, $fakeServer->httpResponse->status);
+        $this->assertEquals(415, $fakeServer->httpResponse->status);
 
     }
 
diff --git a/tests/Sabre/DAV/ServerSimpleTest.php b/tests/Sabre/DAV/ServerSimpleTest.php
index 5876d19..bcc8078 100644
--- a/tests/Sabre/DAV/ServerSimpleTest.php
+++ b/tests/Sabre/DAV/ServerSimpleTest.php
@@ -572,7 +572,7 @@ class ServerSimpleTest extends AbstractServer{
             $this->response->headers
          );
 
-        $this->assertEquals(403, $this->response->status,'We got an incorrect status back. Full response body follows: ' . $this->response->body);
+        $this->assertEquals(415, $this->response->status,'We got an incorrect status back. Full response body follows: ' . $this->response->body);
 
     }
 
diff --git a/tests/Sabre/DAV/Sync/PluginTest.php b/tests/Sabre/DAV/Sync/PluginTest.php
index 662e9a8..863f692 100644
--- a/tests/Sabre/DAV/Sync/PluginTest.php
+++ b/tests/Sabre/DAV/Sync/PluginTest.php
@@ -346,7 +346,7 @@ BLA;
 
         // The default state has no sync-token, so this report should not yet
         // be supported.
-        $this->assertEquals(403, $response->status, 'Full response body:' . $response->body);
+        $this->assertEquals(415, $response->status, 'Full response body:' . $response->body);
 
     }
 
@@ -375,7 +375,7 @@ BLA;
 
         // The default state has no sync-token, so this report should not yet
         // be supported.
-        $this->assertEquals(403, $response->status, 'Full response body:' . $response->body);
+        $this->assertEquals(415, $response->status, 'Full response body:' . $response->body);
 
     }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git



More information about the Pkg-owncloud-commits mailing list