Skip to content

Commit

Permalink
Implement and add tests for /Shares on ocis removed from core
Browse files Browse the repository at this point in the history
  • Loading branch information
SagarGi committed Aug 12, 2022
1 parent 02adcbd commit 6cb2b34
Show file tree
Hide file tree
Showing 2 changed files with 337 additions and 0 deletions.
254 changes: 254 additions & 0 deletions tests/acceptance/features/apiSpaces/copySpaces.feature
Original file line number Diff line number Diff line change
Expand Up @@ -451,3 +451,257 @@ Feature: copy file
| permissions |
| 31 |
| 17 |

@files_sharing-app-required @issue-ocis-reva-11
Scenario: Copying a file to a folder with no permissions
Given using spaces DAV path
And user "Brian" has created folder "/testshare"
And user "Brian" has created a share with settings
| path | testshare |
| shareType | user |
| permissions | read |
| shareWith | Alice |
And user "Alice" has accepted share "/testshare" offered by user "Brian"
And user "Alice" has uploaded file with content "ownCloud test text file 0" to "/textfile0.txt"
When user "Alice" copies file "/textfile0.txt" from space "Personal" to "/testshare/textfile0.txt" inside space "Shares Jail" using the WebDAV API
Then the HTTP status code should be "403"
And user "Alice" should not be able to download file "/testshare/textfile0.txt" inside space "Shares Jail"


@files_sharing-app-required @issue-ocis-reva-11
Scenario: Copying a file to overwrite a file into a folder with no permissions
Given using spaces DAV path
And user "Brian" has created folder "/testshare"
And user "Brian" has uploaded file with content "ownCloud test text file 1" to "textfile1.txt"
And user "Alice" has uploaded file with content "ownCloud test text file 0" to "/textfile0.txt"
And user "Brian" has created a share with settings
| path | testshare |
| shareType | user |
| permissions | read |
| shareWith | Alice |
And user "Alice" has accepted share "/testshare" offered by user "Brian"
And user "Brian" has copied file "textfile1.txt" to "/testshare/overwritethis.txt"
When user "Alice" copies file "/textfile0.txt" from space "Personal" to "/testshare/overwritethis.txt" inside space "Shares Jail" using the WebDAV API
Then the HTTP status code should be "403"
And the content of file "/testshare/overwritethis.txt" inside space "Shares Jail" for user "Alice" should be "ownCloud test text file 1"

@issue-ocis-1239
Scenario: copy a file over the top of an existing folder received as a user share
Given using spaces DAV path
And user "Alice" has uploaded file with content "ownCloud test text file 1" to "textfile1.txt"
And user "Brian" has created folder "/BRIAN-Folder"
And user "Brian" has created folder "BRIAN-Folder/sample-folder"
And user "Brian" has shared folder "BRIAN-Folder" with user "Alice"
And user "Alice" has accepted share "/BRIAN-Folder" offered by user "Brian"
When user "Alice" copies file "/textfile1.txt" from space "Personal" to "/BRIAN-Folder" inside space "Shares Jail" using the WebDAV API
#response code is 500
Then the HTTP status code should be "204"
And the content of file "/BRIAN-Folder" inside space "Shares Jail" for user "Alice" should be "ownCloud test text file 1"
And for user "Alice" folder "BRIAN-FOLDER" of the space "Shares Jail" should not contain these files:
| /sample-folder |
And as "Alice" file "/textfile1.txt" should exist
And user "Alice" should not have any received shares


@issue-ocis-1239
Scenario: copy a folder over the top of an existing file received as a user share
Given using spaces DAV path
And user "Alice" has created folder "/FOLDER"
And user "Alice" has created folder "/FOLDER/sample-folder"
And user "Brian" has uploaded file with content "file to share" to "/sharedfile1.txt"
And user "Brian" has shared file "/sharedfile1.txt" with user "Alice"
And user "Alice" has accepted share "/sharedfile1.txt" offered by user "Brian"
When user "Alice" copies folder "/FOLDER" from space "Personal" to "/sharedfile1.txt" inside space "Shares Jail" using the WebDAV API
#response code is 403
Then the HTTP status code should be "204"
And as "Alice" folder "/FOLDER/sample-folder" should exist
And for user "Alice" folder "sharedfile1.txt" of the space "Shares Jail" should contain these files:
| /sample-folder |
And user "Alice" should not have any received shares


