2022-12-21 17:22:22 +05:45
<? php declare ( strict_types = 1 );
/**
* ownCloud
*
* @author Artur Neumann <artur@jankaritech.com>
* @copyright Copyright (c) 2018, ownCloud GmbH
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License,
* as published by the Free Software Foundation;
* either version 3 of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
use Behat\Behat\Context\Context ;
use Behat\Behat\Hook\Scope\BeforeScenarioScope ;
2023-05-02 17:25:56 +05:45
use GuzzleHttp\Exception\GuzzleException ;
2022-12-21 17:22:22 +05:45
use PHPUnit\Framework\Assert ;
2024-10-08 12:26:40 +05:45
use Psr\Http\Message\ResponseInterface ;
2022-12-21 17:22:22 +05:45
use TestHelpers\HttpRequestHelper ;
use TestHelpers\WebDavHelper ;
2024-10-08 12:26:40 +05:45
use TestHelpers\BehatHelper ;
2022-12-21 17:22:22 +05:45
require_once 'bootstrap.php' ;
/**
* context file for steps that execute actions as "the public".
*/
class PublicWebDavContext implements Context {
2023-05-02 17:25:56 +05:45
private FeatureContext $featureContext ;
2022-12-21 17:22:22 +05:45
/**
* @param string $range ignore if empty
* @param string|null $password
*
2023-10-13 16:59:43 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
2024-12-24 09:30:42 +05:45
public function downloadPublicFileWithRange ( string $range , ? string $password = "" ) : ResponseInterface {
2024-11-11 14:28:23 +05:45
// In this case a single file has been shared as a public link.
// Even if that file is somewhere down inside a folder(s), when
// accessing it as a public link using the public webDAV API
// the client needs to provide the public link share token followed
// by just the name of the file - not the full path.
$fullPath = ( string ) $this -> featureContext -> getLastCreatedPublicShare () -> path ;
$fullPathParts = \explode ( "/" , $fullPath );
$path = \end ( $fullPathParts );
2023-10-13 16:59:43 +05:45
return $this -> downloadFileFromPublicFolder (
2022-12-21 17:22:22 +05:45
$path ,
$password ,
2025-06-19 15:34:02 +05:45
$range ,
2022-12-21 17:22:22 +05:45
);
}
/**
2024-11-11 14:28:23 +05:45
* @When /^the public downloads the last public link shared file using the public WebDAV API$/
* @When /^the public tries to download the last public link shared file using the public WebDAV API$/
2022-12-21 17:22:22 +05:45
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function downloadPublicFile () : void {
2024-11-11 14:28:23 +05:45
$response = $this -> downloadPublicFileWithRange ( "" );
2023-10-13 16:59:43 +05:45
$this -> featureContext -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
}
/**
2024-11-11 14:28:23 +05:45
* @When /^the public downloads the last public link shared file with password "([^"]*)" using the public WebDAV API$/
* @When /^the public tries to download the last public link shared file with password "([^"]*)" using the public WebDAV API$/
2022-12-21 17:22:22 +05:45
*
* @param string $password
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function downloadPublicFileWithPassword ( string $password ) : void {
2024-11-11 14:28:23 +05:45
$response = $this -> downloadPublicFileWithRange ( "" , $password );
2023-10-13 16:59:43 +05:45
$this -> featureContext -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
}
2024-02-19 16:47:19 +05:45
/**
2024-11-11 14:28:23 +05:45
* @When /^user "([^"]*)" tries to download file "([^"]*)" from the last public link using own basic auth and public WebDAV API$/
2024-02-19 16:47:19 +05:45
*
* @param string $user
* @param string $path
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function userTriesToDownloadFileFromPublicLinkUsingBasicAuthAndPublicWebdav (
string $user ,
2025-06-19 15:34:02 +05:45
string $path ,
2024-12-24 09:30:42 +05:45
) : void {
2024-02-19 16:47:19 +05:45
$response = $this -> downloadFromPublicLinkAsUser ( $path , $user );
$this -> featureContext -> setResponse ( $response );
}
2022-12-21 17:22:22 +05:45
/**
2024-11-11 14:28:23 +05:45
* @When /^the public deletes (?:file|folder|entry) "([^"]*)" from the last public link share using the public WebDAV API$/
2022-12-21 17:22:22 +05:45
*
* @param string $fileName
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function thePublicDeletesFileFolderFromTheLastPublicLinkShareUsingThePublicWebdavApi (
2025-06-19 15:34:02 +05:45
string $fileName ,
2024-12-24 09:30:42 +05:45
) : void {
2024-04-17 17:17:44 +05:45
$response = $this -> deleteFileFromPublicShare (
2025-06-19 15:34:02 +05:45
$fileName ,
2024-04-17 17:17:44 +05:45
);
$this -> featureContext -> setResponse ( $response );
$this -> featureContext -> pushToLastStatusCodesArrays ();
}
/**
* @param string $fileName
* @param string $password
*
* @return ResponseInterface
*/
2024-09-17 17:11:20 +05:45
public function deleteFileFromPublicShare ( string $fileName , string $password = "" ) : ResponseInterface {
2024-12-24 09:30:42 +05:45
$token = ( $this -> featureContext -> isUsingSharingNG ())
? $this -> featureContext -> shareNgGetLastCreatedLinkShareToken ()
: $this -> featureContext -> getLastCreatedPublicShareToken ();
2022-12-21 17:22:22 +05:45
$davPath = WebDavHelper :: getDavPath (
2024-11-11 14:28:23 +05:45
WebDavHelper :: DAV_VERSION_NEW ,
2022-12-21 17:22:22 +05:45
$token ,
2025-06-19 15:34:02 +05:45
"public-files" ,
2022-12-21 17:22:22 +05:45
);
2023-11-13 23:37:12 +01:00
$password = $this -> featureContext -> getActualPassword ( $password );
2024-09-17 17:11:20 +05:45
$fullUrl = $this -> featureContext -> getBaseUrl () . "/ $davPath / $fileName " ;
2022-12-21 17:22:22 +05:45
$userName = $this -> getUsernameForPublicWebdavApi (
$token ,
2025-06-19 15:34:02 +05:45
$password ,
2022-12-21 17:22:22 +05:45
);
$headers = [
2025-06-19 10:46:56 +05:45
'X-Requested-With' => 'XMLHttpRequest' ,
2022-12-21 17:22:22 +05:45
];
2024-04-17 17:17:44 +05:45
return HttpRequestHelper :: delete (
$fullUrl ,
$userName ,
$password ,
2025-06-19 15:34:02 +05:45
$headers ,
2022-12-21 17:22:22 +05:45
);
}
/**
2024-10-01 12:40:07 +05:45
* @Given /^the public has deleted (?:file|folder|entry) "([^"]*)" from the last link share with password "([^"]*)" using the public WebDAV API$/
2022-12-21 17:22:22 +05:45
*
* @param string $file
* @param string $password
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function thePublicHasDeletedFileFromTheLastLinkShareWithPasswordUsingPublicWebdavApi (
string $file ,
2025-06-19 15:34:02 +05:45
string $password ,
2024-12-24 09:30:42 +05:45
) : void {
2024-10-01 12:40:07 +05:45
$response = $this -> deleteFileFromPublicShare ( $file , $password );
$this -> featureContext -> theHTTPStatusCodeShouldBe ([ 201 , 204 ], "" , $response );
}
/**
* @When /^the public deletes (?:file|folder|entry) "([^"]*)" from the last link share with password "([^"]*)" using the public WebDAV API$/
*
* @param string $file
* @param string $password
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function thePublicDeletesFileFromTheLastLinkShareWithPasswordUsingPublicWebdavApi (
string $file ,
2025-06-19 15:34:02 +05:45
string $password ,
2024-12-24 09:30:42 +05:45
) : void {
2024-04-17 17:17:44 +05:45
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> deleteFileFromPublicShare ( $file , $password ),
2024-04-17 17:17:44 +05:45
);
$this -> featureContext -> pushToLastStatusCodesArrays ();
2022-12-21 17:22:22 +05:45
}
2024-04-17 17:17:44 +05:45
/**
* @param string $fileName
* @param string $toFileName
* @param string|null $password
*
* @return ResponseInterface
*/
2024-12-24 09:30:42 +05:45
public function renameFileFromPublicShare (
string $fileName ,
string $toFileName ,
2025-06-19 15:34:02 +05:45
? string $password = "" ,
2024-12-24 09:30:42 +05:45
) : ResponseInterface {
$token = ( $this -> featureContext -> isUsingSharingNG ())
? $this -> featureContext -> shareNgGetLastCreatedLinkShareToken ()
: $this -> featureContext -> getLastCreatedPublicShareToken ();
2022-12-21 17:22:22 +05:45
$davPath = WebDavHelper :: getDavPath (
2024-11-11 14:28:23 +05:45
WebDavHelper :: DAV_VERSION_NEW ,
2022-12-21 17:22:22 +05:45
$token ,
2025-06-19 15:34:02 +05:45
"public-files" ,
2022-12-21 17:22:22 +05:45
);
2024-09-17 17:11:20 +05:45
$fullUrl = $this -> featureContext -> getBaseUrl () . "/ $davPath / $fileName " ;
2023-11-13 23:37:12 +01:00
$password = $this -> featureContext -> getActualPassword ( $password );
2024-09-17 17:11:20 +05:45
$destination = $this -> featureContext -> getBaseUrl () . "/ $davPath / $toFileName " ;
2022-12-21 17:22:22 +05:45
$userName = $this -> getUsernameForPublicWebdavApi (
$token ,
2025-06-19 15:34:02 +05:45
$password ,
2022-12-21 17:22:22 +05:45
);
$headers = [
'X-Requested-With' => 'XMLHttpRequest' ,
2025-06-19 10:46:56 +05:45
'Destination' => $destination ,
2022-12-21 17:22:22 +05:45
];
2024-04-17 17:17:44 +05:45
return HttpRequestHelper :: sendRequest (
$fullUrl ,
"MOVE" ,
$userName ,
$password ,
2025-06-19 15:34:02 +05:45
$headers ,
2022-12-21 17:22:22 +05:45
);
}
/**
2024-11-11 14:28:23 +05:45
* @When /^the public renames (?:file|folder|entry) "([^"]*)" to "([^"]*)" from the last public link share using the password "([^"]*)" and the public WebDAV API$/
2022-12-21 17:22:22 +05:45
*
* @param string $fileName
* @param string $toName
* @param string $password
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function thePublicRenamesFileFromTheLastPublicShareUsingThePasswordPasswordAndOldPublicWebdavApi (
string $fileName ,
string $toName ,
2025-06-19 15:34:02 +05:45
string $password ,
2024-12-24 09:30:42 +05:45
) : void {
2024-04-17 17:17:44 +05:45
$this -> featureContext -> setResponse (
2025-06-19 15:34:02 +05:45
$this -> renameFileFromPublicShare ( $fileName , $toName , $password ),
2024-04-17 17:17:44 +05:45
);
$this -> featureContext -> pushToLastStatusCodesArrays ();
2022-12-21 17:22:22 +05:45
}
/**
2024-11-11 14:28:23 +05:45
* @When /^the public downloads file "([^"]*)" from inside the last public link shared folder with password "([^"]*)" using the public WebDAV API$/
* @When /^the public tries to download file "([^"]*)" from inside the last public link shared folder with password "([^"]*)" using the public WebDAV API$/
2022-12-21 17:22:22 +05:45
*
* @param string $path
2023-10-13 16:59:43 +05:45
* @param string $password
2022-12-21 17:22:22 +05:45
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function publicDownloadsFileFromInsideLastPublicSharedFolderWithPassword (
string $path ,
2025-06-19 15:34:02 +05:45
string $password = "" ,
2024-12-24 09:30:42 +05:45
) : void {
2023-10-13 16:59:43 +05:45
$response = $this -> downloadFileFromPublicFolder (
2022-12-21 17:22:22 +05:45
$path ,
$password ,
"" ,
2025-06-19 15:34:02 +05:45
$this -> featureContext -> isUsingSharingNG (),
2022-12-21 17:22:22 +05:45
);
2023-10-13 16:59:43 +05:45
$this -> featureContext -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
}
/**
* @param string $path
2024-02-19 16:47:19 +05:45
* @param string $user
*
* @return ResponseInterface
*/
2024-05-14 11:54:23 +05:45
public function downloadFromPublicLinkAsUser ( string $path , string $user ) : ResponseInterface {
2024-02-19 16:47:19 +05:45
$path = \ltrim ( $path , "/" );
2024-12-24 09:30:42 +05:45
$token = ( $this -> featureContext -> isUsingSharingNG ())
? $this -> featureContext -> shareNgGetLastCreatedLinkShareToken ()
: $this -> featureContext -> getLastCreatedPublicShareToken ();
2024-02-19 16:47:19 +05:45
$davPath = WebDavHelper :: getDavPath (
2024-09-17 17:11:20 +05:45
$this -> featureContext -> getDavPathVersion (),
2024-02-19 16:47:19 +05:45
$token ,
2025-06-19 15:34:02 +05:45
"public-files" ,
2024-02-19 16:47:19 +05:45
);
$username = $this -> featureContext -> getActualUsername ( $user );
$password = $this -> featureContext -> getPasswordForUser ( $user );
2024-09-17 17:11:20 +05:45
$fullUrl = $this -> featureContext -> getBaseUrl () . "/ $davPath / $path " ;
2024-02-19 16:47:19 +05:45
return HttpRequestHelper :: get (
$fullUrl ,
$username ,
2025-06-19 15:34:02 +05:45
$password ,
2024-02-19 16:47:19 +05:45
);
}
/**
* @param string $path
2022-12-21 17:22:22 +05:45
* @param string $password
* @param string $range ignored when empty
2024-01-05 13:57:59 +05:45
* @param bool $shareNg
2022-12-21 17:22:22 +05:45
*
2023-10-13 16:59:43 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
2023-10-13 16:59:43 +05:45
public function downloadFileFromPublicFolder (
2022-12-21 17:22:22 +05:45
string $path ,
string $password ,
string $range ,
2025-06-19 15:34:02 +05:45
bool $shareNg = false ,
2024-12-24 09:30:42 +05:45
) : ResponseInterface {
2022-12-21 17:22:22 +05:45
$path = \ltrim ( $path , "/" );
$password = $this -> featureContext -> getActualPassword ( $password );
2024-01-05 13:57:59 +05:45
if ( $shareNg ) {
$token = $this -> featureContext -> shareNgGetLastCreatedLinkShareToken ();
} else {
$token = $this -> featureContext -> getLastCreatedPublicShareToken ();
}
2022-12-21 17:22:22 +05:45
$davPath = WebDavHelper :: getDavPath (
2024-11-11 14:28:23 +05:45
WebDavHelper :: DAV_VERSION_NEW ,
2022-12-21 17:22:22 +05:45
$token ,
2025-06-19 15:34:02 +05:45
"public-files" ,
2022-12-21 17:22:22 +05:45
);
2024-09-17 17:11:20 +05:45
$fullUrl = $this -> featureContext -> getBaseUrl () . "/ $davPath / $path " ;
2022-12-21 17:22:22 +05:45
$userName = $this -> getUsernameForPublicWebdavApi (
$token ,
2025-06-19 15:34:02 +05:45
$password ,
2022-12-21 17:22:22 +05:45
);
$headers = [
2025-06-19 10:46:56 +05:45
'X-Requested-With' => 'XMLHttpRequest' ,
2022-12-21 17:22:22 +05:45
];
if ( $range !== "" ) {
$headers [ 'Range' ] = $range ;
}
2023-10-13 16:59:43 +05:45
return HttpRequestHelper :: get (
2022-12-21 17:22:22 +05:45
$fullUrl ,
$userName ,
$password ,
2025-06-19 15:34:02 +05:45
$headers ,
2022-12-21 17:22:22 +05:45
);
}
/**
* @param string $source target file name
*
2023-10-13 16:59:43 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
2024-12-24 09:30:42 +05:45
public function publicUploadFile ( string $source ) : ResponseInterface {
2023-10-13 16:59:43 +05:45
return $this -> publicUploadContent (
2022-12-21 17:22:22 +05:45
\basename ( $source ),
'' ,
2025-06-19 15:34:02 +05:45
\file_get_contents ( $source ),
2022-12-21 17:22:22 +05:45
);
}
/**
*
* @param string $baseUrl URL of owncloud
* e.g. http://localhost:8080
* should include the subfolder
* if owncloud runs in a subfolder
* e.g. http://localhost:8080/owncloud-core
* @param string $source
* @param string $destination
*
2023-10-13 16:59:43 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
public function publiclyCopyingFile (
string $baseUrl ,
string $source ,
2025-06-19 15:34:02 +05:45
string $destination ,
2024-12-24 09:30:42 +05:45
) : ResponseInterface {
2024-09-17 17:11:20 +05:45
$fullSourceUrl = " $baseUrl / $source " ;
2022-12-21 17:22:22 +05:45
$fullDestUrl = WebDavHelper :: sanitizeUrl (
2025-06-19 15:34:02 +05:45
" $baseUrl / $destination " ,
2022-12-21 17:22:22 +05:45
);
$headers [ "Destination" ] = $fullDestUrl ;
2023-10-13 16:59:43 +05:45
return HttpRequestHelper :: sendRequest (
2022-12-21 17:22:22 +05:45
$fullSourceUrl ,
"COPY" ,
null ,
null ,
2025-06-19 15:34:02 +05:45
$headers ,
2022-12-21 17:22:22 +05:45
);
}
/**
2024-11-11 14:28:23 +05:45
* @When /^the public copies (?:file|folder) "([^"]*)" to "([^"]*)" using the public WebDAV API$/
2022-12-21 17:22:22 +05:45
*
* @param string $source
* @param string $destination
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function thePublicCopiesFileUsingTheWebDAVApi ( string $source , string $destination ) : void {
$token = ( $this -> featureContext -> isUsingSharingNG ())
? $this -> featureContext -> shareNgGetLastCreatedLinkShareToken ()
: $this -> featureContext -> getLastCreatedPublicShareToken ();
2022-12-21 17:22:22 +05:45
$davPath = WebDavHelper :: getDavPath (
2024-11-11 14:28:23 +05:45
WebDavHelper :: DAV_VERSION_NEW ,
2022-12-21 17:22:22 +05:45
$token ,
2025-06-19 15:34:02 +05:45
"public-files" ,
2022-12-21 17:22:22 +05:45
);
$baseUrl = $this -> featureContext -> getLocalBaseUrl () . '/' . $davPath ;
2023-10-13 16:59:43 +05:45
$response = $this -> publiclyCopyingFile (
2022-12-21 17:22:22 +05:45
$baseUrl ,
$source ,
2025-06-19 15:34:02 +05:45
$destination ,
2022-12-21 17:22:22 +05:45
);
2023-10-13 16:59:43 +05:45
$this -> featureContext -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
}
/**
* This only works with the old API, auto-rename is not supported in the new API
* auto renaming is handled on files drop folders implicitly
*
* @param string $filename target file name
* @param string $body content to upload
*
2023-10-13 16:59:43 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
2024-12-24 09:30:42 +05:45
public function publiclyUploadingContentAutoRename ( string $filename , string $body = 'test' ) : ResponseInterface {
2023-10-13 16:59:43 +05:45
return $this -> publicUploadContent ( $filename , '' , $body , true );
2022-12-21 17:22:22 +05:45
}
/**
* @When the public uploads file :filename with content :body with auto-rename mode using the old public WebDAV API
*
* @param string $filename target file name
* @param string $body content to upload
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function thePublicUploadsFileWithContentWithAutoRenameMode ( string $filename , string $body = 'test' ) : void {
2023-10-13 16:59:43 +05:45
$response = $this -> publiclyUploadingContentAutoRename ( $filename , $body );
$this -> featureContext -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
}
/**
* @Given the public has uploaded file :filename with content :body with auto-rename mode
*
* @param string $filename target file name
* @param string $body content to upload
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function thePublicHasUploadedFileWithContentWithAutoRenameMode (
string $filename ,
2025-06-19 15:34:02 +05:45
string $body = 'test' ,
2024-12-24 09:30:42 +05:45
) : void {
2023-10-13 16:59:43 +05:45
$response = $this -> publiclyUploadingContentAutoRename ( $filename , $body );
$this -> featureContext -> theHTTPStatusCodeShouldBe ([ 201 , 204 ], "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @param string $filename target file name
* @param string $password
* @param string $body content to upload
*
2023-10-13 16:59:43 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
public function publiclyUploadingContentWithPassword (
string $filename ,
string $password = '' ,
string $body = 'test' ,
2024-12-24 09:30:42 +05:45
) : ResponseInterface {
2023-10-13 16:59:43 +05:45
return $this -> publicUploadContent (
2022-12-21 17:22:22 +05:45
$filename ,
$password ,
$body ,
2023-11-13 23:37:12 +01:00
true ,
2022-12-21 17:22:22 +05:45
[],
);
}
2024-10-01 12:40:07 +05:45
/**
* @Given /^the public has uploaded file "([^"]*)" with content "([^"]*)" and password "([^"]*)" to the last link share using the public WebDAV API$/
*
* @param string $filename
* @param string $content
* @param string $password
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function thePublicHasUploadedFileWithContentAndPasswordToLastLinkShareUsingPublicWebdavApi (
string $filename ,
string $content = 'test' ,
2025-06-19 15:34:02 +05:45
string $password = '' ,
2024-12-24 09:30:42 +05:45
) : void {
2024-10-01 12:40:07 +05:45
$response = $this -> publiclyUploadingContentWithPassword (
$filename ,
$password ,
$content ,
);
$this -> featureContext -> theHTTPStatusCodeShouldBe ([ 201 , 204 ], "" , $response );
}
2022-12-21 17:22:22 +05:45
/**
2024-11-11 14:28:23 +05:45
* @When /^the public uploads file "([^"]*)" with password "([^"]*)" and content "([^"]*)" using the public WebDAV API$/
2022-12-21 17:22:22 +05:45
*
* @param string $filename target file name
2024-11-11 14:28:23 +05:45
* @param string $password
2022-12-21 17:22:22 +05:45
* @param string $body content to upload
*
* @return void
*/
public function thePublicUploadsFileWithPasswordAndContentUsingPublicWebDAVApi (
string $filename ,
2024-11-11 14:28:23 +05:45
string $password ,
string $body ,
2024-12-24 09:30:42 +05:45
) : void {
2023-10-13 16:59:43 +05:45
$response = $this -> publiclyUploadingContentWithPassword (
2022-12-21 17:22:22 +05:45
$filename ,
$password ,
2025-06-19 15:34:02 +05:45
$body ,
2022-12-21 17:22:22 +05:45
);
2023-10-13 16:59:43 +05:45
$this -> featureContext -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
}
/**
2024-11-11 14:28:23 +05:45
* @When the public overwrites file :filename with content :body using the public WebDAV API
2022-12-21 17:22:22 +05:45
*
* @param string $filename target file name
* @param string $body content to upload
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function thePublicOverwritesFileWithContentUsingWebDavApi ( string $filename , string $body ) : void {
2024-11-11 14:28:23 +05:45
$response = $this -> publicUploadContent ( $filename , '' , $body );
2023-10-13 16:59:43 +05:45
$this -> featureContext -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
}
/**
2024-11-11 14:28:23 +05:45
* @When /^the public uploads file "([^"]*)" with content "([^"]*)" using the public WebDAV API$/
2022-12-21 17:22:22 +05:45
*
* @param string $filename target file name
* @param string $body content to upload
*
* @return void
*/
public function thePublicUploadsFileWithContentUsingThePublicWebDavApi (
string $filename ,
2025-06-19 15:34:02 +05:45
string $body = 'test' ,
2024-12-24 09:30:42 +05:45
) : void {
2024-09-17 17:11:20 +05:45
$response = $this -> publicUploadContent ( $filename , '' , $body );
2023-10-13 16:59:43 +05:45
$this -> featureContext -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
$this -> featureContext -> pushToLastStatusCodesArrays ();
}
/**
* @Given the public has uploaded file :filename with content :body
*
* @param string $filename target file name
* @param string $body content to upload
*
* @return void
*/
2024-09-17 17:11:20 +05:45
public function thePublicHasUploadedFileWithContent ( string $filename , string $body ) : void {
$response = $this -> publicUploadContent ( $filename , '' , $body );
2023-10-13 16:59:43 +05:45
$this -> featureContext -> theHTTPStatusCodeShouldBe ([ 201 , 204 ], "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
2024-11-11 14:28:23 +05:45
* @Then /^the public should be able to download the last publicly shared file using the public WebDAV API with password "([^"]*)" and the content should be "([^"]*)"$/
2022-12-21 17:22:22 +05:45
*
* @param string $password
* @param string $expectedContent
*
* @return void
* @throws Exception
*/
public function checkLastPublicSharedFileWithPasswordDownload (
string $password ,
2025-06-19 15:34:02 +05:45
string $expectedContent ,
2024-12-24 09:30:42 +05:45
) : void {
2023-10-13 16:59:43 +05:45
$response = $this -> downloadPublicFileWithRange (
2022-12-21 17:22:22 +05:45
"" ,
2025-06-19 15:34:02 +05:45
$password ,
2022-12-21 17:22:22 +05:45
);
2023-10-13 16:59:43 +05:45
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
2022-12-21 17:22:22 +05:45
$this -> featureContext -> checkDownloadedContentMatches (
$expectedContent ,
2024-11-11 14:28:23 +05:45
"Checking the content of the last public shared file after downloading with the public WebDAV API" ,
2025-06-19 15:34:02 +05:45
$response ,
2022-12-21 17:22:22 +05:45
);
}
/**
2024-11-11 14:28:23 +05:45
* @Then /^the public should not be able to download file "([^"]*)" from inside the last public link shared folder using the public WebDAV API without a password$/
* @Then /^the public download of file "([^"]*)" from inside the last public link shared folder using the public WebDAV API should fail with HTTP status code "([^"]*)"$/
2022-12-21 17:22:22 +05:45
*
* @param string $path
* @param string $expectedHttpCode
*
* @return void
*/
public function shouldNotBeAbleToDownloadFileInsidePublicSharedFolder (
string $path ,
2025-06-19 15:34:02 +05:45
string $expectedHttpCode = "401" ,
2024-12-24 09:30:42 +05:45
) : void {
2024-11-11 14:28:23 +05:45
$response = $this -> downloadFileFromPublicFolder (
2022-12-21 17:22:22 +05:45
$path ,
"" ,
2024-04-17 17:17:44 +05:45
"" ,
2025-06-19 15:34:02 +05:45
$this -> featureContext -> isUsingSharingNG (),
2022-12-21 17:22:22 +05:45
);
2024-11-11 14:28:23 +05:45
$this -> featureContext -> theHTTPStatusCodeShouldBe ( $expectedHttpCode , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
2024-11-11 14:28:23 +05:45
* @Then /^the public should be able to download file "([^"]*)" from inside the last public link shared folder using the public WebDAV API with password "([^"]*)"$/
2022-12-21 17:22:22 +05:45
*
* @param string $path
* @param string $password
*
* @return void
*/
public function shouldBeAbleToDownloadFileInsidePublicSharedFolderWithPassword (
string $path ,
2025-06-19 15:34:02 +05:45
string $password ,
2024-12-24 09:30:42 +05:45
) : void {
2024-04-17 17:17:44 +05:45
$response = $this -> downloadFileFromPublicFolder (
2022-12-21 17:22:22 +05:45
$path ,
2024-04-17 17:17:44 +05:45
$password ,
"" ,
2025-06-19 15:34:02 +05:45
$this -> featureContext -> isUsingSharingNG (),
2022-12-21 17:22:22 +05:45
);
2024-04-17 17:17:44 +05:45
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
2024-11-11 14:28:23 +05:45
* @Then /^the public should be able to download file "([^"]*)" from inside the last public link shared folder using the public WebDAV API with password "([^"]*)" and the content should be "([^"]*)"$/
2022-12-21 17:22:22 +05:45
*
* @param string $path
* @param string $password
* @param string $content
*
* @return void
* @throws Exception
*/
public function shouldBeAbleToDownloadFileInsidePublicSharedFolderWithPasswordAndContentShouldBe (
string $path ,
string $password ,
2025-06-19 15:34:02 +05:45
string $content ,
2024-12-24 09:30:42 +05:45
) : void {
2023-10-13 16:59:43 +05:45
$response = $this -> downloadFileFromPublicFolder (
2022-12-21 17:22:22 +05:45
$path ,
$password ,
2023-10-13 16:59:43 +05:45
"" ,
2022-12-21 17:22:22 +05:45
);
2023-10-13 16:59:43 +05:45
$this -> featureContext -> checkDownloadedContentMatches ( $content , "" , $response );
2022-12-21 17:22:22 +05:45
2023-10-13 16:59:43 +05:45
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
2022-12-21 17:22:22 +05:45
}
2024-01-05 13:57:59 +05:45
/**
* @Then /^the public should be able to download file "([^"]*)" from the last link share with password "([^"]*)" and the content should be "([^"]*)"$/
*
* @param string $path
* @param string $password
* @param string $content
*
* @return void
* @throws Exception
*/
public function shouldBeAbleToDownloadFileInsidePublicSharedFolderWithPasswordForSharingNGAndContentShouldBe (
string $path ,
string $password ,
2025-06-19 15:34:02 +05:45
string $content ,
2024-12-24 09:30:42 +05:45
) : void {
2024-01-05 13:57:59 +05:45
$response = $this -> downloadFileFromPublicFolder (
$path ,
$password ,
"" ,
2025-06-19 15:34:02 +05:45
true ,
2024-01-05 13:57:59 +05:45
);
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
$this -> featureContext -> checkDownloadedContentMatches ( $content , "" , $response );
}
2022-12-21 17:22:22 +05:45
/**
2024-11-11 14:28:23 +05:45
* @Then /^the public should not be able to download file "([^"]*)" from inside the last public link shared folder using the public WebDAV API with password "([^"]*)"$/
* @Then /^the public download of file "([^"]*)" from inside the last public link shared folder using the public WebDAV API with password "([^"]*)" should fail with HTTP status code "([^"]*)"$/
2022-12-21 17:22:22 +05:45
*
* @param string $path
* @param string $password
* @param string $expectedHttpCode
*
* @return void
*/
public function shouldNotBeAbleToDownloadFileInsidePublicSharedFolderWithPassword (
string $path ,
string $password ,
2025-06-19 15:34:02 +05:45
string $expectedHttpCode = "401" ,
2024-12-24 09:30:42 +05:45
) : void {
2024-11-11 14:28:23 +05:45
$response = $this -> downloadFileFromPublicFolder (
2022-12-21 17:22:22 +05:45
$path ,
$password ,
2024-04-17 17:17:44 +05:45
"" ,
2025-06-19 15:34:02 +05:45
$this -> featureContext -> isUsingSharingNG (),
2022-12-21 17:22:22 +05:45
);
2024-11-11 14:28:23 +05:45
$this -> featureContext -> theHTTPStatusCodeShouldBe ( $expectedHttpCode , "" , $response );
2022-12-21 17:22:22 +05:45
}
2024-01-05 13:57:59 +05:45
/**
* @Then /^the public download of file "([^"]*)" from the last link share with password "([^"]*)" should fail with HTTP status code "([^"]*)" using shareNg$/
*
* @param string $path
* @param string $password
* @param string $expectedHttpCode
*
* @return void
*/
public function shouldNotBeAbleToDownloadFileWithPasswordForShareNg (
string $path ,
string $password ,
2025-06-19 15:34:02 +05:45
string $expectedHttpCode = "401" ,
2024-12-24 09:30:42 +05:45
) : void {
2024-04-17 17:17:44 +05:45
$this -> tryingToDownloadUsingWebDAVAPI (
2024-01-05 13:57:59 +05:45
$path ,
"new" ,
$password ,
$expectedHttpCode ,
2025-06-19 15:34:02 +05:45
true ,
2024-01-05 13:57:59 +05:45
);
}
2024-04-17 17:17:44 +05:45
/**
* @param string $path
* @param string $password
* @param string $range
* @param string $expectedHttpCode
* @param boolean $shareNg
*
* @return void
*/
public function tryingToDownloadUsingWebDAVAPI (
2022-12-21 17:22:22 +05:45
string $path ,
string $password ,
2024-04-17 17:17:44 +05:45
string $range = "" ,
2024-01-05 13:57:59 +05:45
string $expectedHttpCode = "401" ,
2025-06-19 15:34:02 +05:45
bool $shareNg = false ,
2024-12-24 09:30:42 +05:45
) : void {
2023-10-13 16:59:43 +05:45
$response = $this -> downloadFileFromPublicFolder (
2022-12-21 17:22:22 +05:45
$path ,
$password ,
$range ,
2025-06-19 15:34:02 +05:45
$shareNg ,
2022-12-21 17:22:22 +05:45
);
2024-06-10 12:43:16 +02:00
$this -> featureContext -> theHTTPStatusCodeShouldBe ( $expectedHttpCode , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
2024-11-11 14:28:23 +05:45
* @Then /^the public upload to the last publicly shared file using the public WebDAV API with password "([^"]*)" should (?:fail|pass) with HTTP status code "([^"]*)"$/
2022-12-21 17:22:22 +05:45
*
2023-11-13 23:37:12 +01:00
* @param string $password
2022-12-21 17:22:22 +05:45
* @param string $expectedHttpCode
*
* @return void
* @throws Exception
*/
public function publiclyUploadingShouldToSharedFileShouldFail (
2023-11-13 23:37:12 +01:00
string $password ,
2025-06-19 15:34:02 +05:45
string $expectedHttpCode ,
2024-12-24 09:30:42 +05:45
) : void {
2023-08-03 13:51:22 +05:45
$filename = ( string ) $this -> featureContext -> getLastCreatedPublicShare () -> file_target ;
2022-12-21 17:22:22 +05:45
2023-10-13 16:59:43 +05:45
$response = $this -> publicUploadContent (
2022-12-21 17:22:22 +05:45
$filename ,
2025-06-19 15:34:02 +05:45
$password ,
2022-12-21 17:22:22 +05:45
);
2023-10-13 16:59:43 +05:45
$this -> featureContext -> theHTTPStatusCodeShouldBe ( $expectedHttpCode , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
2024-11-11 14:28:23 +05:45
* @Then /^the public upload to the last publicly shared folder using the public WebDAV API with password "([^"]*)" should fail with HTTP status code "([^"]*)"$/
2023-11-13 23:37:12 +01:00
*
* @param string $password
* @param string|null $expectedHttpCode
*
* @return void
*/
public function publiclyUploadingWithPasswordShouldNotWork (
string $password ,
2025-06-24 11:39:50 +02:00
? string $expectedHttpCode = null ,
2024-12-24 09:30:42 +05:45
) : void {
2024-04-17 17:17:44 +05:45
$response = $this -> publicUploadContent (
'whateverfilefortesting.txt' ,
2025-06-19 15:34:02 +05:45
$password ,
2024-04-17 17:17:44 +05:45
);
Assert :: assertGreaterThanOrEqual (
$expectedHttpCode ,
$response -> getStatusCode (),
2025-06-19 15:34:02 +05:45
"upload should have failed but passed with code " . $response -> getStatusCode (),
2024-04-17 17:17:44 +05:45
);
2023-11-13 23:37:12 +01:00
}
2022-12-21 17:22:22 +05:45
/**
2024-11-11 14:28:23 +05:45
* @Then /^the public should be able to upload file "([^"]*)" into the last public link shared folder using the public WebDAV API with password "([^"]*)"$/
2022-12-21 17:22:22 +05:45
*
* @param string $filename
* @param string $password
*
* @return void
*/
public function publiclyUploadingIntoFolderWithPasswordShouldWork (
string $filename ,
2025-06-19 15:34:02 +05:45
string $password ,
2024-12-24 09:30:42 +05:45
) : void {
2023-10-13 16:59:43 +05:45
$response = $this -> publicUploadContent (
2022-12-21 17:22:22 +05:45
$filename ,
2025-06-19 15:34:02 +05:45
$password ,
2022-12-21 17:22:22 +05:45
);
2023-10-13 16:59:43 +05:45
$this -> featureContext -> theHTTPStatusCodeShouldBe ([ 201 , 204 ], "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
2024-11-11 14:28:23 +05:45
* @Then /^uploading a file with password "([^"]*)" should work using the public WebDAV API$/
2022-12-21 17:22:22 +05:45
*
* @param string $password
*
* @return void
* @throws Exception
*/
2024-12-24 09:30:42 +05:45
public function publiclyUploadingShouldWork ( string $password ) : void {
2024-11-11 14:28:23 +05:45
$path = "whateverfilefortesting-publicWebDAVAPI.txt" ;
$content = "test" ;
2022-12-21 17:22:22 +05:45
2023-10-13 16:59:43 +05:45
$response = $this -> publicUploadContent (
2022-12-21 17:22:22 +05:45
$path ,
2023-11-13 23:37:12 +01:00
$password ,
2022-12-21 17:22:22 +05:45
$content ,
);
2023-10-13 16:59:43 +05:45
2022-12-21 17:22:22 +05:45
Assert :: assertTrue (
2024-04-17 17:17:44 +05:45
( $response -> getStatusCode () === 201 ),
2022-12-21 17:22:22 +05:45
"upload should have passed but failed with code " .
2025-06-19 15:34:02 +05:45
$response -> getStatusCode (),
2022-12-21 17:22:22 +05:45
);
2023-10-13 16:59:43 +05:45
$response = $this -> downloadFileFromPublicFolder (
$path ,
2023-11-13 23:37:12 +01:00
$password ,
2025-06-19 15:34:02 +05:45
"" ,
2023-10-13 16:59:43 +05:45
);
2024-04-17 17:17:44 +05:45
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 200 , "" , $response );
2023-10-13 16:59:43 +05:45
$this -> featureContext -> checkDownloadedContentMatches ( $content , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
2024-11-11 14:28:23 +05:45
* @Then /^uploading content to a public link shared file with password "([^"]*)" should (not|)\s?work using the public WebDAV API$/
2022-12-21 17:22:22 +05:45
*
2023-11-13 23:37:12 +01:00
* @param string $password
2022-12-21 17:22:22 +05:45
* @param string $shouldOrNot (not|)
*
* @return void
* @throws Exception
*/
public function publiclyUploadingToPublicLinkSharedFileShouldWork (
2023-11-13 23:37:12 +01:00
string $password ,
2022-12-21 17:22:22 +05:45
string $shouldOrNot ,
2024-12-24 09:30:42 +05:45
) : void {
2024-11-11 14:28:23 +05:45
$content = "test" ;
2022-12-21 17:22:22 +05:45
$should = ( $shouldOrNot !== "not" );
2024-11-11 14:28:23 +05:45
$path = ( string ) $this -> featureContext -> getLastCreatedPublicShare () -> path ;
2022-12-21 17:22:22 +05:45
2023-10-13 16:59:43 +05:45
$response = $this -> publicUploadContent (
2022-12-21 17:22:22 +05:45
$path ,
2023-11-13 23:37:12 +01:00
$password ,
2025-06-19 15:34:02 +05:45
$content ,
2022-12-21 17:22:22 +05:45
);
if ( $should ) {
Assert :: assertTrue (
( $response -> getStatusCode () == 204 ),
"upload should have passed but failed with code " .
2025-06-19 15:34:02 +05:45
$response -> getStatusCode (),
2022-12-21 17:22:22 +05:45
);
2023-10-13 16:59:43 +05:45
$response = $this -> downloadPublicFileWithRange (
2022-12-21 17:22:22 +05:45
"" ,
2025-06-19 15:34:02 +05:45
$password ,
2022-12-21 17:22:22 +05:45
);
$this -> featureContext -> checkDownloadedContentMatches (
$content ,
2024-11-11 14:28:23 +05:45
"Checking the content of the last public shared file after downloading with the public WebDAV API" ,
2025-06-19 15:34:02 +05:45
$response ,
2022-12-21 17:22:22 +05:45
);
} else {
$expectedCode = 403 ;
Assert :: assertTrue (
( $response -> getStatusCode () == $expectedCode ),
"upload should have failed with HTTP status $expectedCode but passed with code " .
2025-06-19 15:34:02 +05:45
$response -> getStatusCode (),
2022-12-21 17:22:22 +05:45
);
}
}
2024-04-30 12:26:21 +05:45
/**
2024-11-11 14:28:23 +05:45
* @When the public uploads file :source to :destination inside last link shared folder using the public WebDAV API
2024-04-30 12:26:21 +05:45
*
* @param string $source
* @param string $destination
*
* @return void
*/
2024-11-11 14:28:23 +05:45
public function thePublicUploadsFileToInsideLastLinkSharedFolderUsingThePublicWebdavApi (
2024-04-30 12:26:21 +05:45
string $source ,
string $destination ,
2024-12-24 09:30:42 +05:45
) : void {
2024-04-30 12:26:21 +05:45
$content = \file_get_contents (
2025-06-19 15:34:02 +05:45
$this -> featureContext -> acceptanceTestsDirLocation () . $source ,
2024-04-30 12:26:21 +05:45
);
$response = $this -> publicUploadContent (
$destination ,
'' ,
2025-06-19 15:34:02 +05:45
$content ,
2024-04-30 12:26:21 +05:45
);
$this -> featureContext -> setResponse ( $response );
}
/**
*
2024-11-11 14:28:23 +05:45
* @When the public uploads file :source to :destination inside last link shared folder with password :password using the public WebDAV API
2024-04-30 12:26:21 +05:45
*
* @param string $source
* @param string $destination
* @param string $password
*
* @return void
*/
2024-11-11 14:28:23 +05:45
public function thePublicUploadsFileToInsideLastLinkSharedFolderWithPasswordUsingThePublicWebdavApi (
2024-04-30 12:26:21 +05:45
string $source ,
string $destination ,
2025-06-19 15:34:02 +05:45
string $password ,
2024-12-24 09:30:42 +05:45
) : void {
2024-04-30 12:26:21 +05:45
$content = \file_get_contents (
2025-06-19 15:34:02 +05:45
$this -> featureContext -> acceptanceTestsDirLocation () . $source ,
2024-04-30 12:26:21 +05:45
);
$response = $this -> publicUploadContent (
$destination ,
$password ,
2025-06-19 15:34:02 +05:45
$content ,
2024-04-30 12:26:21 +05:45
);
$this -> featureContext -> setResponse ( $response );
}
2022-12-21 17:22:22 +05:45
/**
2024-11-11 14:28:23 +05:45
* @When the public uploads file :fileName to the last public link shared folder with password :password with mtime :mtime using the public WebDAV API
2022-12-21 17:22:22 +05:45
*
2024-05-30 17:07:09 +05:45
* @param string $fileName
* @param string $password
* @param string $mtime
2022-12-21 17:22:22 +05:45
*
* @return void
* @throws Exception
*/
public function thePublicUploadsFileToLastSharedFolderWithMtimeUsingTheWebdavApi (
string $fileName ,
2023-11-13 23:37:12 +01:00
string $password ,
2025-06-19 15:34:02 +05:45
string $mtime ,
2024-12-24 09:30:42 +05:45
) : void {
2022-12-21 17:22:22 +05:45
$mtime = new DateTime ( $mtime );
$mtime = $mtime -> format ( 'U' );
2023-10-13 16:59:43 +05:45
$response = $this -> publicUploadContent (
2022-12-21 17:22:22 +05:45
$fileName ,
2023-11-13 23:37:12 +01:00
$password ,
2022-12-21 17:22:22 +05:45
'test' ,
false ,
2025-06-19 15:34:02 +05:45
[ "X-OC-Mtime" => $mtime ],
2022-12-21 17:22:22 +05:45
);
2023-10-13 16:59:43 +05:45
$this -> featureContext -> setResponse ( $response );
2022-12-21 17:22:22 +05:45
}
/**
* @param string $destination
* @param string $password
*
2023-10-13 16:59:43 +05:45
* @return ResponseInterface
2022-12-21 17:22:22 +05:45
*/
public function publicCreatesFolderUsingPassword (
string $destination ,
2025-06-19 15:34:02 +05:45
string $password ,
2024-12-24 09:30:42 +05:45
) : ResponseInterface {
$token = ( $this -> featureContext -> isUsingSharingNG ())
? $this -> featureContext -> shareNgGetLastCreatedLinkShareToken ()
: $this -> featureContext -> getLastCreatedPublicShareToken ();
2022-12-21 17:22:22 +05:45
$davPath = WebDavHelper :: getDavPath (
2024-09-17 17:11:20 +05:45
$this -> featureContext -> getDavPathVersion (),
2022-12-21 17:22:22 +05:45
$token ,
2025-06-19 15:34:02 +05:45
"public-files" ,
2022-12-21 17:22:22 +05:45
);
2024-09-17 17:11:20 +05:45
$url = $this -> featureContext -> getBaseUrl () . "/ $davPath /" ;
2022-12-21 17:22:22 +05:45
$password = $this -> featureContext -> getActualPassword ( $password );
$userName = $this -> getUsernameForPublicWebdavApi (
$token ,
2025-06-19 15:34:02 +05:45
$password ,
2022-12-21 17:22:22 +05:45
);
$foldername = \implode (
'/' ,
2025-06-19 15:34:02 +05:45
\array_map ( 'rawurlencode' , \explode ( '/' , $destination )),
2022-12-21 17:22:22 +05:45
);
$url .= \ltrim ( $foldername , '/' );
2023-10-13 16:59:43 +05:45
return HttpRequestHelper :: sendRequest (
$url ,
'MKCOL' ,
$userName ,
2025-06-19 15:34:02 +05:45
$password ,
2022-12-21 17:22:22 +05:45
);
}
/**
2024-11-11 14:28:23 +05:45
* @When the public creates folder :destination using the public WebDAV API
2022-12-21 17:22:22 +05:45
*
* @param String $destination
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function publicCreatesFolder ( string $destination ) : void {
2023-10-13 16:59:43 +05:45
$this -> featureContext -> setResponse ( $this -> publicCreatesFolderUsingPassword ( $destination , '' ));
2022-12-21 17:22:22 +05:45
}
/**
* @Then /^the public should be able to create folder "([^"]*)" in the last public link shared folder using the new public WebDAV API with password "([^"]*)"$/
*
* @param string $foldername
* @param string $password
*
* @return void
*/
public function publicShouldBeAbleToCreateFolderWithPassword (
string $foldername ,
2025-06-19 15:34:02 +05:45
string $password ,
2024-12-24 09:30:42 +05:45
) : void {
2023-10-13 16:59:43 +05:45
$response = $this -> publicCreatesFolderUsingPassword ( $foldername , $password );
$this -> featureContext -> theHTTPStatusCodeShouldBe ( 201 , "" , $response );
2022-12-21 17:22:22 +05:45
}
/**
* @Then /^the public creation of folder "([^"]*)" in the last public link shared folder using the new public WebDAV API with password "([^"]*)" should fail with HTTP status code "([^"]*)"$/
*
* @param string $foldername
* @param string $password
* @param string $expectedHttpCode
*
* @return void
*/
public function publicCreationOfFolderWithPasswordShouldFail (
string $foldername ,
string $password ,
2025-06-19 15:34:02 +05:45
string $expectedHttpCode ,
2024-12-24 09:30:42 +05:45
) : void {
2023-10-13 16:59:43 +05:45
$response = $this -> publicCreatesFolderUsingPassword ( $foldername , $password );
2022-12-21 17:22:22 +05:45
$this -> featureContext -> theHTTPStatusCodeShouldBe (
$expectedHttpCode ,
"creation of $foldername in the last publicly shared folder should have failed with code " .
2023-10-13 16:59:43 +05:45
$expectedHttpCode ,
2025-06-19 15:34:02 +05:45
$response ,
2022-12-21 17:22:22 +05:45
);
}
/**
* @Then the mtime of file :fileName in the last shared public link using the WebDAV API should be :mtime
*
* @param string $fileName
* @param string $mtime
*
* @return void
* @throws Exception
*/
public function theMtimeOfFileInTheLastSharedPublicLinkUsingTheWebdavApiShouldBe (
string $fileName ,
2025-06-19 15:34:02 +05:45
string $mtime ,
2024-12-24 09:30:42 +05:45
) : void {
$token = ( $this -> featureContext -> isUsingSharingNG ())
? $this -> featureContext -> shareNgGetLastCreatedLinkShareToken ()
: $this -> featureContext -> getLastCreatedPublicShareToken ();
2022-12-21 17:22:22 +05:45
$baseUrl = $this -> featureContext -> getBaseUrl ();
2023-03-02 10:43:37 +05:45
$mtime = \explode ( " " , $mtime );
\array_pop ( $mtime );
$mtime = \implode ( " " , $mtime );
Assert :: assertStringContainsString (
$mtime ,
2023-05-09 17:09:42 +05:45
WebDavHelper :: getMtimeOfFileInPublicLinkShare (
2023-03-02 10:43:37 +05:45
$baseUrl ,
$fileName ,
$token ,
2025-06-19 15:34:02 +05:45
),
2023-03-02 10:43:37 +05:45
);
2022-12-21 17:22:22 +05:45
}
/**
* @Then the mtime of file :fileName in the last shared public link using the WebDAV API should not be :mtime
*
* @param string $fileName
* @param string $mtime
*
* @return void
* @throws Exception
*/
public function theMtimeOfFileInTheLastSharedPublicLinkUsingTheWebdavApiShouldNotBe (
string $fileName ,
2025-06-19 15:34:02 +05:45
string $mtime ,
2024-12-24 09:30:42 +05:45
) : void {
2023-08-03 13:51:22 +05:45
$token = $this -> featureContext -> getLastCreatedPublicShareToken ();
2022-12-21 17:22:22 +05:45
$baseUrl = $this -> featureContext -> getBaseUrl ();
Assert :: assertNotEquals (
$mtime ,
2023-05-09 17:09:42 +05:45
WebDavHelper :: getMtimeOfFileInPublicLinkShare (
2022-12-21 17:22:22 +05:45
$baseUrl ,
$fileName ,
$token ,
2025-06-19 15:34:02 +05:45
),
2022-12-21 17:22:22 +05:45
);
}
/**
* Uploads a file through the public WebDAV API and sets the response in FeatureContext
*
* @param string $filename
* @param string|null $password
* @param string $body
* @param bool $autoRename
* @param array $additionalHeaders
*
2023-10-13 16:59:43 +05:45
* @return ResponseInterface|null
2022-12-21 17:22:22 +05:45
*/
public function publicUploadContent (
string $filename ,
? string $password = '' ,
string $body = 'test' ,
bool $autoRename = false ,
array $additionalHeaders = [],
2024-12-24 09:30:42 +05:45
) : ? ResponseInterface {
2022-12-21 17:22:22 +05:45
$password = $this -> featureContext -> getActualPassword ( $password );
2024-04-30 12:26:21 +05:45
if ( $this -> featureContext -> isUsingSharingNG ()) {
$token = $this -> featureContext -> shareNgGetLastCreatedLinkShareToken ();
} else {
$token = $this -> featureContext -> getLastCreatedPublicShareToken ();
}
2022-12-21 17:22:22 +05:45
$davPath = WebDavHelper :: getDavPath (
2024-11-11 14:28:23 +05:45
WebDavHelper :: DAV_VERSION_NEW ,
2022-12-21 17:22:22 +05:45
$token ,
2025-06-19 15:34:02 +05:45
"public-files" ,
2022-12-21 17:22:22 +05:45
);
$userName = $this -> getUsernameForPublicWebdavApi (
$token ,
2025-06-19 15:34:02 +05:45
$password ,
2022-12-21 17:22:22 +05:45
);
$filename = \implode (
'/' ,
2025-06-19 15:34:02 +05:45
\array_map ( 'rawurlencode' , \explode ( '/' , $filename )),
2022-12-21 17:22:22 +05:45
);
2024-09-17 17:11:20 +05:45
$encodedFilePath = \ltrim ( $filename , '/' );
$url = $this -> featureContext -> getBaseUrl () . "/ $davPath / $encodedFilePath " ;
2022-12-21 17:22:22 +05:45
// Trim any "/" from the end. For example, if we are putting content to a
// single file that has been shared with a link, then the URL should end
// with the link token and no "/" at the end.
$url = \rtrim ( $url , "/" );
$headers = [ 'X-Requested-With' => 'XMLHttpRequest' ];
if ( $autoRename ) {
$headers [ 'OC-Autorename' ] = 1 ;
}
$headers = \array_merge ( $headers , $additionalHeaders );
2023-10-13 16:59:43 +05:45
return HttpRequestHelper :: put (
2022-12-21 17:22:22 +05:45
$url ,
$userName ,
$password ,
$headers ,
2025-06-19 15:34:02 +05:45
$body ,
2022-12-21 17:22:22 +05:45
);
}
/**
* @param string $token
* @param string $password
*
* @return string|null
*/
private function getUsernameForPublicWebdavApi (
string $token ,
2025-06-19 15:34:02 +05:45
string $password ,
2024-12-24 09:30:42 +05:45
) : ? string {
2024-11-11 14:28:23 +05:45
if ( $password !== '' ) {
$userName = 'public' ;
2022-12-21 17:22:22 +05:45
} else {
2024-11-11 14:28:23 +05:45
$userName = null ;
2022-12-21 17:22:22 +05:45
}
return $userName ;
}
/**
* @BeforeScenario
*
* @param BeforeScenarioScope $scope
*
* @return void
*/
2024-12-24 09:30:42 +05:45
public function before ( BeforeScenarioScope $scope ) : void {
2022-12-21 17:22:22 +05:45
// Get the environment
$environment = $scope -> getEnvironment ();
// Get all the contexts you need in this context
2024-10-08 12:26:40 +05:45
$this -> featureContext = BehatHelper :: getContext ( $scope , $environment , 'FeatureContext' );
2022-12-21 17:22:22 +05:45
}
2023-01-05 14:39:18 +05:45
/**
2024-11-11 14:28:23 +05:45
* @When /^the public sends "([^"]*)" request to the last public link share using the public WebDAV API(?: with password "([^"]*)")?$/
2023-01-05 14:39:18 +05:45
*
* @param string $method
2023-05-02 17:25:56 +05:45
* @param string|null $password
2023-01-05 14:39:18 +05:45
*
* @return void
* @throws GuzzleException
*/
2024-12-24 09:30:42 +05:45
public function publicSendsRequestToLastPublicShare ( string $method , ? string $password = '' ) : void {
2023-01-05 14:39:18 +05:45
if ( $method === "PROPFIND" ) {
$body = '<?xml version="1.0"?>
<d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns">
<d:prop>
<d:resourcetype/>
<oc:public-link-item-type/>
<oc:public-link-permission/>
<oc:public-link-expiration/>
<oc:public-link-share-datetime/>
<oc:public-link-share-owner/>
</d:prop>
</d:propfind>' ;
2023-05-02 17:25:56 +05:45
} else {
$body = null ;
2023-01-05 14:39:18 +05:45
}
2024-12-24 09:30:42 +05:45
$token = ( $this -> featureContext -> isUsingSharingNG ())
? $this -> featureContext -> shareNgGetLastCreatedLinkShareToken ()
: $this -> featureContext -> getLastCreatedPublicShareToken ();
2023-01-05 14:39:18 +05:45
$davPath = WebDavHelper :: getDavPath (
2024-11-11 14:28:23 +05:45
WebDavHelper :: DAV_VERSION_NEW ,
2024-09-17 17:11:20 +05:45
$token ,
2025-06-19 15:34:02 +05:45
"public-files" ,
2023-01-05 14:39:18 +05:45
);
2023-11-13 23:37:12 +01:00
$password = $this -> featureContext -> getActualPassword ( $password );
2023-01-05 14:39:18 +05:45
$username = $this -> getUsernameForPublicWebdavApi (
$token ,
2025-06-19 15:34:02 +05:45
$password ,
2023-01-05 14:39:18 +05:45
);
2024-09-17 17:11:20 +05:45
$fullUrl = $this -> featureContext -> getBaseUrl () . "/ $davPath " ;
2023-01-05 14:39:18 +05:45
$response = HttpRequestHelper :: sendRequest (
$fullUrl ,
$method ,
$username ,
$password ,
null ,
2025-06-19 15:34:02 +05:45
$body ,
2023-01-05 14:39:18 +05:45
);
$this -> featureContext -> setResponse ( $response );
}
2022-12-21 17:22:22 +05:45
}