Skip to content

Commit

Permalink
[Tests-Only] add api tests for accessing shares by id
Browse files Browse the repository at this point in the history
  • Loading branch information
dpakach committed May 26, 2021
1 parent 8753d1d commit 84df91a
Show file tree
Hide file tree
Showing 4 changed files with 297 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
@api @files_sharing-app-required @notToImplementOnOCIS
Feature: share access by ID

Background:
Given these users have been created with default attributes and without skeleton files:
| username |
| Alice |
| Brian |

Scenario Outline: Get a share with a valid share ID
Given using OCS API version "<ocs_api_version>"
And user "Alice" has uploaded file with content "ownCloud test text file 0" to "/textfile0.txt"
When user "Alice" shares file "textfile0.txt" with user "Brian" using the sharing API
And user "Alice" gets share with id "%last_share_id%" using the sharing API
Then the OCS status code should be "<ocs_status_code>"
And the HTTP status code should be "200"
And the fields of the last response to user "Alice" sharing with user "Brian" should include
| share_with | %username% |
| share_with_displayname | %displayname% |
| file_target | /textfile0.txt |
| path | /textfile0.txt |
| permissions | share,read,update |
| uid_owner | %username% |
| displayname_owner | %displayname% |
| item_type | file |
| mimetype | text/plain |
| storage_id | ANY_VALUE |
| share_type | user |
And the content of file "/textfile0.txt" for user "Brian" should be "ownCloud test text file 0"
Examples:
| ocs_api_version | ocs_status_code |
| 1 | 100 |
| 2 | 200 |

Scenario Outline: accept a share using the share Id
Given parameter "shareapi_auto_accept_share" of app "core" has been set to "yes"
And using OCS API version "<ocs_api_version>"
And user "Alice" has uploaded file with content "ownCloud test text file 0" to "/textfile0.txt"
When user "Alice" shares file "textfile0.txt" with user "Brian" using the sharing API
And user "Brian" accepts share with ID "%last_share_id%" using the sharing API
Then the OCS status code should be "<ocs_status_code>"
And the HTTP status code should be "200"
And user "Brian" should see the following elements
| /textfile0.txt |
And the sharing API should report to user "Brian" that these shares are in the accepted state
| path |
| /textfile0.txt |
Examples:
| ocs_api_version | ocs_status_code |
| 1 | 100 |
| 2 | 200 |

Scenario Outline: decline a share using the share Id
Given using OCS API version "<ocs_api_version>"
And user "Alice" has uploaded file with content "ownCloud test text file 0" to "/textfile0.txt"
When user "Alice" shares file "textfile0.txt" with user "Brian" using the sharing API
And user "Brian" declines share with ID "%last_share_id%" using the sharing API
Then the OCS status code should be "<ocs_status_code>"
And the HTTP status code should be "200"
And user "Brian" should not see the following elements
| /textfile0.txt |
And the sharing API should report to user "Brian" that these shares are in the declined state
| path |
| /textfile0.txt |
Examples:
| ocs_api_version | ocs_status_code |
| 1 | 100 |
| 2 | 200 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
@api @files_sharing-app-required
Feature: share access by ID

Background:
Given the administrator has set the default folder for received shares to "Shares"
And auto-accept shares has been disabled
And these users have been created with default attributes and without skeleton files:
| username |
| Alice |
| Brian |


