Skip to content

Commit 732f2b2

Browse files
committed
test: rename PROPFIND response check steps
test: fix tests
1 parent 0892258 commit 732f2b2

File tree

15 files changed

+124
-108
lines changed

15 files changed

+124
-108
lines changed

tests/acceptance/TestHelpers/CollaborationHelper.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
* A helper class for managing wopi requests
3030
*/
3131
class CollaborationHelper {
32-
3332
/**
3433
* @param string $fileId
3534
* @param string $app

tests/acceptance/TestHelpers/GraphHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public static function getFederatedUserRegex(): string {
132132
*
133133
* @return string regex pattern
134134
*/
135-
public static function sanitizeRegexPattern(string $pattern): string {
135+
public static function jsonSchemaRegexToPureRegex(string $pattern): string {
136136
$pattern = \str_replace("\\\\", "\\", $pattern);
137137
$pattern = \str_replace("/", "\/", $pattern);
138138
$pattern = \preg_replace('/^\^/', '', $pattern);

tests/acceptance/TestHelpers/HttpRequestHelper.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,4 +665,22 @@ public static function getRequestTimeout(): int {
665665
public static function getJsonDecodedResponseBodyContent(ResponseInterface $response): mixed {
666666
return json_decode($response->getBody()->getContents(), null, 512, JSON_THROW_ON_ERROR);
667667
}
668+
669+
/**
670+
* @return bool
671+
*/
672+
public static function sendScenarioLineReferencesInXRequestId(): bool {
673+
return (\getenv("SEND_SCENARIO_LINE_REFERENCES") === "true");
674+
}
675+
676+
/**
677+
* @return bool
678+
*/
679+
public static function getXRequestIdRegex(): string {
680+
if (self::sendScenarioLineReferencesInXRequestId()) {
681+
return '/^[a-zA-Z]+\/[a-zA-Z]+\.feature:\d+(-\d+)?$/';
682+
}
683+
$host = gethostname();
684+
return "/^$host\/.*$/";
685+
}
668686
}

tests/acceptance/bootstrap/FeatureContext.php

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,6 @@ class FeatureContext extends BehatVariablesContext {
145145
* in the apiComments suite.
146146
*/
147147
private string $stepLineRef = '';
148-
private bool $sendStepLineRef = false;
149-
private bool $sendStepLineRefHasBeenChecked = false;
150148

151149
/**
152150
* @var boolean true if TEST_SERVER_FED_URL is defined
@@ -416,17 +414,6 @@ public function isTestingWithLdap(): bool {
416414
return (\getenv("TEST_WITH_LDAP") === "true");
417415
}
418416

419-
/**
420-
* @return bool
421-
*/
422-
public function sendScenarioLineReferencesInXRequestId(): ?bool {
423-
if ($this->sendStepLineRefHasBeenChecked === false) {
424-
$this->sendStepLineRef = (\getenv("SEND_SCENARIO_LINE_REFERENCES") === "true");
425-
$this->sendStepLineRefHasBeenChecked = true;
426-
}
427-
return $this->sendStepLineRef;
428-
}
429-
430417
/**
431418
* @return bool
432419
*/
@@ -880,7 +867,7 @@ public function getRemoteBaseUrlWithoutScheme(): string {
880867
* @return string
881868
*/
882869
public function getStepLineRef(): string {
883-
if (!$this->sendStepLineRef) {
870+
if (!HttpRequestHelper::sendScenarioLineReferencesInXRequestId()) {
884871
return '';
885872
}
886873

@@ -2435,6 +2422,14 @@ public function substituteInLineCodes(
24352422
"getUUIDv4Regex"
24362423
],
24372424
"parameter" => []
2425+
],
2426+
[
2427+
"code" => "%request_id_pattern%",
2428+
"function" => [
2429+
__NAMESPACE__ . '\TestHelpers\HttpRequestHelper',
2430+
"getXRequestIdRegex"
2431+
],
2432+
"parameter" => []
24382433
]
24392434
];
24402435
if ($user !== null) {
@@ -2522,11 +2517,15 @@ public function substituteInLineCodes(
25222517
$substitution["function"],
25232518
$substitution["parameter"]
25242519
);
2525-
foreach ($functions as $function => $parameters) {
2526-
$replacement = \call_user_func_array(
2527-
$function,
2528-
\array_merge([$replacement], $parameters)
2529-
);
2520+
2521+
// do not run functions on regex patterns
2522+
if (!\str_ends_with($value, "_pattern%")) {
2523+
foreach ($functions as $function => $parameters) {
2524+
$replacement = \call_user_func_array(
2525+
$function,
2526+
\array_merge([$replacement], $parameters)
2527+
);
2528+
}
25302529
}
25312530
$value = \str_replace(
25322531
$substitution["code"],
@@ -2644,7 +2643,7 @@ public function before(BeforeScenarioScope $scope): void {
26442643
$environment->registerContext($this->spacesContext);
26452644
}
26462645

2647-
if ($this->sendScenarioLineReferencesInXRequestId()) {
2646+
if (HttpRequestHelper::sendScenarioLineReferencesInXRequestId()) {
26482647
$this->scenarioString = $suiteName . '/' . $featureFileName . ':' . $scenarioLine;
26492648
} else {
26502649
$this->scenarioString = '';
@@ -2678,7 +2677,7 @@ public function before(BeforeScenarioScope $scope): void {
26782677
* @return void
26792678
*/
26802679
public function beforeEachStep(BeforeStepScope $scope): void {
2681-
if ($this->sendScenarioLineReferencesInXRequestId()) {
2680+
if (HttpRequestHelper::sendScenarioLineReferencesInXRequestId()) {
26822681
$this->stepLineRef = $this->scenarioString . '-' . $scope->getStep()->getLine();
26832682
} else {
26842683
$this->stepLineRef = '';

tests/acceptance/bootstrap/SpacesContext.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3775,7 +3775,7 @@ public function sendPropfindRequestToSpace(string $user, string $spaceName, ?str
37753775
if ($resource === '' || $resource === '/') {
37763776
$resource = $spaceName;
37773777
} else {
3778-
$resource = $spaceName . '/' . $resource;
3778+
$resource = "$spaceName/$resource";
37793779
}
37803780
}
37813781

@@ -3795,44 +3795,44 @@ public function sendPropfindRequestToSpace(string $user, string $spaceName, ?str
37953795
}
37963796

37973797
/**
3798-
* @Then /^as user "([^"]*)" the (PROPFIND|REPORT) response should contain a (mountpoint|space) "([^"]*)" with these key and value pairs:$/
3798+
* @Then /^as user "([^"]*)" the (PROPFIND|REPORT) response should contain a (resource|space) "([^"]*)" with these key and value pairs:$/
37993799
*
38003800
* @param string $user
38013801
* @param string $method # method should be either PROPFIND or REPORT
3802-
* @param string $type # type should be either mountpoint or space
3803-
* @param string $mountPoint
3802+
* @param string $type # type should be either resource or space
3803+
* @param string $resource
38043804
* @param TableNode $table
38053805
*
38063806
* @return void
38073807
* @throws GuzzleException
38083808
* @throws JsonException
38093809
*/
3810-
public function asUsertheXMLResponseShouldContainMountpointWithTheseKeyAndValuePair(string $user, string $method, string $type, string $mountPoint, TableNode $table): void {
3810+
public function asUsertheXMLResponseShouldContainMountpointWithTheseKeyAndValuePair(string $user, string $method, string $type, string $resource, TableNode $table): void {
38113811
$this->featureContext->verifyTableNodeColumns($table, ['key', 'value']);
38123812
if ($this->featureContext->getDavPathVersion() === WebDavHelper::DAV_VERSION_SPACES && $type === 'space') {
3813-
$space = $this->getSpaceByName($user, $mountPoint);
3814-
$mountPoint = $space['id'];
3813+
$space = $this->getSpaceByName($user, $resource);
3814+
$resource = $space['id'];
38153815
} else {
3816-
$mountPoint = \rawurlencode($mountPoint);
3816+
$resource = \rawurlencode($resource);
38173817
}
3818-
$this->theXMLResponseShouldContain($mountPoint, $table);
3818+
$this->theXMLResponseShouldContain($resource, $table);
38193819
}
38203820

38213821
/**
3822-
* @param string $spaceNameOrMountPoint # an entity inside a space, or the space name itself
3822+
* @param string $resource
38233823
* @param TableNode $table
38243824
*
38253825
* @return void
38263826
* @throws GuzzleException
38273827
* @throws JsonException
38283828
*/
3829-
public function theXMLResponseShouldContain(string $spaceNameOrMountPoint, TableNode $table): void {
3829+
public function theXMLResponseShouldContain(string $resource, TableNode $table): void {
38303830
$xmlResponse = $this->featureContext->getResponseXml();
3831-
$hrefs = array_map(fn($href) => $href->__toString(), $xmlResponse->xpath("//d:response/d:href"));
3831+
$hrefs = array_map(fn ($href) => $href->__toString(), $xmlResponse->xpath("//d:response/d:href"));
38323832

38333833
$currentHref = '';
38343834
foreach ($hrefs as $href) {
3835-
if (\str_ends_with(\rtrim($href, "/"), "/$spaceNameOrMountPoint")) {
3835+
if (\str_ends_with(\rtrim($href, "/"), "/$resource")) {
38363836
$currentHref = $href;
38373837
break;
38383838
}
@@ -3851,15 +3851,15 @@ public function theXMLResponseShouldContain(string $spaceNameOrMountPoint, Table
38513851

38523852
switch ($itemToFind) {
38533853
case "oc:fileid":
3854-
$expectedValue = GraphHelper::sanitizeRegexPattern($expectedValue);
3854+
$expectedValue = GraphHelper::jsonSchemaRegexToPureRegex($expectedValue);
38553855
Assert::assertRegExp($expectedValue, $actualValue, 'wrong "fileid" in the response');
38563856
break;
38573857
case "oc:file-parent":
3858-
$expectedValue = GraphHelper::sanitizeRegexPattern($expectedValue);
3858+
$expectedValue = GraphHelper::jsonSchemaRegexToPureRegex($expectedValue);
38593859
Assert::assertRegExp($expectedValue, $actualValue, 'wrong "file-parent" in the response');
38603860
break;
38613861
case "oc:privatelink":
3862-
$expectedValue = GraphHelper::sanitizeRegexPattern($expectedValue);
3862+
$expectedValue = GraphHelper::jsonSchemaRegexToPureRegex($expectedValue);
38633863
Assert::assertRegExp($expectedValue, $actualValue, 'wrong "privatelink" in the response');
38643864
break;
38653865
case "oc:tags":
@@ -3871,7 +3871,7 @@ public function theXMLResponseShouldContain(string $spaceNameOrMountPoint, Table
38713871

38723872
$actualTags = \explode(",", $actualValue);
38733873
\sort($actualTags);
3874-
$actualTags = \implode(",", $actualValue);
3874+
$actualTags = \implode(",", $actualTags);
38753875
Assert::assertEquals($expectedTags, $actualTags, "wrong '$itemToFind' in the response");
38763876
break;
38773877
case "d:lockdiscovery/d:activelock/d:timeout":
@@ -3887,7 +3887,7 @@ public function theXMLResponseShouldContain(string $spaceNameOrMountPoint, Table
38873887
}
38883888
break;
38893889
case "oc:remote-item-id":
3890-
$expectedValue = GraphHelper::sanitizeRegexPattern($expectedValue);
3890+
$expectedValue = GraphHelper::jsonSchemaRegexToPureRegex($expectedValue);
38913891
Assert::assertRegExp($expectedValue, $actualValue, 'wrong "remote-item-id" in the response');
38923892
break;
38933893
default:

tests/acceptance/features/apiContract/copy.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Feature: Copy test
2121
| Origin | %base_url% |
2222
Then the HTTP status code should be "201"
2323
And the following headers should match these regular expressions
24-
| Oc-Fileid | /^[a-f0-9!\$\-]{110}$/ |
25-
| Access-Control-Allow-Origin | /^%base_url%$/ |
26-
| X-Request-Id | /^[a-zA-Z]+\/[a-zA-Z]+\.feature:\d+(-\d+)?$/ |
24+
| Oc-Fileid | /^[a-f0-9!\$\-]{110}$/ |
25+
| Access-Control-Allow-Origin | /^%base_url%$/ |
26+
| X-Request-Id | %request_id_pattern% |
2727

tests/acceptance/features/apiContract/propfind.feature

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Feature: Propfind test
1818
When user "Alice" sends PROPFIND request to space "new-space" with depth "0" using the WebDAV API
1919
Then the HTTP status code should be "207"
2020
And the following headers should match these regular expressions
21-
| X-Request-Id | /^[a-zA-Z]+\/[a-zA-Z]+\.feature:\d+(-\d+)?$/ |
21+
| X-Request-Id | %request_id_pattern% |
2222
And as user "Alice" the PROPFIND response should contain a space "new-space" with these key and value pairs:
2323
| key | value |
2424
| oc:fileid | %file_id_pattern% |
@@ -38,15 +38,15 @@ Feature: Propfind test
3838
When user "Brian" sends PROPFIND request to space "new-space" with depth "0" using the WebDAV API
3939
Then the HTTP status code should be "207"
4040
And the following headers should match these regular expressions
41-
| X-Request-Id | /^[a-zA-Z]+\/[a-zA-Z]+\.feature:\d+(-\d+)?$/ |
41+
| X-Request-Id | %request_id_pattern% |
4242
And as user "Brian" the PROPFIND response should contain a space "new-space" with these key and value pairs:
4343
| key | value |
4444
| oc:fileid | %file_id_pattern% |
4545
| oc:name | new-space |
4646
| oc:permissions | <oc-permission> |
4747
| oc:privatelink | %base_url%/f/[0-9a-z-$%]+ |
4848
| oc:size | 12 |
49-
Examples:
49+
Examples:
5050
| space-role | oc-permission |
5151
| Manager | RDNVCKZP |
5252
| Space Editor | DNVCK |
@@ -62,7 +62,7 @@ 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 as user "Brian" the PROPFIND response should contain a mountpoint "folderMain" with these key and value pairs:
65+
And as user "Brian" the PROPFIND response should contain a resource "folderMain" with these key and value pairs:
6666
| key | value |
6767
| oc:fileid | %file_id_pattern% |
6868
| oc:file-parent | %file_id_pattern% |
@@ -85,7 +85,7 @@ 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 as user "Brian" the PROPFIND response should contain a mountpoint "subFolder2" with these key and value pairs:
88+
And as user "Brian" the PROPFIND response should contain a resource "subFolder2" with these key and value pairs:
8989
| key | value |
9090
| oc:fileid | %file_id_pattern% |
9191
| oc:file-parent | %file_id_pattern% |
@@ -108,7 +108,7 @@ 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 as user "Brian" the PROPFIND response should contain a mountpoint "testfile.txt" with these key and value pairs:
111+
And as user "Brian" the PROPFIND response should contain a resource "testfile.txt" with these key and value pairs:
112112
| key | value |
113113
| oc:fileid | %file_id_pattern% |
114114
| oc:file-parent | %file_id_pattern% |

tests/acceptance/features/apiContract/sharesReport.feature

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ Feature: REPORT request to Shares space
2525
When user "Brian" searches for "SubFolder1" using the WebDAV API
2626
Then the HTTP status code should be "207"
2727
And the following headers should match these regular expressions
28-
| X-Request-Id | /^[a-zA-Z]+\/[a-zA-Z]+\.feature:\d+(-\d+)?$/ |
29-
And as user "Brian" the REPORT response should contain a mountpoint "SubFolder1" with these key and value pairs:
28+
| X-Request-Id | %request_id_pattern% |
29+
And as user "Brian" the REPORT response should contain a resource "SubFolder1" with these key and value pairs:
3030
| key | value |
3131
| oc:fileid | %file_id_pattern% |
3232
| oc:file-parent | %file_id_pattern% |
@@ -47,8 +47,8 @@ Feature: REPORT request to Shares space
4747
When user "Brian" searches for "frodo.txt" using the WebDAV API
4848
Then the HTTP status code should be "207"
4949
And the following headers should match these regular expressions
50-
| X-Request-Id | /^[a-zA-Z]+\/[a-zA-Z]+\.feature:\d+(-\d+)?$/ |
51-
And as user "Brian" the REPORT response should contain a mountpoint "frodo.txt" with these key and value pairs:
50+
| X-Request-Id | %request_id_pattern% |
51+
And as user "Brian" the REPORT response should contain a resource "frodo.txt" with these key and value pairs:
5252
| key | value |
5353
| oc:fileid | %file_id_pattern% |
5454
| oc:file-parent | %file_id_pattern% |
@@ -77,7 +77,7 @@ Feature: REPORT request to Shares space
7777
When user "Brian" searches for "folderToBrian" using the WebDAV API
7878
Then the HTTP status code should be "207"
7979
And the following headers should match these regular expressions
80-
| X-Request-Id | /^[a-zA-Z]+\/[a-zA-Z]+\.feature:\d+(-\d+)?$/ |
80+
| X-Request-Id | %request_id_pattern% |
8181
And the search result should contain "0" entries
8282
Examples:
8383
| dav-path-version |
@@ -99,8 +99,8 @@ Feature: REPORT request to Shares space
9999
When user "Brian" searches for "secureFolder" using the WebDAV API
100100
Then the HTTP status code should be "207"
101101
And the following headers should match these regular expressions
102-
| X-Request-Id | /^[a-zA-Z]+\/[a-zA-Z]+\.feature:\d+(-\d+)?$/ |
103-
And as user "Brian" the REPORT response should contain a mountpoint "secureFolder" with these key and value pairs:
102+
| X-Request-Id | %request_id_pattern% |
103+
And as user "Brian" the REPORT response should contain a resource "secureFolder" with these key and value pairs:
104104
| key | value |
105105
| oc:shareroot | /secureFolder |
106106
| oc:name | secureFolder |
@@ -110,9 +110,9 @@ Feature: REPORT request to Shares space
110110
| oc:remote-item-id | %file_id_pattern% |
111111
When user "Brian" searches for "secure.txt" using the WebDAV API
112112
And the following headers should match these regular expressions
113-
| X-Request-Id | /^[a-zA-Z]+\/[a-zA-Z]+\.feature:\d+(-\d+)?$/ |
113+
| X-Request-Id | %request_id_pattern% |
114114
Then the HTTP status code should be "207"
115-
And as user "Brian" the REPORT response should contain a mountpoint "secure.txt" with these key and value pairs:
115+
And as user "Brian" the REPORT response should contain a resource "secure.txt" with these key and value pairs:
116116
| key | value |
117117
| oc:shareroot | /secureFolder |
118118
| oc:name | secure.txt |
@@ -139,8 +139,8 @@ Feature: REPORT request to Shares space
139139
When user "Brian" searches for "secure.txt" using the WebDAV API
140140
Then the HTTP status code should be "207"
141141
And the following headers should match these regular expressions
142-
| X-Request-Id | /^[a-zA-Z]+\/[a-zA-Z]+\.feature:\d+(-\d+)?$/ |
143-
And as user "Brian" the REPORT response should contain a mountpoint "secure.txt" with these key and value pairs:
142+
| X-Request-Id | %request_id_pattern% |
143+
And as user "Brian" the REPORT response should contain a resource "secure.txt" with these key and value pairs:
144144
| key | value |
145145
| oc:shareroot | /secure.txt |
146146
| oc:name | secure.txt |

0 commit comments

Comments
 (0)