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

Test remote shares ocs endpoint #34641

Merged
merged 2 commits into from
Feb 28, 2019
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
20 changes: 20 additions & 0 deletions tests/TestHelpers/SharingHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,24 @@ public static function getPermissionSum($permissions) {
}
return $permissionSum;
}

/**
*
* @param \SimpleXMLElement $responseXmlObject
* @param string $errorMessage
*
* @throws \Exception
*
* @return string
*/
public static function getLastShareIdFromResponse(
$responseXmlObject, $errorMessage = "cannot find share id in response"
) {
$xmlPart = $responseXmlObject->xpath("//data/element[last()]/id");

if (!\is_array($xmlPart) || (\count($xmlPart) === 0)) {
throw new \Exception($errorMessage);
}
return $xmlPart[0]->__toString();
}
}
47 changes: 47 additions & 0 deletions tests/acceptance/features/apiFederation/federated.feature
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,53 @@ Feature: federated
| mountpoint | {{TemporaryMountPointName#/textfile0.txt}} |
| accepted | 0 |

Scenario: Remote sharee requests information of only one share
Given user "user0" from server "REMOTE" has shared "/textfile0.txt" with user "user1" from server "LOCAL"
And user "user1" from server "LOCAL" has accepted the last pending share
When user "user1" retrieves the information of the last federated cloud share using the sharing API
Then the OCS status code should be "100"
And the HTTP status code should be "200"
And the fields of the last response should include
| id | A_NUMBER |
| remote | REMOTE |
| remote_id | A_NUMBER |
| share_token | A_TOKEN |
| name | /textfile0.txt |
| owner | user0 |
| user | user1 |
| mountpoint | /textfile0 (2).txt |
| accepted | 1 |
| type | file |
| permissions | 27 |

@issue-34636
Scenario: Remote sharee requests information of only one share before accepting it
Given user "user0" from server "REMOTE" has shared "/textfile0.txt" with user "user1" from server "LOCAL"
When user "user1" retrieves the information of the last pending federated cloud share using the sharing API
Then the HTTP status code should be "200"
And the body of the response should be empty
#And the OCS status code should be "100"
#And the fields of the last response should include
# | id | A_NUMBER |
# | remote | REMOTE |
# | remote_id | A_NUMBER |
# | share_token | A_TOKEN |
# | name | /textfile0.txt |
# | owner | user0 |
# | user | user1 |
# | mountpoint | {{TemporaryMountPointName#/textfile0.txt}} |
# | accepted | 0 |

Scenario: sending a GET request to a pending remote share is not valid
When user "user1" sends HTTP method "GET" to OCS API endpoint "/apps/files_sharing/api/v1/remote_shares/pending/12"
Then the HTTP status code should be "405"
And the body of the response should be empty

Scenario: sending a GET request to a not existing remote share
When user "user1" sends HTTP method "GET" to OCS API endpoint "/apps/files_sharing/api/v1/remote_shares/9999999999"
Then the OCS status code should be "404"
And the HTTP status code should be "200"

Scenario: accept a pending remote share
Given user "user0" from server "REMOTE" has shared "/textfile0.txt" with user "user1" from server "LOCAL"
When user "user1" from server "LOCAL" accepts the last pending share using the sharing API
Expand Down
11 changes: 11 additions & 0 deletions tests/acceptance/features/bootstrap/BasicStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -1941,6 +1941,17 @@ public function theFileShouldNotExistInTheServerRoot($path) {
);
}

/**
* @Then the body of the response should be empty
*
* @return void
*/
public function theResponseBodyShouldBeEmpty() {
PHPUnit_Framework_Assert::assertEmpty(
$this->getResponse()->getBody()->getContents()
);
}

/**
* @param ResponseInterface|null $response
*
Expand Down
54 changes: 53 additions & 1 deletion tests/acceptance/features/bootstrap/FederationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use TestHelpers\SharingHelper;

require_once 'bootstrap.php';

Expand Down Expand Up @@ -105,7 +106,9 @@ public function userFromServerAcceptsLastPendingShareUsingTheSharingAPI($user, $
$this->userGetsTheListOfPendingFederatedCloudShares($user);
$this->featureContext->theHTTPStatusCodeShouldBe('200');
$this->featureContext->theOCSStatusCodeShouldBe('100');
$share_id = $this->featureContext->getResponseXml()->data[0]->element[0]->id;
$share_id = SharingHelper::getLastShareIdFromResponse(
$this->featureContext->getResponseXml()
);
$this->featureContext->theUserSendsToOcsApiEndpointWithBody(
'POST',
"/apps/files_sharing/api/v1/remote_shares/pending/{$share_id}",
Expand All @@ -130,6 +133,55 @@ public function userFromServerHasAcceptedLastPendingShare($user, $server) {
$this->featureContext->theOCSStatusCodeShouldBe('100');
}

/**
* @When /^user "([^"]*)" retrieves the information of the last federated cloud share using the sharing API$/
*
* @param string $user
*
* @return void
*/
public function userRetrievesInformationOfLastFederatedShare($user) {
$this->featureContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user,
'GET',
"/apps/files_sharing/api/v1/remote_shares",
null
);
$this->featureContext->theHTTPStatusCodeShouldBe('200');
$this->featureContext->theOCSStatusCodeShouldBe('100');
$share_id = SharingHelper::getLastShareIdFromResponse(
$this->featureContext->getResponseXml()
);
$this->featureContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user,
'GET',
"/apps/files_sharing/api/v1/remote_shares/{$share_id}",
null
);
}

/**
* @When /^user "([^"]*)" retrieves the information of the last pending federated cloud share using the sharing API$/
*
* @param string $user
*
* @return void
*/
public function userRetrievesInformationOfLastPendingFederatedShare($user) {
$this->userGetsTheListOfPendingFederatedCloudShares($user);
$this->featureContext->theHTTPStatusCodeShouldBe('200');
$this->featureContext->theOCSStatusCodeShouldBe('100');
$share_id = SharingHelper::getLastShareIdFromResponse(
$this->featureContext->getResponseXml()
);
$this->featureContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user,
'GET',
"/apps/files_sharing/api/v1/remote_shares/{$share_id}",
null
);
}

/**
* @When /^user "([^"]*)" gets the list of pending federated cloud shares using the sharing API$/
*
Expand Down