removing usage of a stepdefination inside another stepdefination in PublicWebDavContext (#8813)

This commit is contained in:
nirajacharya2
2024-04-17 17:17:44 +05:45
committed by GitHub
parent 8556318809
commit ed79f3e012
2 changed files with 156 additions and 83 deletions
@@ -133,14 +133,26 @@ class PublicWebDavContext implements Context {
* *
* @param string $fileName * @param string $fileName
* @param string $publicWebDAVAPIVersion * @param string $publicWebDAVAPIVersion
* @param string $password
* *
* @return void * @return void
*/ */
public function deleteFileFromPublicShare(string $fileName, string $publicWebDAVAPIVersion, string $password = ""):void { public function thePublicDeletesFileFolderFromTheLastPublicLinkShareUsingThePublicWebdavApi(string $fileName, string $publicWebDAVAPIVersion):void {
if ($publicWebDAVAPIVersion === "old") { $response = $this->deleteFileFromPublicShare(
return; $fileName,
} $publicWebDAVAPIVersion
);
$this->featureContext->setResponse($response);
$this->featureContext->pushToLastStatusCodesArrays();
}
/**
* @param string $fileName
* @param string $publicWebDAVAPIVersion
* @param string $password
*
* @return ResponseInterface
*/
public function deleteFileFromPublicShare(string $fileName, string $publicWebDAVAPIVersion, string $password = ""):ResponseInterface {
$token = $this->featureContext->getLastCreatedPublicShareToken(); $token = $this->featureContext->getLastCreatedPublicShareToken();
$davPath = WebDavHelper::getDavPath( $davPath = WebDavHelper::getDavPath(
$token, $token,
@@ -157,16 +169,13 @@ class PublicWebDavContext implements Context {
$headers = [ $headers = [
'X-Requested-With' => 'XMLHttpRequest' 'X-Requested-With' => 'XMLHttpRequest'
]; ];
$this->featureContext->setResponse( return HttpRequestHelper::delete(
HttpRequestHelper::delete( $fullUrl,
$fullUrl, $this->featureContext->getStepLineRef(),
$this->featureContext->getStepLineRef(), $userName,
$userName, $password,
$password, $headers
$headers
)
); );
$this->featureContext->pushToLastStatusCodesArrays();
} }
/** /**
@@ -179,7 +188,13 @@ class PublicWebDavContext implements Context {
* @return void * @return void
*/ */
public function thePublicDeletesFileFromTheLastPublicShareUsingThePasswordPasswordAndOldPublicWebdavApi(string $file, string $password, string $publicWebDAVAPIVersion):void { public function thePublicDeletesFileFromTheLastPublicShareUsingThePasswordPasswordAndOldPublicWebdavApi(string $file, string $password, string $publicWebDAVAPIVersion):void {
$this->deleteFileFromPublicShare($file, $publicWebDAVAPIVersion, $password); if ($publicWebDAVAPIVersion === "old") {
return;
}
$this->featureContext->setResponse(
$this->deleteFileFromPublicShare($file, $publicWebDAVAPIVersion, $password)
);
$this->featureContext->pushToLastStatusCodesArrays();
} }
/** /**
@@ -192,10 +207,23 @@ class PublicWebDavContext implements Context {
* *
* @return void * @return void
*/ */
public function renameFileFromPublicShare(string $fileName, string $toFileName, string $publicWebDAVAPIVersion, ?string $password = ""):void { public function thePublicRenamesFileFolderFromTheLastPublicShareUsingPublicWebdavApi(string $fileName, string $toFileName, string $publicWebDAVAPIVersion, ?string $password = ""):void {
if ($publicWebDAVAPIVersion === "old") { if ($publicWebDAVAPIVersion === "old") {
return; return;
} }
$this->featureContext->setResponse($this->renameFileFromPublicShare($fileName, $toFileName, $publicWebDAVAPIVersion, $password));
$this->featureContext->pushToLastStatusCodesArrays();
}
/**
* @param string $fileName
* @param string $toFileName
* @param string $publicWebDAVAPIVersion
* @param string|null $password
*
* @return ResponseInterface
*/
public function renameFileFromPublicShare(string $fileName, string $toFileName, string $publicWebDAVAPIVersion, ?string $password = ""):ResponseInterface {
$token = $this->featureContext->getLastCreatedPublicShareToken(); $token = $this->featureContext->getLastCreatedPublicShareToken();
$davPath = WebDavHelper::getDavPath( $davPath = WebDavHelper::getDavPath(
$token, $token,
@@ -214,15 +242,13 @@ class PublicWebDavContext implements Context {
'X-Requested-With' => 'XMLHttpRequest', 'X-Requested-With' => 'XMLHttpRequest',
'Destination' => $destination 'Destination' => $destination
]; ];
$this->featureContext->setResponse( return HttpRequestHelper::sendRequest(
HttpRequestHelper::sendRequest( $fullUrl,
$fullUrl, $this->featureContext->getStepLineRef(),
$this->featureContext->getStepLineRef(), "MOVE",
"MOVE", $userName,
$userName, $password,
$password, $headers
$headers
)
); );
} }
@@ -237,7 +263,13 @@ class PublicWebDavContext implements Context {
* @return void * @return void
*/ */
public function thePublicRenamesFileFromTheLastPublicShareUsingThePasswordPasswordAndOldPublicWebdavApi(string $fileName, string $toName, string $password, string $publicWebDAVAPIVersion):void { public function thePublicRenamesFileFromTheLastPublicShareUsingThePasswordPasswordAndOldPublicWebdavApi(string $fileName, string $toName, string $password, string $publicWebDAVAPIVersion):void {
$this->renameFileFromPublicShare($fileName, $toName, $publicWebDAVAPIVersion, $password); if ($publicWebDAVAPIVersion === "old") {
return;
}
$this->featureContext->setResponse(
$this->renameFileFromPublicShare($fileName, $toName, $publicWebDAVAPIVersion, $password)
);
$this->featureContext->pushToLastStatusCodesArrays();
} }
/** /**
@@ -826,11 +858,19 @@ class PublicWebDavContext implements Context {
string $publicWebDAVAPIVersion, string $publicWebDAVAPIVersion,
string $expectedHttpCode string $expectedHttpCode
):void { ):void {
$this->theLastPublicSharedFileShouldNotBeAbleToBeDownloadedWithPassword( $response = $this->downloadPublicFileWithRange(
$publicWebDAVAPIVersion,
"", "",
$publicWebDAVAPIVersion,
$expectedHttpCode $expectedHttpCode
); );
$responseContent = $response->getBody()->getContents();
\libxml_use_internal_errors(true);
Assert::assertNotFalse(
\simplexml_load_string($responseContent),
"response body is not valid XML, maybe download did work\n" .
"response body: \n$responseContent\n"
);
$this->featureContext->theHTTPStatusCodeShouldBe($expectedHttpCode, "", $response);
} }
/** /**
@@ -845,12 +885,17 @@ class PublicWebDavContext implements Context {
string $path, string $path,
string $publicWebDAVAPIVersion string $publicWebDAVAPIVersion
):void { ):void {
$this->shouldBeAbleToDownloadRangeOfFileInsidePublicSharedFolderWithPassword( if ($publicWebDAVAPIVersion === "old") {
"", return;
}
$response = $this->downloadFileFromPublicFolder(
$path, $path,
$publicWebDAVAPIVersion, "",
"" "",
$publicWebDAVAPIVersion
); );
$this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response);
} }
/** /**
@@ -868,11 +913,11 @@ class PublicWebDavContext implements Context {
string $publicWebDAVAPIVersion, string $publicWebDAVAPIVersion,
string $expectedHttpCode = "401" string $expectedHttpCode = "401"
):void { ):void {
$this->shouldNotBeAbleToDownloadRangeOfFileInsidePublicSharedFolderWithPassword( $this->tryingToDownloadUsingWebDAVAPI(
"",
$path, $path,
$publicWebDAVAPIVersion, $publicWebDAVAPIVersion,
"", "",
"",
$expectedHttpCode $expectedHttpCode
); );
} }
@@ -891,12 +936,17 @@ class PublicWebDavContext implements Context {
string $publicWebDAVAPIVersion, string $publicWebDAVAPIVersion,
string $password string $password
):void { ):void {
$this->shouldBeAbleToDownloadRangeOfFileInsidePublicSharedFolderWithPassword( if ($publicWebDAVAPIVersion === "old") {
"", return;
}
$response = $this->downloadFileFromPublicFolder(
$path, $path,
$publicWebDAVAPIVersion, $password,
$password "",
$publicWebDAVAPIVersion
); );
$this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response);
} }
/** /**
@@ -1006,7 +1056,19 @@ class PublicWebDavContext implements Context {
string $publicWebDAVAPIVersion, string $publicWebDAVAPIVersion,
string $content string $content
):void { ):void {
$this->shouldBeAbleToDownloadFileInsidePublicSharedFolderWithPasswordAndContentShouldBe($path, $publicWebDAVAPIVersion, "", $content); if ($publicWebDAVAPIVersion === "old") {
return;
}
$response = $this->downloadFileFromPublicFolder(
$path,
"",
"",
$publicWebDAVAPIVersion
);
$this->featureContext->checkDownloadedContentMatches($content, "", $response);
$this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response);
} }
/** /**
@@ -1026,11 +1088,11 @@ class PublicWebDavContext implements Context {
string $password, string $password,
string $expectedHttpCode = "401" string $expectedHttpCode = "401"
):void { ):void {
$this->shouldNotBeAbleToDownloadRangeOfFileInsidePublicSharedFolderWithPassword( $this->tryingToDownloadUsingWebDAVAPI(
"",
$path, $path,
$publicWebDAVAPIVersion, $publicWebDAVAPIVersion,
$password, $password,
"",
$expectedHttpCode $expectedHttpCode
); );
} }
@@ -1049,11 +1111,11 @@ class PublicWebDavContext implements Context {
string $password, string $password,
string $expectedHttpCode = "401" string $expectedHttpCode = "401"
):void { ):void {
$this->shouldNotBeAbleToDownloadRangeOfFileInsidePublicSharedFolderWithPassword( $this->tryingToDownloadUsingWebDAVAPI(
"",
$path, $path,
"new", "new",
$password, $password,
"",
$expectedHttpCode, $expectedHttpCode,
true true
); );
@@ -1091,6 +1153,7 @@ class PublicWebDavContext implements Context {
/** /**
* @Then /^the public should not be able to download the range "([^"]*)" of file "([^"]*)" from inside the last public link shared folder using the (old|new) public WebDAV API with password "([^"]*)"$/ * @Then /^the public should not be able to download the range "([^"]*)" of file "([^"]*)" from inside the last public link shared folder using the (old|new) public WebDAV API with password "([^"]*)"$/
* @Then /^the public should not be able to download the range "([^"]*)" of file "([^"]*)" from inside the last public link shared folder using the (old|new) public WebDAV API without a password$/
* *
* @param string $range * @param string $range
* @param string $path * @param string $path
@@ -1104,9 +1167,30 @@ class PublicWebDavContext implements Context {
*/ */
public function shouldNotBeAbleToDownloadRangeOfFileInsidePublicSharedFolderWithPassword( public function shouldNotBeAbleToDownloadRangeOfFileInsidePublicSharedFolderWithPassword(
string $range, string $range,
string $path,
string $publicWebDAVAPIVersion,
string $password = "",
string $expectedHttpCode = "401",
bool $shareNg = false
):void {
$this->tryingToDownloadUsingWebDAVAPI($path, $publicWebDAVAPIVersion, $password, $range, $expectedHttpCode, $shareNg);
}
/**
* @param string $path
* @param string $publicWebDAVAPIVersion
* @param string $password
* @param string $range
* @param string $expectedHttpCode
* @param boolean $shareNg
*
* @return void
*/
public function tryingToDownloadUsingWebDAVAPI(
string $path, string $path,
string $publicWebDAVAPIVersion, string $publicWebDAVAPIVersion,
string $password, string $password,
string $range = "",
string $expectedHttpCode = "401", string $expectedHttpCode = "401",
bool $shareNg = false bool $shareNg = false
):void { ):void {
@@ -1149,36 +1233,18 @@ class PublicWebDavContext implements Context {
string $publicWebDAVAPIVersion, string $publicWebDAVAPIVersion,
string $content string $content
):void { ):void {
$this->shouldBeAbleToDownloadRangeOfFileInsidePublicSharedFolderWithPassword( if ($publicWebDAVAPIVersion === "old") {
$range, return;
$path, }
$publicWebDAVAPIVersion,
"",
$content
);
}
/** $response = $this->downloadFileFromPublicFolder(
* @Then /^the public should not be able to download the range "([^"]*)" of file "([^"]*)" from inside the last public link shared folder using the (old|new) public WebDAV API without a password$/
*
* @param string $range
* @param string $path
* @param string $publicWebDAVAPIVersion
*
* @return void
* @throws Exception
*/
public function shouldNotBeAbleToDownloadRangeOfFileInsidePublicSharedFolder(
string $range,
string $path,
string $publicWebDAVAPIVersion
):void {
$this->shouldNotBeAbleToDownloadRangeOfFileInsidePublicSharedFolderWithPassword(
$range,
$path, $path,
$publicWebDAVAPIVersion, '',
"" $range,
$publicWebDAVAPIVersion
); );
$this->featureContext->checkDownloadedContentMatches($content, "", $response);
$this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response);
} }
/** /**
@@ -1227,10 +1293,6 @@ class PublicWebDavContext implements Context {
string $publicWebDAVAPIVersion, string $publicWebDAVAPIVersion,
string $expectedHttpCode = null string $expectedHttpCode = null
):void { ):void {
if ($publicWebDAVAPIVersion === "old") {
return;
}
$response = $this->publicUploadContent( $response = $this->publicUploadContent(
'whateverfilefortesting.txt', 'whateverfilefortesting.txt',
'', '',
@@ -1266,7 +1328,22 @@ class PublicWebDavContext implements Context {
string $password, string $password,
string $expectedHttpCode = null string $expectedHttpCode = null
):void { ):void {
$this->publiclyUploadingShouldNotWork($publicWebDAVAPIVersion, $expectedHttpCode, $password); if ($publicWebDAVAPIVersion === "old") {
return;
}
$response = $this->publicUploadContent(
'whateverfilefortesting.txt',
$password,
'test',
false,
[],
$publicWebDAVAPIVersion
);
Assert::assertGreaterThanOrEqual(
$expectedHttpCode,
$response->getStatusCode(),
"upload should have failed but passed with code " . $response->getStatusCode()
);
} }
/** /**
@@ -1355,21 +1432,17 @@ class PublicWebDavContext implements Context {
); );
Assert::assertTrue( Assert::assertTrue(
($response->getStatusCode() == 201), ($response->getStatusCode() === 201),
"upload should have passed but failed with code " . "upload should have passed but failed with code " .
$response->getStatusCode() $response->getStatusCode()
); );
$this->shouldBeAbleToDownloadFileInsidePublicSharedFolderWithPassword(
$path,
$publicWebDAVAPIVersion,
$password
);
$response = $this->downloadFileFromPublicFolder( $response = $this->downloadFileFromPublicFolder(
$path, $path,
$password, $password,
"", "",
$publicWebDAVAPIVersion $publicWebDAVAPIVersion
); );
$this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response);
$this->featureContext->checkDownloadedContentMatches($content, "", $response); $this->featureContext->checkDownloadedContentMatches($content, "", $response);
} }
@@ -244,8 +244,8 @@ Feature: update a public link share
| password | %public% | | password | %public% |
And user "Alice" has updated the last public link share with And user "Alice" has updated the last public link share with
| permissions | read | | permissions | read |
And the public deletes file "CHILD/child.txt" from the last public link share using the password "%public%" and new public WebDAV API When the public deletes file "CHILD/child.txt" from the last public link share using the password "%public%" and new public WebDAV API
And the HTTP status code of responses on all endpoints should be "403" Then the HTTP status code of responses on all endpoints should be "403"
And as "Alice" file "PARENT/CHILD/child.txt" should exist And as "Alice" file "PARENT/CHILD/child.txt" should exist
Examples: Examples:
| ocs-api-version | | ocs-api-version |