@issue-ocis-1239
Scenario: copy a folder into another folder at different level which is received as a user share
Given using spaces DAV path
And user "Brian" has created folder "BRIAN-FOLDER"
And user "Brian" has created folder "BRIAN-FOLDER/second-level-folder"
And user "Brian" has created folder "BRIAN-FOLDER/second-level-folder/third-level-folder"
And user "Brian" has shared folder "BRIAN-FOLDER" with user "Alice"
And user "Alice" has accepted share "/BRIAN-FOLDER" offered by user "Brian"
And user "Alice" has created folder "Sample-Folder-A"
And user "Alice" has created folder "Sample-Folder-A/sample-folder-b"
And user "Alice" has created folder "Sample-Folder-A/sample-folder-b/sample-folder-c"
When user "Alice" copies folder "Sample-Folder-A/sample-folder-b" from space "Personal" to "/BRIAN-FOLDER/second-level-folder/third-level-folder" inside space "Shares Jail" using the WebDAV API
Then the HTTP status code should be "204"
And as "Alice" folder "/Sample-Folder-A/sample-folder-b/sample-folder-c" should exist
And for user "Alice" folder "BRIAN-FOLDER" of the space "Shares Jail" should contain these files:
| /second-level-folder/third-level-folder/sample-folder-c |
And the response when user "Alice" gets the info of the last share should include
| file_target | /Shares/BRIAN-FOLDER |

@issue-ocis-1239
Scenario: copy a file into a folder at different level received as a user share
Given using spaces DAV path
And user "Brian" has created folder "BRIAN-FOLDER"
And user "Brian" has created folder "BRIAN-FOLDER/second-level-folder"
And user "Brian" has created folder "BRIAN-FOLDER/second-level-folder/third-level-folder"
And user "Brian" has shared folder "BRIAN-FOLDER" with user "Alice"
And user "Alice" has accepted share "/BRIAN-FOLDER" offered by user "Brian"
And user "Alice" has created folder "Sample-Folder-A"
And user "Alice" has created folder "Sample-Folder-A/sample-folder-b"
And user "Alice" has uploaded file with content "sample file-c" to "Sample-Folder-A/sample-folder-b/textfile-c.txt"
When user "Alice" copies folder "Sample-Folder-A/sample-folder-b/textfile-c.txt" from space "Personal" to "/BRIAN-FOLDER/second-level-folder" inside space "Shares Jail" using the WebDAV API
Then the HTTP status code should be "204"
And for user "Alice" folder "BRIAN-FOLDER" of the space "Shares Jail" should not contain these files:
| /second-level-folder/third-level-folder |
And as "Alice" file "Sample-Folder-A/sample-folder-b/textfile-c.txt" should exist
And for user "Alice" folder "BRIAN-FOLDER" of the space "Shares Jail" should contain these files:
| /second-level-folder |
And the content of file "/BRIAN-FOLDER/second-level-folder" inside space "Shares Jail" for user "Alice" should be "sample file-c"
And the response when user "Alice" gets the info of the last share should include
| file_target | /Shares/BRIAN-FOLDER |


