]> source.dussan.org Git - nextcloud-server.git/commitdiff
confirm content on dav-v2 test 41705/head
authorMaxence Lange <maxence@artificial-owl.com>
Fri, 24 Nov 2023 09:35:01 +0000 (08:35 -0100)
committerMaxence Lange <maxence@artificial-owl.com>
Fri, 24 Nov 2023 12:11:48 +0000 (11:11 -0100)
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
build/integration/features/bootstrap/WebDav.php
build/integration/features/dav-v2.feature

index 4212f56ce2b4410415c5a0717bedb310eaa839cd..c239461b78864a715e15e705d2ee5f29c90065bb 100644 (file)
@@ -7,6 +7,7 @@
  * @author Joas Schilling <coding@schilljs.com>
  * @author John Molakvoæ <skjnldsv@protonmail.com>
  * @author Lukas Reschke <lukas@statuscode.ch>
+ * @author Maxence Lange <maxence@artificial-owl.com>
  * @author Morris Jobke <hey@morrisjobke.de>
  * @author Robin Appelman <robin@icewind.nl>
  * @author Roeland Jago Douma <roeland@famdouma.nl>
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  *
  */
+
 use GuzzleHttp\Client as GClient;
-use GuzzleHttp\Message\ResponseInterface;
 use PHPUnit\Framework\Assert;
+use Psr\Http\Message\ResponseInterface;
 use Sabre\DAV\Client as SClient;
 use Sabre\DAV\Xml\Property\ResourceType;
 
@@ -43,17 +45,13 @@ require __DIR__ . '/../../vendor/autoload.php';
 trait WebDav {
        use Sharing;
 
-       /** @var string */
-       private $davPath = "remote.php/webdav";
-       /** @var boolean */
-       private $usingOldDavPath = true;
+       private string $davPath = "remote.php/webdav";
+       private bool $usingOldDavPath = true;
+       private ?array $storedETAG = null; // map with user as key and another map as value, which has path as key and etag as value
+       private ?int $storedFileID = null;
        /** @var ResponseInterface */
        private $response;
-       /** @var array map with user as key and another map as value, which has path as key and etag as value */
-       private $storedETAG = null;
-       /** @var int */
-       private $storedFileID = null;
-
+       private array $parsedResponse = [];
        private string $s3MultipartDestination;
        private string $uploadId;
 
@@ -237,7 +235,7 @@ trait WebDav {
        public function searchFavorite(): void {
                $this->searchFile(
                        $this->currentUser,
-                       null,
+                       '<oc:favorite/>',
                        null,
                        '<d:eq>
                        <d:prop>
@@ -333,6 +331,19 @@ trait WebDav {
                $this->response = $this->listFolder($user, $path, 0);
        }
 
+       /**
+        * @Then the response should be empty
+        * @throws \Exception
+        */
+       public function theResponseShouldBeEmpty(): void {
+               $response = ($this->response instanceof ResponseInterface) ? $this->convertResponseToDavEntries() : $this->response;
+               if ($response === []) {
+                       return;
+               }
+
+               throw new \Exception('response is not empty');
+       }
+
        /**
         * @Then the single response should contain a property :key with value :value
         * @param string $key
@@ -340,12 +351,12 @@ trait WebDav {
         * @throws \Exception
         */
        public function theSingleResponseShouldContainAPropertyWithValue($key, $expectedValue) {
-               $keys = $this->response;
-               if (!array_key_exists($key, $keys)) {
+               $response = ($this->response instanceof ResponseInterface) ? $this->convertResponseToDavSingleEntry() : $this->response;
+               if (!array_key_exists($key, $response)) {
                        throw new \Exception("Cannot find property \"$key\" with \"$expectedValue\"");
                }
 
-               $value = $keys[$key];
+               $value = $response[$key];
                if ($value instanceof ResourceType) {
                        $value = $value->getValue();
                        if (empty($value)) {
@@ -533,6 +544,7 @@ trait WebDav {
                        $this->response = $this->makeDavRequest($user, "SEARCH", '', [
                                'Content-Type' => 'text/xml'
                        ], $body, '');
+
                        var_dump((string)$this->response->getBody());
                } catch (\GuzzleHttp\Exception\ServerException $e) {
                        // 5xx responses cause a server exception
@@ -1112,4 +1124,32 @@ trait WebDav {
                        $this->theHTTPStatusCodeShouldBe(500);
                }
        }
+
+       /**
+        * @return array
+        * @throws Exception
+        */
+       private function convertResponseToDavSingleEntry(): array {
+               $results = $this->convertResponseToDavEntries();
+               if (count($results) > 1) {
+                       throw new \Exception('result is empty or contain more than one (1) entry');
+               }
+
+               return array_shift($results);
+       }
+
+       /**
+        * @return array
+        */
+       private function convertResponseToDavEntries(): array {
+               $client = $this->getSabreClient($this->currentUser);
+               $parsedResponse = $client->parseMultiStatus((string)$this->response->getBody());
+
+               $results = [];
+               foreach ($parsedResponse as $href => $statusList) {
+                       $results[$href] = $statusList[200] ?? [];
+               }
+
+               return $results;
+       }
 }
index 235ae5339134e1a8cc8eeb092d9cabb1df7a1561..a3ac59578e97eb5e93702a84cdea718a3af63b43 100644 (file)
@@ -81,16 +81,27 @@ Feature: dav-v2
                When User "user0" uploads file "data/textfile.txt" to "/testquota/asdf.txt"
                Then the HTTP status code should be "201"
 
-       Scenario: Create a search query
+       Scenario: Create a search query on image
                Given using new dav path
                And As an "admin"
-               When User "user0" uploads file "data/green-square-256.png" to "/image.png"
-               When Image search should work
+    And user "user0" exists
+    And As an "user0"
+    When User "user0" uploads file "data/textfile.txt" to "/testquota/asdf.txt"
+    Then Image search should work
+    And the response should be empty
+    When User "user0" uploads file "data/green-square-256.png" to "/image.png"
+               Then Image search should work
+    And the single response should contain a property "{DAV:}getcontenttype" with value "image/png"
 
   Scenario: Create a search query on favorite
     Given using new dav path
     And As an "admin"
     And user "user0" exists
+    And As an "user0"
     When User "user0" uploads file "data/green-square-256.png" to "/fav_image.png"
+    Then Favorite search should work
+    And the response should be empty
     When user "user0" favorites element "/fav_image.png"
-    When Favorite search should work
+    Then Favorite search should work
+    And the single response should contain a property "{http://owncloud.org/ns}favorite" with value "1"
+