Skip to content

Commit 0892258

Browse files
committed
test: fix PROPFIND shares space tests
1 parent 7da4086 commit 0892258

File tree

11 files changed

+229
-260
lines changed

11 files changed

+229
-260
lines changed

tests/acceptance/TestHelpers/GraphHelper.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public static function getShareIdRegex(): string {
116116
public static function getEtagRegex(): string {
117117
return "^\\\"[a-f0-9:.]{1,32}\\\"$";
118118
}
119+
119120
/**
120121
* Federated users have a base64 encoded string of {remoteid}@{provider} as their id
121122
* This regex matches only non empty base64 encoded strings
@@ -126,6 +127,19 @@ public static function getFederatedUserRegex(): string {
126127
return '^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{4})$';
127128
}
128129

130+
/**
131+
* @param string $pattern
132+
*
133+
* @return string regex pattern
134+
*/
135+
public static function sanitizeRegexPattern(string $pattern): string {
136+
$pattern = \str_replace("\\\\", "\\", $pattern);
137+
$pattern = \str_replace("/", "\/", $pattern);
138+
$pattern = \preg_replace('/^\^/', '', $pattern);
139+
$pattern = \preg_replace('/\$$/', '', $pattern);
140+
return "/^$pattern$/";
141+
}
142+
129143
/**
130144
* Key name can consist of @@@
131145
* This function separate such key and return its actual value from actual drive response which can be used for assertion

tests/acceptance/bootstrap/SpacesContext.php

Lines changed: 69 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,11 @@ public function getResourceId(string $user, string $spaceName, string $folderNam
355355
$this->featureContext->getPasswordForUser($user),
356356
['Depth' => '0'],
357357
);
358-
$responseArray = json_decode(json_encode($this->featureContext->getResponseXml($response)->xpath("//d:response/d:propstat/d:prop/oc:fileid")), true, 512, JSON_THROW_ON_ERROR);
359-
Assert::assertNotEmpty($responseArray, "the PROPFIND response for $folderName is empty");
360-
return $responseArray[0][0];
358+
359+
$this->featureContext->theHttpStatusCodeShouldBe(207, '', $response);
360+
$xmlResponse = $this->featureContext->getResponseXml($response);
361+
$fileId = $xmlResponse->xpath("//d:response/d:propstat/d:prop/oc:fileid")[0];
362+
return $fileId->__toString();
361363
}
362364

363365
/**
@@ -3701,9 +3703,8 @@ public function userSendsPropfindRequestToSpaceUsingTheWebdavApi(string $user, s
37013703
* @throws GuzzleException
37023704
*/
37033705
public function userSendsPropfindRequestFromTheSpaceToTheResourceWithDepthUsingTheWebdavApi(string $user, string $spaceName, string $resource, ?string $folderDepth = "1"): void {
3704-
$this->featureContext->setResponse(
3705-
$this->sendPropfindRequestToSpace($user, $spaceName, $resource, null, $folderDepth)
3706-
);
3706+
$response = $this->sendPropfindRequestToSpace($user, $spaceName, $resource, null, $folderDepth);
3707+
$this->featureContext->setResponse($response);
37073708
}
37083709

37093710
/**
@@ -3768,6 +3769,16 @@ public function sendPropfindRequestToSpace(string $user, string $spaceName, ?str
37683769
'd:lockdiscovery',
37693770
'd:activelock'
37703771
];
3772+
3773+
$davPathVersion = $this->featureContext->getDavPathVersion();
3774+
if ($spaceName === 'Shares' && $davPathVersion !== WebDavHelper::DAV_VERSION_SPACES) {
3775+
if ($resource === '' || $resource === '/') {
3776+
$resource = $spaceName;
3777+
} else {
3778+
$resource = $spaceName . '/' . $resource;
3779+
}
3780+
}
3781+
37713782
return WebDavHelper::propfind(
37723783
$this->featureContext->getBaseUrl(),
37733784
$this->featureContext->getActualUsername($user),
@@ -3777,127 +3788,110 @@ public function sendPropfindRequestToSpace(string $user, string $spaceName, ?str
37773788
$this->featureContext->getStepLineRef(),
37783789
$folderDepth,
37793790
"files",
3780-
$this->featureContext->getDavPathVersion(),
3791+
$davPathVersion,
37813792
null,
37823793
$headers
37833794
);
37843795
}
37853796

37863797
/**
3787-
* @Then /^the "([^"]*)" response should contain a space "([^"]*)" with these key and value pairs:$/
3788-
*
3789-
* @param string $method # method should be either PROPFIND or REPORT
3790-
* @param string $space
3791-
* @param TableNode $table
3792-
*
3793-
* @return void
3794-
* @throws GuzzleException
3795-
* @throws JsonException
3796-
*/
3797-
public function theResponseShouldContainSpace(string $method, string $space, TableNode $table): void {
3798-
$this->featureContext->verifyTableNodeColumns($table, ['key', 'value']);
3799-
$this->theResponseShouldContain($method, $this->getSpaceCreator($space), $space, $table);
3800-
}
3801-
3802-
/**
3803-
* @Then /^the "([^"]*)" response to user "([^"]*)" should contain a mountpoint "([^"]*)" with these key and value pairs:$/
3804-
* @Then /^the "([^"]*)" response to user "([^"]*)" should contain a space "([^"]*)" with these key and value pairs:$/
3798+
* @Then /^as user "([^"]*)" the (PROPFIND|REPORT) response should contain a (mountpoint|space) "([^"]*)" with these key and value pairs:$/
38053799
*
3806-
* @param string $method # method should be either PROPFIND or REPORT
38073800
* @param string $user
3801+
* @param string $method # method should be either PROPFIND or REPORT
3802+
* @param string $type # type should be either mountpoint or space
38083803
* @param string $mountPoint
38093804
* @param TableNode $table
38103805
*
38113806
* @return void
38123807
* @throws GuzzleException
38133808
* @throws JsonException
38143809
*/
3815-
public function theResponseShouldContainMountPoint(string $method, string $user, string $mountPoint, TableNode $table): void {
3810+
public function asUsertheXMLResponseShouldContainMountpointWithTheseKeyAndValuePair(string $user, string $method, string $type, string $mountPoint, TableNode $table): void {
38163811
$this->featureContext->verifyTableNodeColumns($table, ['key', 'value']);
3817-
$this->theResponseShouldContain($method, $user, $mountPoint, $table);
3812+
if ($this->featureContext->getDavPathVersion() === WebDavHelper::DAV_VERSION_SPACES && $type === 'space') {
3813+
$space = $this->getSpaceByName($user, $mountPoint);
3814+
$mountPoint = $space['id'];
3815+
} else {
3816+
$mountPoint = \rawurlencode($mountPoint);
3817+
}
3818+
$this->theXMLResponseShouldContain($mountPoint, $table);
38183819
}
38193820

38203821
/**
3821-
* @param string $method # method should be either PROPFIND or REPORT
3822-
* @param string $user
38233822
* @param string $spaceNameOrMountPoint # an entity inside a space, or the space name itself
38243823
* @param TableNode $table
38253824
*
38263825
* @return void
38273826
* @throws GuzzleException
38283827
* @throws JsonException
38293828
*/
3830-
public function theResponseShouldContain(string $method, string $user, string $spaceNameOrMountPoint, TableNode $table): void {
3831-
$xmlRes = $this->featureContext->getResponseXml();
3829+
public function theXMLResponseShouldContain(string $spaceNameOrMountPoint, TableNode $table): void {
3830+
$xmlResponse = $this->featureContext->getResponseXml();
3831+
$hrefs = array_map(fn($href) => $href->__toString(), $xmlResponse->xpath("//d:response/d:href"));
3832+
3833+
$currentHref = '';
3834+
foreach ($hrefs as $href) {
3835+
if (\str_ends_with(\rtrim($href, "/"), "/$spaceNameOrMountPoint")) {
3836+
$currentHref = $href;
3837+
break;
3838+
}
3839+
}
3840+
38323841
foreach ($table->getHash() as $row) {
3833-
$findItem = $row['key'];
3834-
$xmlResponses = $xmlRes->xpath("//d:response/d:propstat/d:prop/$findItem");
3842+
$itemToFind = $row['key'];
3843+
$foundXmlItem = $xmlResponse->xpath("//d:href[text()='$currentHref']/following-sibling::d:propstat//$itemToFind");
38353844
Assert::assertNotEmpty(
3836-
$xmlResponses,
3837-
'The xml response "' . $xmlRes->asXML() . '" did not contain "<' . $findItem . '>" element'
3845+
$foundXmlItem,
3846+
'The xml response "' . $xmlResponse->asXML() . '" did not contain "<' . $itemToFind . '>" element'
38383847
);
38393848

3840-
$responseValues = [];
3841-
foreach ($xmlResponses as $xmlResponse) {
3842-
$responseValues[] = $xmlResponse[0]->__toString();
3843-
}
3849+
$actualValue = $foundXmlItem[0]->__toString();
3850+
$expectedValue = $this->featureContext->substituteInLineCodes($row['value']);
38443851

3845-
$value = str_replace('UUIDof:', '', $row['value']);
3846-
switch ($findItem) {
3852+
switch ($itemToFind) {
38473853
case "oc:fileid":
3848-
$resourceType = $xmlRes->xpath("//d:response/d:propstat/d:prop/d:getcontenttype")[0]->__toString();
3849-
if ($method === 'PROPFIND') {
3850-
if (!$resourceType) {
3851-
Assert::assertContainsEquals($this->getResourceId($user, $spaceNameOrMountPoint, $value), $responseValues, 'wrong fileId in the response');
3852-
} else {
3853-
Assert::assertContainsEquals($this->getFileId($user, $spaceNameOrMountPoint, $value), $responseValues, 'wrong fileId in the response');
3854-
}
3855-
} else {
3856-
if ($resourceType === 'httpd/unix-directory') {
3857-
Assert::assertContainsEquals($this->getResourceId($user, $spaceNameOrMountPoint, $value), $responseValues, 'wrong fileId in the response');
3858-
} else {
3859-
Assert::assertContainsEquals($this->getFileId($user, $spaceNameOrMountPoint, $value), $responseValues, 'wrong fileId in the response');
3860-
}
3861-
}
3854+
$expectedValue = GraphHelper::sanitizeRegexPattern($expectedValue);
3855+
Assert::assertRegExp($expectedValue, $actualValue, 'wrong "fileid" in the response');
38623856
break;
38633857
case "oc:file-parent":
3864-
Assert::assertContainsEquals($this->getResourceId($user, $spaceNameOrMountPoint, $value), $responseValues, 'wrong file-parentId in the response');
3858+
$expectedValue = GraphHelper::sanitizeRegexPattern($expectedValue);
3859+
Assert::assertRegExp($expectedValue, $actualValue, 'wrong "file-parent" in the response');
38653860
break;
38663861
case "oc:privatelink":
3867-
Assert::assertContainsEquals($this->getPrivateLink($user, $spaceNameOrMountPoint), $responseValues, 'cannot find private link for space or resource in the response');
3862+
$expectedValue = GraphHelper::sanitizeRegexPattern($expectedValue);
3863+
Assert::assertRegExp($expectedValue, $actualValue, 'wrong "privatelink" in the response');
38683864
break;
38693865
case "oc:tags":
38703866
// The value should be a comma-separated string of tag names.
38713867
// We do not care what order they happen to be in, so compare as sorted lists.
3872-
$expectedTags = \explode(",", $value);
3868+
$expectedTags = \explode(",", $expectedValue);
38733869
\sort($expectedTags);
38743870
$expectedTags = \implode(",", $expectedTags);
3875-
$actualTags = [];
3876-
foreach ($responseValues as $responseValue) {
3877-
$responseValue = \explode(",", $responseValue);
3878-
\sort($responseValue);
3879-
$responseValue = \implode(",", $responseValue);
3880-
$actualTags[] = $responseValue;
3881-
}
3882-
Assert::assertContainsEquals($expectedTags, $actualTags, "wrong $findItem in the response");
3871+
3872+
$actualTags = \explode(",", $actualValue);
3873+
\sort($actualTags);
3874+
$actualTags = \implode(",", $actualValue);
3875+
Assert::assertEquals($expectedTags, $actualTags, "wrong '$itemToFind' in the response");
38833876
break;
38843877
case "d:lockdiscovery/d:activelock/d:timeout":
3885-
if ($value === "Infinity") {
3886-
Assert::assertContainsEquals($value, $responseValues, "wrong $findItem in the response");
3878+
if ($expectedValue === "Infinity") {
3879+
Assert::assertEquals($expectedValue, $actualValue, "wrong '$itemToFind' in the response");
38873880
} else {
38883881
// some time may be required between a lock and propfind request.
3889-
$responseValue = explode('-', $responseValues[0]);
3882+
$responseValue = explode('-', $actualValue);
38903883
$responseValue = \intval($responseValue[1]);
3891-
$value = explode('-', $value);
3892-
$value = \intval($value[1]);
3893-
Assert::assertTrue($responseValue >= ($value - 3));
3884+
$expectedValue = explode('-', $expectedValue);
3885+
$expectedValue = \intval($expectedValue[1]);
3886+
Assert::assertTrue($responseValue >= ($expectedValue - 3));
38943887
}
38953888
break;
38963889
case "oc:remote-item-id":
3897-
Assert::assertContainsEquals($this->getResourceId($user, $spaceNameOrMountPoint, $value), $responseValues, 'wrong remoteItemId in the response');
3890+
$expectedValue = GraphHelper::sanitizeRegexPattern($expectedValue);
3891+
Assert::assertRegExp($expectedValue, $actualValue, 'wrong "remote-item-id" in the response');
38983892
break;
38993893
default:
3900-
Assert::assertContainsEquals($value, $responseValues, "wrong $findItem in the response");
3894+
Assert::assertEquals($expectedValue, $actualValue, "wrong '$itemToFind' in the response");
39013895
break;
39023896
}
39033897
}

tests/acceptance/features/apiContract/propfind.feature

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ Feature: Propfind test
1919
Then the HTTP status code should be "207"
2020
And the following headers should match these regular expressions
2121
| X-Request-Id | /^[a-zA-Z]+\/[a-zA-Z]+\.feature:\d+(-\d+)?$/ |
22-
And the "PROPFIND" response should contain a space "new-space" with these key and value pairs:
23-
| key | value |
24-
| oc:fileid | UUIDof:new-space |
25-
| oc:name | new-space |
26-
| oc:permissions | RDNVCKZP |
27-
| oc:privatelink | |
28-
| oc:size | 12 |
22+
And as user "Alice" the PROPFIND response should contain a space "new-space" with these key and value pairs:
23+
| key | value |
24+
| oc:fileid | %file_id_pattern% |
25+
| oc:name | new-space |
26+
| oc:permissions | RDNVCKZP |
27+
| oc:privatelink | %base_url%/f/[0-9a-z-$%]+ |
28+
| oc:size | 12 |
2929

3030

3131
Scenario Outline: space member with a different role checks the PROPFIND request of a space
@@ -39,14 +39,14 @@ Feature: Propfind test
3939
Then the HTTP status code should be "207"
4040
And the following headers should match these regular expressions
4141
| X-Request-Id | /^[a-zA-Z]+\/[a-zA-Z]+\.feature:\d+(-\d+)?$/ |
42-
And the "PROPFIND" response should contain a space "new-space" with these key and value pairs:
43-
| key | value |
44-
| oc:fileid | UUIDof:new-space |
45-
| oc:name | new-space |
46-
| oc:permissions | <oc-permission> |
47-
| oc:privatelink | |
48-
| oc:size | 12 |
49-
Examples:
42+
And as user "Brian" the PROPFIND response should contain a space "new-space" with these key and value pairs:
43+
| key | value |
44+
| oc:fileid | %file_id_pattern% |
45+
| oc:name | new-space |
46+
| oc:permissions | <oc-permission> |
47+
| oc:privatelink | %base_url%/f/[0-9a-z-$%]+ |
48+
| oc:size | 12 |
49+
Examples:
5050
| space-role | oc-permission |
5151
| Manager | RDNVCKZP |
5252
| Space Editor | DNVCK |
@@ -62,10 +62,10 @@ Feature: Propfind test
6262
| permissionsRole | <space-role> |
6363
When user "Brian" sends PROPFIND request from the space "new-space" to the resource "folderMain" with depth "0" using the WebDAV API
6464
Then the HTTP status code should be "207"
65-
And the "PROPFIND" response should contain a space "new-space" with these key and value pairs:
65+
And as user "Brian" the PROPFIND response should contain a mountpoint "folderMain" with these key and value pairs:
6666
| key | value |
67-
| oc:fileid | UUIDof:folderMain |
68-
| oc:file-parent | UUIDof:new-space |
67+
| oc:fileid | %file_id_pattern% |
68+
| oc:file-parent | %file_id_pattern% |
6969
| oc:name | folderMain |
7070
| oc:permissions | <oc-permission> |
7171
| oc:size | 0 |
@@ -85,13 +85,13 @@ Feature: Propfind test
8585
| permissionsRole | <space-role> |
8686
When user "Brian" sends PROPFIND request from the space "new-space" to the resource "folderMain/subFolder1/subFolder2" with depth "0" using the WebDAV API
8787
Then the HTTP status code should be "207"
88-
And the "PROPFIND" response should contain a space "new-space" with these key and value pairs:
89-
| key | value |
90-
| oc:fileid | UUIDof:folderMain/subFolder1/subFolder2 |
91-
| oc:file-parent | UUIDof:folderMain/subFolder1 |
92-
| oc:name | subFolder2 |
93-
| oc:permissions | <oc-permission> |
94-
| oc:size | 0 |
88+
And as user "Brian" the PROPFIND response should contain a mountpoint "subFolder2" with these key and value pairs:
89+
| key | value |
90+
| oc:fileid | %file_id_pattern% |
91+
| oc:file-parent | %file_id_pattern% |
92+
| oc:name | subFolder2 |
93+
| oc:permissions | <oc-permission> |
94+
| oc:size | 0 |
9595
Examples:
9696
| space-role | oc-permission |
9797
| Manager | RDNVCKZP |
@@ -108,13 +108,13 @@ Feature: Propfind test
108108
| permissionsRole | <space-role> |
109109
When user "Brian" sends PROPFIND request from the space "new-space" to the resource "testfile.txt" with depth "0" using the WebDAV API
110110
Then the HTTP status code should be "207"
111-
And the "PROPFIND" response should contain a space "new-space" with these key and value pairs:
112-
| key | value |
113-
| oc:fileid | UUIDof:testfile.txt |
114-
| oc:file-parent | UUIDof:new-space |
115-
| oc:name | testfile.txt |
116-
| oc:permissions | <oc-permission> |
117-
| oc:size | 12 |
111+
And as user "Brian" the PROPFIND response should contain a mountpoint "testfile.txt" with these key and value pairs:
112+
| key | value |
113+
| oc:fileid | %file_id_pattern% |
114+
| oc:file-parent | %file_id_pattern% |
115+
| oc:name | testfile.txt |
116+
| oc:permissions | <oc-permission> |
117+
| oc:size | 12 |
118118
Examples:
119119
| space-role | oc-permission |
120120
| Manager | RDNVWZP |

0 commit comments

Comments
 (0)