Scenario Outline: Get a share with a valid share ID
Given using OCS API version "<ocs_api_version>"
And user "Alice" has uploaded file with content "ownCloud test text file 0" to "/textfile0.txt"
When user "Alice" shares file "textfile0.txt" with user "Brian" using the sharing API
And user "Brian" accepts share "/textfile0.txt" offered by user "Alice" using the sharing API
And user "Alice" gets share with id "%last_share_id%" using the sharing API
Then the OCS status code should be "<ocs_status_code>"
And the HTTP status code should be "200"
And the fields of the last response to user "Alice" sharing with user "Brian" should include
| share_with | %username% |
| share_with_displayname | %displayname% |
| file_target | /Shares/textfile0.txt |
| path | /textfile0.txt |
| permissions | share,read,update |
| uid_owner | %username% |
| displayname_owner | %displayname% |
| item_type | file |
| mimetype | text/plain |
| storage_id | ANY_VALUE |
| share_type | user |
And the content of file "/Shares/textfile0.txt" for user "Brian" should be "ownCloud test text file 0"
Examples:
| ocs_api_version | ocs_status_code |
| 1 | 100 |
| 2 | 200 |


Scenario Outline: Get a share with an invalid share id
Given using OCS API version "<ocs_api_version>"
And user "Alice" gets share with id "<share_id>" using the sharing API
Then the OCS status code should be "404"
And the HTTP status code should be "<http_status_code>"
And the API should not return any data
Examples:
| ocs_api_version | share_id | http_status_code |
| 1 | 2333311 | 200 |
| 2 | 2333311 | 404 |
| 1 | helloshare | 200 |
| 2 | helloshare | 404 |
| 1 | $#@r3 | 200 |
| 2 | $#@r3 | 404 |


Scenario Outline: accept a share using the share Id
Given using OCS API version "<ocs_api_version>"
And user "Alice" has uploaded file with content "ownCloud test text file 0" to "/textfile0.txt"
When user "Alice" shares file "textfile0.txt" with user "Brian" using the sharing API
And user "Brian" accepts share with ID "%last_share_id%" using the sharing API
Then the OCS status code should be "<ocs_status_code>"
And the HTTP status code should be "200"
And user "Brian" should see the following elements
| /Shares/textfile0.txt |
And the sharing API should report to user "Brian" that these shares are in the accepted state
| path |
| /Shares/textfile0.txt |
Examples:
| ocs_api_version | ocs_status_code |
| 1 | 100 |
| 2 | 200 |


Scenario Outline: accept a share using the invalid share Id
Given parameter "shareapi_auto_accept_share" of app "core" has been set to "yes"
And using OCS API version "<ocs_api_version>"
When user "Brian" accepts share with ID "<share_id>" using the sharing API
Then the OCS status code should be "404"
And the HTTP status code should be "<http_status_code>"
And the API should not return any data
Examples:
| ocs_api_version | share_id | http_status_code |
| 1 | 2333311 | 200 |
| 2 | 2333311 | 404 |
| 1 | helloshare | 200 |
| 2 | helloshare | 404 |
| 1 | $#@r3 | 200 |
| 2 | $#@r3 | 404 |
| 1 | 0 | 200 |
| 2 | 0 | 404 |


Scenario Outline: accept a share using empty share Id
Given parameter "shareapi_auto_accept_share" of app "core" has been set to "yes"
And using OCS API version "<ocs_api_version>"
When user "Brian" accepts share with ID "" using the sharing API
Then the OCS status code should be "<ocs_status_code>"
And the HTTP status code should be "<http_status_code>"
And the API should not return any data
Examples:
| ocs_api_version | http_status_code | ocs_status_code |
| 1 | 200 | 999 |
| 2 | 500 | 500 |



Scenario Outline: decline a share using the share Id
Given using OCS API version "<ocs_api_version>"
And user "Alice" has uploaded file with content "ownCloud test text file 0" to "/textfile0.txt"
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 "Brian" declines share with ID "%last_share_id%" using the sharing API
Then the OCS status code should be "<ocs_status_code>"
And the HTTP status code should be "200"
And user "Brian" should not see the following elements
| /Shares/textfile0.txt |
And the sharing API should report to user "Brian" that these shares are in the declined state
| path |
| /textfile0.txt |
Examples:
| ocs_api_version | ocs_status_code |
| 1 | 100 |
| 2 | 200 |