@issue-ocis-1239
Scenario: copy a file into a file at different level received as a user share
Given using spaces DAV path
And user "Brian" has created folder "BRIAN-FOLDER"
And user "Brian" has uploaded file with content "file at second level" to "BRIAN-FOLDER/second-level-file.txt"
And user "Brian" has shared folder "BRIAN-FOLDER" with user "Alice"
And user "Alice" has accepted share "/BRIAN-FOLDER" offered by user "Brian"
And user "Alice" has created folder "Sample-Folder-A"
And user "Alice" has created folder "Sample-Folder-A/sample-folder-b"
And user "Alice" has uploaded file with content "sample file-c" to "Sample-Folder-A/sample-folder-b/textfile-c.txt"
When user "Alice" copies folder "Sample-Folder-A/sample-folder-b/textfile-c.txt" from space "Personal" to "/BRIAN-FOLDER/second-level-file.txt" inside space "Shares Jail" using the WebDAV API
Then the HTTP status code should be "204"
And as "Alice" file "Sample-Folder-A/sample-folder-b/textfile-c.txt" should exist
And for user "Alice" folder "BRIAN-FOLDER" of the space "Shares Jail" should contain these files:
| /second-level-file.txt |
And for user "Alice" folder "BRIAN-FOLDER" of the space "Shares Jail" should not contain these files:
| /textfile-c.txt.txt |
And the content of file "/BRIAN-FOLDER/second-level-file.txt" inside space "Shares Jail" for user "Alice" should be "sample file-c"
And the response when user "Alice" gets the info of the last share should include
| file_target | /Shares/BRIAN-FOLDER |


@issue-ocis-1239
Scenario: copy a folder into a file at different level received as a user share
Given using spaces DAV path
And user "Alice" has created folder "FOLDER"
And user "Alice" has created folder "FOLDER/second-level-folder"
And user "Alice" has created folder "FOLDER/second-level-folder/third-level-folder"
And user "Brian" has created folder "BRIAN-FOLDER"
And user "Brian" has created folder "BRIAN-FOLDER/second-level-folder"
And user "Brian" has uploaded file with content "file at third level" to "BRIAN-FOLDER/second-level-folder/third-level-file.txt"
And user "Brian" has shared folder "BRIAN-FOLDER" with user "Alice"
And user "Alice" has accepted share "/BRIAN-FOLDER" offered by user "Brian"
When user "Alice" copies folder "FOLDER/second-level-folder" from space "Personal" to "/BRIAN-FOLDER/second-level-folder/third-level-file.txt" inside space "Shares Jail" using the WebDAV API
Then the HTTP status code should be "204"
And for user "Alice" folder "BRIAN-FOLDER" of the space "Shares Jail" should contain these files:
| /second-level-folder/third-level-file.txt |
And as "Alice" folder "FOLDER/second-level-folder/third-level-folder" should exist
And for user "Alice" folder "BRIAN-FOLDER" of the space "Shares Jail" should contain these files:
| /second-level-folder/third-level-file.txt/third-level-folder |
And for user "Alice" folder "BRIAN-FOLDER" of the space "Shares Jail" should not contain these files:
| /second-level-folder/second-level-folder |
And the response when user "Alice" gets the info of the last share should include
| file_target | /Shares/BRIAN-FOLDER |


@issue-ocis-1239
Scenario: copy a folder into another folder at different level which is received as a group share
Given using spaces DAV path
And group "grp1" has been created
And user "Alice" has been added to group "grp1"
And user "Brian" has been added to group "grp1"
And user "Brian" has created folder "BRIAN-FOLDER"
And user "Brian" has created folder "BRIAN-FOLDER/second-level-folder"
And user "Brian" has created folder "BRIAN-FOLDER/second-level-folder/third-level-folder"
And user "Brian" has shared folder "BRIAN-FOLDER" with group "grp1"
And user "Alice" has accepted share "/BRIAN-FOLDER" offered by user "Brian"
And user "Alice" has created folder "Sample-Folder-A"
And user "Alice" has created folder "Sample-Folder-A/sample-folder-b"
And user "Alice" has created folder "Sample-Folder-A/sample-folder-b/sample-folder-c"
When user "Alice" copies folder "Sample-Folder-A/sample-folder-b" from space "Personal" to "/BRIAN-FOLDER/second-level-folder/third-level-folder" inside space "Shares Jail" using the WebDAV API
Then the HTTP status code should be "204"
And as "Alice" folder "/Sample-Folder-A/sample-folder-b/sample-folder-c" should exist
And for user "Alice" folder "BRIAN-FOLDER" of the space "Shares Jail" should contain these files:
| /second-level-folder/third-level-folder/sample-folder-c |
And the response when user "Alice" gets the info of the last share should include
| file_target | /Shares/BRIAN-FOLDER |


