Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests-only] [full-ci] Refactoring unshare step definition code #6608

Merged
merged 4 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion tests/TestHelpers/SharingHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ public static function createShare(
$fd['expireDate'] = $expireDate;
}
$headers = ['OCS-APIREQUEST' => 'true'];

saw-jan marked this conversation as resolved.
Show resolved Hide resolved
return HttpRequestHelper::post(
$fullUrl,
$xRequestId,
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance/expected-failures-API-on-OCIS-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ Not everything needs to be implemented for ocis. While the oc10 testsuite covers
- [coreApiCapabilities/capabilities.feature:136](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiCapabilities/capabilities.feature#L136)
- [coreApiCapabilities/capabilities.feature:175](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiCapabilities/capabilities.feature#L175)

#### [Sharing of project space root via public link does no longer work](https://github.com/owncloud/ocis/issues/6278)
#### [sharing the shares folder to users exits with different status code than in oc10 backend](https://github.com/owncloud/ocis/issues/2215)
- [coreApiShareCreateSpecialToShares2/createShareDefaultFolderForReceivedShares.feature:23](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareDefaultFolderForReceivedShares.feature#L23)
- [coreApiShareCreateSpecialToShares2/createShareDefaultFolderForReceivedShares.feature:24](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/coreApiShareCreateSpecialToShares2/createShareDefaultFolderForReceivedShares.feature#L24)

Expand Down
25 changes: 19 additions & 6 deletions tests/acceptance/features/bootstrap/Sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -3554,6 +3554,25 @@ public function assertNoSharesOfUserAreInState(string $user, string $state):void
* @throws JsonException
*/
public function userHasUnsharedResourceSharedTo(string $sharer, string $path, string $sharee): void {
$this->userUnsharesResourceSharedTo($sharer, $path, $sharee);
$this->ocsContext->assertOCSResponseIndicatesSuccess(
'The ocs share response does not indicate success.',
);
$this->emptyLastHTTPStatusCodesArray();
$this->emptyLastOCSStatusCodesArray();
}

/**
* @When /^user "([^"]*)" unshares (?:folder|file|entity) "([^"]*)" shared to "([^"]*)"$/
*
* @param string $sharer
* @param string $path
* @param string $sharee
*
* @return void
* @throws JsonException
*/
public function userUnsharesResourceSharedTo(string $sharer, string $path, string $sharee): void {
$sharer = $this->getActualUsername($sharer);
$sharee = $this->getActualUsername($sharee);

Expand All @@ -3575,12 +3594,6 @@ public function userHasUnsharedResourceSharedTo(string $sharer, string $path, st
'DELETE',
'/apps/files_sharing/api/v' . $this->sharingApiVersion . '/shares/' . $shareId
);

$this->ocsContext->assertOCSResponseIndicatesSuccess(
'The ocs share response does not indicate success.',
);
$this->emptyLastHTTPStatusCodesArray();
$this->emptyLastOCSStatusCodesArray();
}

/**
Expand Down
64 changes: 25 additions & 39 deletions tests/acceptance/features/bootstrap/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -3334,78 +3334,71 @@ public function theUserShouldNotBeAbleToDeleteEntry(string $user, string $entry,
* @return void
*/
public function fileHasBeenDeleted(string $file, string $user):void {
$this->userHasDeletedFile($user, "deleted", "file", $file);
$this->userHasDeletedResource($user, "deleted", "file", $file);
}

/**
* @When /^user "([^"]*)" (?:deletes|unshares) (?:file|folder) "([^"]*)" using the WebDAV API$/
* @When user :user deletes file/folder :resource using the WebDAV API
*
* @param string $user
* @param string $file
* @param string $resource
*
* @return void
*/
public function userDeletesFile(string $user, string $file):void {
public function userDeletesFile(string $user, string $resource):void {
$user = $this->getActualUsername($user);
$this->pauseUploadDelete();
$this->response = $this->makeDavRequest($user, 'DELETE', $file, []);
$this->response = $this->makeDavRequest($user, 'DELETE', $resource, []);
$this->lastUploadDeleteTime = \time();
$this->pushToLastHttpStatusCodesArray((string) $this->getResponse()->getStatusCode());
}

/**
* @Given /^user "([^"]*)" has (deleted|unshared) (?:file|folder|entity) "([^"]*)"$/
* @Given /^user "([^"]*)" has deleted (?:file|folder|entity) "([^"]*)"$/
*
* @param string $user
* @param string $deletedOrUnshared
* @param string $entry
* @param string $resource
*
* @return void
* @throws Exception
*/
public function userHasDeletedFile(string $user, string $deletedOrUnshared, string $entry):void {
public function userHasDeletedResource(string $user, string $resource):void {
$user = $this->getActualUsername($user);
$this->userDeletesFile($user, $entry);
$this->userDeletesFile($user, $resource);
// If the file or folder was there and got deleted then we get a 204
// That is good and the expected status
// If the file or folder was already not there then we get a 404
// That is not expected. Scenarios that use "Given user has deleted..."
// should only be using such steps when it is a file that exists and needs
// to be deleted.
if ($deletedOrUnshared === "deleted") {
$deleteText = "delete";
} else {
$deleteText = "unshare";
}

$this->theHTTPStatusCodeShouldBe(
["204"],
"HTTP status code was not 204 while trying to $deleteText resource '$entry' for user '$user'"
"HTTP status code was not 204 while trying to delete resource '$resource' for user '$user'"
);
$this->emptyLastHTTPStatusCodesArray();
}

/**
* @Given /^user "([^"]*)" has (deleted|unshared) the following (?:files|folders|resources)$/
* @Given /^user "([^"]*)" has deleted the following (?:files|folders|resources)$/
*
* @param string $user
* @param string $deletedOrUnshared
* @param TableNode $table
*
* @return void
* @throws Exception
*/
public function userHasDeletedFollowingFiles(string $user, string $deletedOrUnshared, TableNode $table):void {
public function userHasDeletedFollowingFiles(string $user, TableNode $table):void {
$this->verifyTableNodeColumns($table, ["path"]);
$paths = $table->getHash();

foreach ($paths as $file) {
$this->userHasDeletedFile($user, $deletedOrUnshared, $file["path"]);
$this->userHasDeletedResource($user, $file["path"]);
}
}

/**
* @When /^user "([^"]*)" (?:deletes|unshares) the following (?:files|folders)$/
* @When /^user "([^"]*)" deletes the following (?:files|folders)$/
*
* @param string $user
* @param TableNode $table
Expand All @@ -3425,7 +3418,7 @@ public function userDeletesFollowingFiles(string $user, TableNode $table):void {
}

/**
* @When /^the user (?:deletes|unshares) (?:file|folder) "([^"]*)" using the WebDAV API$/
* @When /^the user deletes (?:file|folder) "([^"]*)" using the WebDAV API$/
*
* @param string $file
*
Expand All @@ -3436,20 +3429,19 @@ public function theUserDeletesFile(string $file):void {
}

/**
* @Given /^the user has (deleted|unshared) (file|folder) "([^"]*)"$/
* @Given /^the user has deleted (file|folder) "([^"]*)"$/
*
* @param string $deletedOrUnshared
* @param string $fileOrFolder
* @param string $file
*
* @return void
*/
public function theUserHasDeletedFile(string $deletedOrUnshared, string $fileOrFolder, string $file):void {
$this->userHasDeletedFile($this->getCurrentUser(), $deletedOrUnshared, $fileOrFolder, $file);
public function theUserHasDeletedFile(string $fileOrFolder, string $file):void {
$this->userHasDeletedResource($this->getCurrentUser(), $fileOrFolder, $file);
}

/**
* @When /^user "([^"]*)" (?:deletes|unshares) these (?:files|folders|entries) without delays using the WebDAV API$/
* @When /^user "([^"]*)" deletes these (?:files|folders|entries) without delays using the WebDAV API$/
*
* @param string $user
* @param TableNode $table of files or folders to delete
Expand All @@ -3469,7 +3461,7 @@ public function userDeletesFilesFoldersWithoutDelays(string $user, TableNode $ta
}

/**
* @When /^the user (?:deletes|unshares) these (?:files|folders|entries) without delays using the WebDAV API$/
* @When /^the user deletes these (?:files|folders|entries) without delays using the WebDAV API$/
*
* @param TableNode $table of files or folders to delete
*
Expand All @@ -3481,7 +3473,7 @@ public function theUserDeletesFilesFoldersWithoutDelays(TableNode $table):void {
}

/**
* @When /^user "([^"]*)" on "(LOCAL|REMOTE)" (?:deletes|unshares) (?:file|folder) "([^"]*)" using the WebDAV API$/
* @When /^user "([^"]*)" on "(LOCAL|REMOTE)" deletes (?:file|folder) "([^"]*)" using the WebDAV API$/
*
* @param string $user
* @param string $server
Expand All @@ -3496,30 +3488,24 @@ public function userOnDeletesFile(string $user, string $server, string $file):vo
}

/**
* @Given /^user "([^"]*)" on "(LOCAL|REMOTE)" has (deleted|unshared) (file|folder) "([^"]*)"$/
* @Given /^user "([^"]*)" on "(LOCAL|REMOTE)" has deleted (file|folder) "([^"]*)"$/
*
* @param string $user
* @param string $server
* @param string $deletedOrUnshared
* @param string $fileOrFolder
* @param string $entry
*
* @return void
*/
public function userOnHasDeletedFile(string $user, string $server, string $deletedOrUnshared, string $fileOrFolder, string $entry):void {
public function userOnHasDeletedFile(string $user, string $server, string $fileOrFolder, string $entry):void {
$this->userOnDeletesFile($user, $server, $entry);
// If the file was there and got deleted then we get a 204
// If the file was already not there then we get a 404
// Either way, the outcome of the "given" step is OK
if ($deletedOrUnshared === "deleted") {
$deleteText = "delete";
} else {
$deleteText = "unshare";
}

$this->theHTTPStatusCodeShouldBe(
["204", "404"],
"HTTP status code was not 204 or 404 while trying to $deleteText $fileOrFolder '$entry' for user '$user' on server '$server'"
"HTTP status code was not 204 or 404 while trying to delete $fileOrFolder '$entry' for user '$user' on server '$server'"
);
}

Expand Down Expand Up @@ -4513,7 +4499,7 @@ public function userDeletesEverythingInFolder(
foreach ($elementList as $element) {
$element = \substr((string)$element, \strlen($davPrefix));
if ($checkEachDelete) {
$this->userHasDeletedFile($user, "deleted", "file", $element);
$this->userHasDeletedResource($user, "deleted", "file", $element);
} else {
$this->userDeletesFile($user, $element);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ Feature: shares are received in the default folder for received shares
And user "Alice" has created folder "FOLDER"
When user "Alice" shares folder "/FOLDER" with user "Brian" using the sharing API
And user "Brian" accepts share "/FOLDER" offered by user "Alice" using the sharing API
And user "Brian" unshares folder "Shares/FOLDER" using the WebDAV API
And user "Brian" declines share "/Shares/FOLDER" offered by user "Alice" using the sharing API
And user "Brian" shares folder "/Shares" with user "Alice" using the sharing API
Then the OCS status code of responses on each endpoint should be "<ocs_status_code>" respectively
And the HTTP status code of responses on each endpoint should be "<http_status_code>" respectively
Examples:
| ocs_api_version | ocs_status_code | http_status_code |
| 1 | 100, 100, 400 | 200, 200, 204, 200 |
| 2 | 200, 200, 400 | 200, 200, 204, 400 |
| ocs_api_version | ocs_status_code | http_status_code |
| 1 | 100, 100, 100, 400 | 200, 200, 200, 200 |
| 2 | 200, 200, 200, 400 | 200, 200, 200, 400 |
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Feature: sharing
And as "Alice" file "/shared_file.txt" should exist in the trashbin
And as "Brian" file "/shared_file.txt" should exist in the trashbin


Scenario: deleting a folder out of a share as recipient creates a backup for the owner
Given using OCS API version "1"
And user "Alice" has created folder "/shared"
Expand Down Expand Up @@ -106,8 +106,8 @@ Feature: sharing
And user "Carol" has stored etag of element "/PARENT"
And user "Brian" has stored etag of element "/"
And user "Brian" has stored etag of element "/Shares"
When user "Brian" unshares file "/Shares/parent.txt" using the WebDAV API
Then the HTTP status code should be "204"
When user "Brian" declines share "/Shares/parent.txt" offered by user "Carol" using the sharing API
Then the HTTP status code should be "200"
And the etag of element "/" of user "Brian" should have changed
And the etag of element "/Shares" of user "Brian" should have changed
And the etag of element "/PARENT" of user "Carol" should not have changed
Expand Down Expand Up @@ -226,3 +226,17 @@ Feature: sharing
| ocs_api_version | ocs_status_code | http_status_code |
| 1 | 404 | 200 |
| 2 | 404 | 404 |


Scenario Outline: unshare a shared resources
Given using OCS API version "<ocs_api_version>"
And user "Alice" has shared file "textfile0.txt" with user "Brian"
And user "Brian" has accepted share "/textfile0.txt" offered by user "Alice"
When user "Alice" unshares file "textfile0.txt" shared to "Brian"
Then the OCS status code should be "<ocs_status_code>"
And the HTTP status code should be "<http_status_code>"
And as "Brian" file "/Shares/textfile0.txt" should not exist
Examples:
| ocs_api_version | ocs_status_code | http_status_code |
| 1 | 100 | 200 |
| 2 | 200 | 200 |
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ Feature: dav-versions
| new | Brian | /testshare |


Scenario: receiver tries to get file versions of unshared file from the sharer
Scenario: sharee tries to get file versions of file not shared by the sharer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, should be fine there. This scenario tests the edge case that when textfile0 is shared with Brian, he cannot view the versions of another unshared file of Alice.

Given user "Brian" has been created with default attributes and without skeleton files
And user "Alice" has uploaded file with content "textfile0" to "textfile0.txt"
And user "Alice" has uploaded file with content "textfile1" to "textfile1.txt"
Expand Down