Scenario Outline: decline a share using a invalid share Id
Given parameter "shareapi_auto_accept_share" of app "core" has been set to "yes"
And using OCS API version "<ocs_api_version>"
When user "Brian" declines share with ID "<share_id>" using the sharing API
Then the OCS status code should be "404"
And the HTTP status code should be "<http_status_code>"
And the API should not return any data
Examples:
| ocs_api_version | share_id | http_status_code |
| 1 | 2333311 | 200 |
| 2 | 2333311 | 404 |
| 1 | helloshare | 200 |
| 2 | helloshare | 404 |
| 1 | $#@r3 | 200 |
| 2 | $#@r3 | 404 |
| 1 | 0 | 200 |
| 2 | 0 | 404 |


Scenario Outline: decline a share using empty share Id
Given parameter "shareapi_auto_accept_share" of app "core" has been set to "yes"
And using OCS API version "<ocs_api_version>"
When user "Brian" declines share with ID "" using the sharing API
Then the OCS status code should be "<ocs_status_code>"
And the HTTP status code should be "<http_status_code>"
And the API should not return any data
Examples:
| ocs_api_version | http_status_code | ocs_status_code |
| 1 | 200 | 999 |
| 2 | 500 | 500 |
8 changes: 8 additions & 0 deletions tests/acceptance/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2687,6 +2687,14 @@ public function substituteInLineCodes(
"getCommentUrlRegExp"
],
"parameter" => []
],
[
"code" => "%last_share_id%",
"function" => [
$this,
"getLastShareId"
],
"parameter" => []
]
];
if ($user !== null) {
Expand Down
66 changes: 66 additions & 0 deletions tests/acceptance/features/bootstrap/Sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -1682,6 +1682,19 @@ public function getLastShareIdOf($user) {
return $id;
}

/**
* Retrieves the id of the last shared file
*
* @return string|null
*/
public function getLastShareId() {
if ($this->lastShareData) {
return $this->lastShareData->data[0]->id;
} else {
return null;
}
}

/**
* Retrieves all the shares of the respective user
*
Expand Down Expand Up @@ -2634,6 +2647,34 @@ public function userReactsToShareOfferedBy($user, $action, $share, $offeredBy) {
);
}

/**
* @When /^user "([^"]*)" (declines|accepts) share with ID "([^"]*)" using the sharing API$/
*
* @param string $user
* @param string $action
* @param string $share_id
*
* @return void
* @throws \Exception
*/
public function userReactsToShareWithShareIDOfferedBy($user, $action, $share_id) {
$user = $this->getActualUsername($user);

$shareId = $this->substituteInLineCodes($share_id, $user);

$url = "/apps/files_sharing/api/v{$this->sharingApiVersion}" .
"/shares/pending/$shareId";
if (\substr($action, 0, 7) === "decline") {
$httpRequestMethod = "DELETE";
} elseif (\substr($action, 0, 6) === "accept") {
$httpRequestMethod = "POST";
}

$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user, $httpRequestMethod, $url, null
);
}

/**
* @Given /^user "([^"]*)" has (declined|accepted) share "([^"]*)" offered by user "([^"]*)"$/
*
Expand Down Expand Up @@ -2787,6 +2828,31 @@ public function administratorAddsGroupToExcludeFromReceivingSharesList($group) {
}
}

/**
* @When user :user gets share with id :share using the sharing API
*
* @param $user
* @param $share_id
*
* @return void
*/
public function userGetsTheLastShareWithTheShareIdUsingTheSharingApi($user, $share_id) {
$user = $this->getActualUsername($user);
$share_id = $this->substituteInLineCodes($share_id, $user);
$url = $this->getSharesEndpointPath("/$share_id");

$this->response = OcsApiHelper::sendRequest(
$this->getBaseUrl(),
$user,
$this->getPasswordForUser($user),
"GET",
$url,
[],
$this->ocsApiVersion
);
return $this->response;
}

/**
*
* @param string $user
Expand Down

0 comments on commit 84df91a

Please sign in to comment.