@issue-ocis-1239
Scenario: copy a file into a folder at different level received as a group share
Given using spaces DAV path
And group "grp1" has been created
And user "Alice" has been added to group "grp1"
And user "Brian" has been added to group "grp1"
And user "Brian" has created folder "BRIAN-FOLDER"
And user "Brian" has created folder "BRIAN-FOLDER/second-level-folder"
And user "Brian" has created folder "BRIAN-FOLDER/second-level-folder/third-level-folder"
And user "Brian" has shared folder "BRIAN-FOLDER" with group "grp1"
And user "Alice" has accepted share "/BRIAN-FOLDER" offered by user "Brian"
And user "Alice" has created folder "Sample-Folder-A"
And user "Alice" has created folder "Sample-Folder-A/sample-folder-b"
And user "Alice" has uploaded file with content "sample file-c" to "Sample-Folder-A/sample-folder-b/textfile-c.txt"
When user "Alice" copies folder "Sample-Folder-A/sample-folder-b/textfile-c.txt" from space "Personal" to "/BRIAN-FOLDER/second-level-folder" inside space "Shares Jail" using the WebDAV API
Then the HTTP status code should be "204"
And for user "Alice" folder "BRIAN-FOLDER" of the space "Shares Jail" should not contain these files:
| /second-level-folder/third-level-folder |
And as "Alice" file "Sample-Folder-A/sample-folder-b/textfile-c.txt" should exist
And for user "Alice" folder "BRIAN-FOLDER" of the space "Shares Jail" should contain these files:
| /second-level-folder |
And the content of file "/BRIAN-FOLDER/second-level-folder" inside space "Shares Jail" for user "Alice" should be "sample file-c"
And the response when user "Alice" gets the info of the last share should include
| file_target | /Shares/BRIAN-FOLDER |

@issue-ocis-1239
Scenario: copy a file into a file at different level received as a group share
Given using spaces DAV path
And group "grp1" has been created
And user "Alice" has been added to group "grp1"
And user "Brian" has been added to group "grp1"
And user "Brian" has created folder "BRIAN-FOLDER"
And user "Brian" has uploaded file with content "file at second level" to "BRIAN-FOLDER/second-level-file.txt"
And user "Brian" has shared folder "BRIAN-FOLDER" with group "grp1"
And user "Alice" has accepted share "/BRIAN-FOLDER" offered by user "Brian"
And user "Alice" has created folder "Sample-Folder-A"
And user "Alice" has created folder "Sample-Folder-A/sample-folder-b"
And user "Alice" has uploaded file with content "sample file-c" to "Sample-Folder-A/sample-folder-b/textfile-c.txt"
When user "Alice" copies folder "Sample-Folder-A/sample-folder-b/textfile-c.txt" from space "Personal" to "/BRIAN-FOLDER/second-level-file.txt" inside space "Shares Jail" using the WebDAV API
Then the HTTP status code should be "204"
And as "Alice" file "Sample-Folder-A/sample-folder-b/textfile-c.txt" should exist
And for user "Alice" folder "BRIAN-FOLDER" of the space "Shares Jail" should not contain these files:
| /textfile-c.txt |
And as "Alice" file "Sample-Folder-A/sample-folder-b/textfile-c.txt" should exist
And for user "Alice" folder "BRIAN-FOLDER" of the space "Shares Jail" should contain these files:
| /second-level-file.txt |
And the content of file "/BRIAN-FOLDER/second-level-file.txt" inside space "Shares Jail" for user "Alice" should be "sample file-c"
And the response when user "Alice" gets the info of the last share should include
| file_target | /Shares/BRIAN-FOLDER |

