Skip to content

Commit 38714a2

Browse files
Merge pull request #41741 from nextcloud/backport/41705/stable28
[stable28] confirm content on dav-v2 test
2 parents 700b6ea + ec74c00 commit 38714a2

File tree

2 files changed

+69
-18
lines changed

2 files changed

+69
-18
lines changed

build/integration/features/bootstrap/WebDav.php

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* @author Joas Schilling <[email protected]>
88
* @author John Molakvoæ <[email protected]>
99
* @author Lukas Reschke <[email protected]>
10+
* @author Maxence Lange <[email protected]>
1011
* @author Morris Jobke <[email protected]>
1112
* @author Robin Appelman <[email protected]>
1213
* @author Roeland Jago Douma <[email protected]>
@@ -31,9 +32,10 @@
3132
* along with this program. If not, see <http://www.gnu.org/licenses/>.
3233
*
3334
*/
35+
3436
use GuzzleHttp\Client as GClient;
35-
use GuzzleHttp\Message\ResponseInterface;
3637
use PHPUnit\Framework\Assert;
38+
use Psr\Http\Message\ResponseInterface;
3739
use Sabre\DAV\Client as SClient;
3840
use Sabre\DAV\Xml\Property\ResourceType;
3941

@@ -43,17 +45,13 @@
4345
trait WebDav {
4446
use Sharing;
4547

46-
/** @var string */
47-
private $davPath = "remote.php/webdav";
48-
/** @var boolean */
49-
private $usingOldDavPath = true;
48+
private string $davPath = "remote.php/webdav";
49+
private bool $usingOldDavPath = true;
50+
private ?array $storedETAG = null; // map with user as key and another map as value, which has path as key and etag as value
51+
private ?int $storedFileID = null;
5052
/** @var ResponseInterface */
5153
private $response;
52-
/** @var array map with user as key and another map as value, which has path as key and etag as value */
53-
private $storedETAG = null;
54-
/** @var int */
55-
private $storedFileID = null;
56-
54+
private array $parsedResponse = [];
5755
private string $s3MultipartDestination;
5856
private string $uploadId;
5957

@@ -237,7 +235,7 @@ public function search(): void {
237235
public function searchFavorite(): void {
238236
$this->searchFile(
239237
$this->currentUser,
240-
null,
238+
'<oc:favorite/>',
241239
null,
242240
'<d:eq>
243241
<d:prop>
@@ -333,19 +331,32 @@ public function asTheFileOrFolderExists($user, $entry, $path) {
333331
$this->response = $this->listFolder($user, $path, 0);
334332
}
335333

334+
/**
335+
* @Then the response should be empty
336+
* @throws \Exception
337+
*/
338+
public function theResponseShouldBeEmpty(): void {
339+
$response = ($this->response instanceof ResponseInterface) ? $this->convertResponseToDavEntries() : $this->response;
340+
if ($response === []) {
341+
return;
342+
}
343+
344+
throw new \Exception('response is not empty');
345+
}
346+
336347
/**
337348
* @Then the single response should contain a property :key with value :value
338349
* @param string $key
339350
* @param string $expectedValue
340351
* @throws \Exception
341352
*/
342353
public function theSingleResponseShouldContainAPropertyWithValue($key, $expectedValue) {
343-
$keys = $this->response;
344-
if (!array_key_exists($key, $keys)) {
354+
$response = ($this->response instanceof ResponseInterface) ? $this->convertResponseToDavSingleEntry() : $this->response;
355+
if (!array_key_exists($key, $response)) {
345356
throw new \Exception("Cannot find property \"$key\" with \"$expectedValue\"");
346357
}
347358

348-
$value = $keys[$key];
359+
$value = $response[$key];
349360
if ($value instanceof ResourceType) {
350361
$value = $value->getValue();
351362
if (empty($value)) {
@@ -533,6 +544,7 @@ public function searchFile(string $user, ?string $properties = null, ?string $sc
533544
$this->response = $this->makeDavRequest($user, "SEARCH", '', [
534545
'Content-Type' => 'text/xml'
535546
], $body, '');
547+
536548
var_dump((string)$this->response->getBody());
537549
} catch (\GuzzleHttp\Exception\ServerException $e) {
538550
// 5xx responses cause a server exception
@@ -1112,4 +1124,32 @@ public function theUploadShouldFailOnObjectStorage() {
11121124
$this->theHTTPStatusCodeShouldBe(500);
11131125
}
11141126
}
1127+
1128+
/**
1129+
* @return array
1130+
* @throws Exception
1131+
*/
1132+
private function convertResponseToDavSingleEntry(): array {
1133+
$results = $this->convertResponseToDavEntries();
1134+
if (count($results) > 1) {
1135+
throw new \Exception('result is empty or contain more than one (1) entry');
1136+
}
1137+
1138+
return array_shift($results);
1139+
}
1140+
1141+
/**
1142+
* @return array
1143+
*/
1144+
private function convertResponseToDavEntries(): array {
1145+
$client = $this->getSabreClient($this->currentUser);
1146+
$parsedResponse = $client->parseMultiStatus((string)$this->response->getBody());
1147+
1148+
$results = [];
1149+
foreach ($parsedResponse as $href => $statusList) {
1150+
$results[$href] = $statusList[200] ?? [];
1151+
}
1152+
1153+
return $results;
1154+
}
11151155
}

build/integration/features/dav-v2.feature

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,27 @@ Feature: dav-v2
8181
When User "user0" uploads file "data/textfile.txt" to "/testquota/asdf.txt"
8282
Then the HTTP status code should be "201"
8383

84-
Scenario: Create a search query
84+
Scenario: Create a search query on image
8585
Given using new dav path
8686
And As an "admin"
87-
When User "user0" uploads file "data/green-square-256.png" to "/image.png"
88-
When Image search should work
87+
And user "user0" exists
88+
And As an "user0"
89+
When User "user0" uploads file "data/textfile.txt" to "/testquota/asdf.txt"
90+
Then Image search should work
91+
And the response should be empty
92+
When User "user0" uploads file "data/green-square-256.png" to "/image.png"
93+
Then Image search should work
94+
And the single response should contain a property "{DAV:}getcontenttype" with value "image/png"
8995

9096
Scenario: Create a search query on favorite
9197
Given using new dav path
9298
And As an "admin"
9399
And user "user0" exists
100+
And As an "user0"
94101
When User "user0" uploads file "data/green-square-256.png" to "/fav_image.png"
102+
Then Favorite search should work
103+
And the response should be empty
95104
When user "user0" favorites element "/fav_image.png"
96-
When Favorite search should work
105+
Then Favorite search should work
106+
And the single response should contain a property "{http://owncloud.org/ns}favorite" with value "1"
107+

0 commit comments

Comments
 (0)