@issue-ocis-1239
Scenario: copy a folder into a file at different level received as a group share
Given using spaces DAV path
And group "grp1" has been created
And user "Alice" has been added to group "grp1"
And user "Brian" has been added to group "grp1"
And user "Brian" has created folder "BRIAN-FOLDER"
And user "Brian" has created folder "BRIAN-FOLDER/second-level-folder"
And user "Brian" has uploaded file with content "file at third level" to "BRIAN-FOLDER/second-level-folder/third-level-file.txt"
And user "Brian" has shared folder "BRIAN-FOLDER" with group "grp1"
And user "Alice" has accepted share "/BRIAN-FOLDER" offered by user "Brian"
And user "Alice" has created folder "FOLDER"
And user "Alice" has created folder "FOLDER/second-level-folder"
And user "Alice" has created folder "FOLDER/second-level-folder/third-level-folder"
When user "Alice" copies folder "FOLDER/second-level-folder" from space "Personal" to "/BRIAN-FOLDER/second-level-folder/third-level-file.txt" inside space "Shares Jail" using the WebDAV API
Then the HTTP status code should be "204"
And for user "Alice" folder "BRIAN-FOLDER" of the space "Shares Jail" should contain these files:
| /second-level-folder/third-level-file.txt |
| /second-level-folder/third-level-file.txt/third-level-folder |
And as "Alice" folder "FOLDER/second-level-folder/third-level-folder" should exist
And for user "Alice" folder "BRIAN-FOLDER" of the space "Shares Jail" should not contain these files:
| /second-level-folder/second-level-folder |
And the response when user "Alice" gets the info of the last share should include
| file_target | /Shares/BRIAN-FOLDER |
83 changes: 83 additions & 0 deletions tests/acceptance/features/bootstrap/SpacesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1878,6 +1878,89 @@ public function userCopiesFileFromAndToSpaceBetweenSpaces(
$this->copyFilesAndFoldersRequest($user, $fullUrl, $headers);
}

/**
* @param string $fullUrl
* @param string $user
*
* @return void
*/
public function downloadFileAsUserUsingPassword(
string $fullUrl,
string $user
):void {
$this->featureContext->setResponse(
HttpRequestHelper::sendRequest(
$fullUrl,
$this->featureContext->getStepLineRef(),
'GET',
$user,
$this->featureContext->getPasswordForUser($user),
)
);
}

/**
* @Then /^the content of file "([^"]*)" inside space "([^"]*)" for user "([^"]*)" should be "([^"]*)"$/
*
* @param string $fileName
* @param string $spaceName
* @param string $user
* @param string $expectedContent
*
* @return void
* @throws GuzzleException
*/
public function contentOfFileForUserInsideSpaceShouldBe(
string $fileName,
string $spaceName,
string $user,
string $expectedContent
):void {
$space = $this->getSpaceByName($user, $spaceName);
$fullUrl = $space["root"]["webDavUrl"] . '/' . ltrim($fileName, "/");
$this->downloadFileAsUserUsingPassword($fullUrl, $user);
$actualContent = (string) $this->featureContext->getResponse()->getBody()->getContents();
$actualStatus = $this->featureContext->getResponse()->getStatusCode();
Assert::assertEquals(
$expectedContent,
$actualContent,
"The downloaded content was expected to be '$expectedContent', but actually is '$actualContent'. HTTP status was $actualStatus"
);
}

/**
* @Then /^user "([^"]*)" should not be able to download file "([^"]*)" inside space "([^"]*)"$/
*
* @param string $user
* @param string $fileName
* @param string $spaceName
*
* @return void
* @throws GuzzleException
*/
public function userShouldNotBeAbleToDownloadFileInsideSpace(
string $user,
string $fileName,
string $spaceName
):void {
$space = $this->getSpaceByName($user, $spaceName);
$fullUrl = $space["root"]["webDavUrl"] . '/' . ltrim($fileName, "/");
$this->downloadFileAsUserUsingPassword($fullUrl, $user);
Assert::assertGreaterThanOrEqual(
400,
$this->featureContext->getResponse()->getStatusCode(),
__METHOD__
. ' download must fail'
);
Assert::assertLessThanOrEqual(
499,
$this->featureContext->getResponse()->getStatusCode(),
__METHOD__
. ' 4xx error expected but got status code "'
. $this->featureContext->getResponse()->getStatusCode() . '"'
);
}

/**
* @When /^user "([^"]*)" moves (?:file|folder) "([^"]*)" from space "([^"]*)" to "([^"]*)" inside space "([^"]*)" using the WebDAV API$/
*
Expand Down

0 comments on commit 6cb2b34

Please sign in to comment.