diff --git a/tests/acceptance/TestHelpers/OcmHelper.php b/tests/acceptance/TestHelpers/OcmHelper.php index 5432d293f77..d838752143b 100644 --- a/tests/acceptance/TestHelpers/OcmHelper.php +++ b/tests/acceptance/TestHelpers/OcmHelper.php @@ -170,4 +170,38 @@ public static function listInvite( self::getRequestHeaders() ); } + + /** + * @param string $baseUrl + * @param string $xRequestId + * @param string $user + * @param string $password + * @param string $userId + * @param string $idp + * + * @return ResponseInterface + * @throws GuzzleException + */ + public static function deleteConnection( + string $baseUrl, + string $xRequestId, + string $user, + string $password, + string $userId, + string $idp + ): ResponseInterface { + $url = self::getFullUrl($baseUrl, 'delete-accepted-user'); + $body = [ + "idp" => $idp, + "user_id" => $userId + ]; + return HttpRequestHelper::delete( + $url, + $xRequestId, + $user, + $password, + self::getRequestHeaders(), + \json_encode($body) + ); + } } diff --git a/tests/acceptance/bootstrap/OcmContext.php b/tests/acceptance/bootstrap/OcmContext.php index bf41e1b54b7..102ea6aef06 100644 --- a/tests/acceptance/bootstrap/OcmContext.php +++ b/tests/acceptance/bootstrap/OcmContext.php @@ -230,6 +230,24 @@ public function userFindsAcceptedUsers(string $user): void { $this->featureContext->setResponse($this->findAcceptedUsers($user)); } + /** + * + * @param string $user + * @param string $ocmUserName + * + * @return array + * @throws GuzzleException + */ + public function getAcceptedUserByName(string $user, string $ocmUserName): array { + $users = ($this->featureContext->getJsonDecodedResponse($this->findAcceptedUsers($user))); + foreach ($users as $user) { + if (strpos($user["display_name"], $ocmUserName) !== false) { + return $user; + } + } + throw new \Exception("Could not find user with name '{$ocmUserName}' in the accepted users list."); + } + /** * @param string $user * @@ -268,4 +286,51 @@ public function userListsCreatedInvitations(string $user): void { public function theUserWaitsForTokenToExpire(int $number): void { \sleep($number); } + + /** + * @When user :user deletes federated connection with user :ocmUser using the Graph API + * + * @param string $user + * @param string $ocmUser + * + * @return void + * @throws GuzzleException + */ + public function userDeletesFederatedConnectionWithUserUsingTheGraphApi(string $user, string $ocmUser): void { + $this->featureContext->setResponse($this->deleteConnection($user, $ocmUser)); + } + + /** + * @When user :user has deleted federated connection with user :ocmUser + * + * @param string $user + * @param string $ocmUser + * + * @return void + * @throws GuzzleException + */ + public function userHasDeletedFederatedConnectionWithUser(string $user, string $ocmUser): void { + $response = $this->deleteConnection($user, $ocmUser); + $this->featureContext->theHTTPStatusCodeShouldBe(200, "failed while deleting connection with user $ocmUser", $response); + } + + /** + * @param string $user + * @param string $ocmUser + * + * @return ResponseInterface + * @throws GuzzleException + */ + public function deleteConnection(string $user, string $ocmUser): ResponseInterface { + $ocmUser = $this->getAcceptedUserByName($user, $ocmUser); + return OcmHelper::deleteConnection( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $user, + $this->featureContext->getPasswordForUser($user), + $ocmUser['user_id'], + $ocmUser['idp'] + ); + } + } diff --git a/tests/acceptance/bootstrap/SharingNgContext.php b/tests/acceptance/bootstrap/SharingNgContext.php index 394cf9626c0..8e00d7cb3ba 100644 --- a/tests/acceptance/bootstrap/SharingNgContext.php +++ b/tests/acceptance/bootstrap/SharingNgContext.php @@ -239,7 +239,6 @@ public function userTriesToListThePermissionsOfSpaceUsingPermissionsEndpointOfTh * @param string $user * @param array $shareInfo * @param string|null $fileId - * @param bool $isFederated * * @return ResponseInterface * @@ -247,7 +246,7 @@ public function userTriesToListThePermissionsOfSpaceUsingPermissionsEndpointOfTh * @throws GuzzleException * @throws Exception */ - public function sendShareInvitation(string $user, array $shareInfo, string $fileId = null, $isFederated = false): ResponseInterface { + public function sendShareInvitation(string $user, array $shareInfo, string $fileId = null): ResponseInterface { if ($shareInfo['space'] === 'Personal' || $shareInfo['space'] === 'Shares') { $space = $this->spacesContext->getSpaceByName($user, $shareInfo['space']); } else { @@ -283,8 +282,8 @@ public function sendShareInvitation(string $user, array $shareInfo, string $file $shareeId = ""; if ($shareType === "user") { $shareeId = $this->featureContext->getAttributeOfCreatedUser($sharee, 'id'); - if ($isFederated) { - $shareeId = base64_encode($shareeId . $shareInfo['federatedServer']); + if (isset($shareInfo['federatedServer'])) { + $shareeId = ($this->featureContext->ocmContext->getAcceptedUserByName($user, $sharee))['user_id']; } } elseif ($shareType === "group") { $shareeId = $this->featureContext->getAttributeOfCreatedGroup($sharee, 'id'); @@ -352,6 +351,9 @@ public function sendDriveShareInvitation(string $user, TableNode $table): Respon $shareeId = ""; if ($shareType === "user") { $shareeId = $this->featureContext->getAttributeOfCreatedUser($sharee, 'id'); + if (isset($shareInfo['federatedServer'])) { + $shareeId = ($this->featureContext->ocmContext->getAcceptedUserByName($user, $sharee))['user_id']; + } } elseif ($shareType === "group") { $shareeId = $this->featureContext->getAttributeOfCreatedGroup($sharee, 'id'); } @@ -379,6 +381,7 @@ public function sendDriveShareInvitation(string $user, TableNode $table): Respon /** * @Given /^user "([^"]*)" has sent the following resource share invitation:$/ + * @Given /^user "([^"]*)" has sent the following resource share invitation to federated user:$/ * * @param string $user * @param TableNode $table @@ -414,6 +417,7 @@ public function userHasSentTheFollowingShareShareInvitation(string $user, TableN /** * @When /^user "([^"]*)" sends the following resource share invitation using the Graph API:$/ * @When /^user "([^"]*)" tries to send the following resource share invitation using the Graph API:$/ + * @When /^user "([^"]*)" sends the following resource share invitation to federated user using the Graph API:$/ * * @param string $user * @param TableNode $table @@ -430,24 +434,6 @@ public function userSendsTheFollowingResourceShareInvitationUsingTheGraphApi(str ); } - /** - * @When /^user "([^"]*)" sends the following resource share invitation to federated user using the Graph API:$/ - * - * @param string $user - * @param TableNode $table - * - * @return void - * @throws Exception - * @throws GuzzleException - */ - public function userSendsTheFollowingResourceShareInvitationTofederatedUserUsingTheGraphApi(string $user, TableNode $table): void { - $rows = $table->getRowsHash(); - Assert::assertArrayHasKey("resource", $rows, "'resource' should be provided in the data-table while sharing a resource"); - $this->featureContext->setResponse( - $this->sendShareInvitation($user, $rows, null, true) - ); - } - /** * @When /^user "([^"]*)" sends the following space share invitation using permissions endpoint of the Graph API:$/ * diff --git a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md index 1bcffbf70e2..ce88480b9f6 100644 --- a/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md +++ b/tests/acceptance/expected-failures-localAPI-on-OCIS-storage.md @@ -256,10 +256,19 @@ The expected failures in this file are from features in the owncloud/ocis repo. #### [OCM. admin cannot get federated users if he hasn't connection with them ](https://github.com/owncloud/ocis/issues/9829) -tests/acceptance/features/apiOcm/searchFederationUsers.feature - - [apiOcm/searchFederationUsers.feature:429](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiOcm/searchFederationUsers.feature#L429) - [apiOcm/searchFederationUsers.feature:601](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiOcm/searchFederationUsers.feature#L601) + +#### [OCM. federated connection is not dropped when one of the users deletes the connection](https://github.com/owncloud/ocis/issues/10216) + +- [apiOcm/deleteFederatedConnections.feature:39](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiOcm/deleteFederatedConnections.feature#L39) +- [apiOcm/deleteFederatedConnections.feature:66](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiOcm/deleteFederatedConnections.feature#L66) + + +#### [OCM. server crash after deleting share for ocm user](https://github.com/owncloud/ocis/issues/10213) + +- [apiOcm/deleteFederatedConnections.feature:103](https://github.com/owncloud/ocis/blob/master/tests/acceptance/features/apiOcm/deleteFederatedConnections.feature#L103) + Note: always have an empty line at the end of this file. The bash script that processes this file requires that the last line has a newline on the end. diff --git a/tests/acceptance/features/apiOcm/deleteFederatedConnections.feature b/tests/acceptance/features/apiOcm/deleteFederatedConnections.feature new file mode 100755 index 00000000000..39f6da2584c --- /dev/null +++ b/tests/acceptance/features/apiOcm/deleteFederatedConnections.feature @@ -0,0 +1,137 @@ +@ocm +Feature: delete federated connections + As a user + I want to delete federated connections if they are no longer needed + + Background: + Given user "Alice" has been created with default attributes and without skeleton files + And using server "REMOTE" + And user "Brian" has been created with default attributes and without skeleton files + + + Scenario: federated user deletes the federated connection + Given using server "LOCAL" + And "Alice" has created the federation share invitation + And using server "REMOTE" + And "Brian" has accepted invitation + When user "Brian" deletes federated connection with user "Alice" using the Graph API + Then the HTTP status code should be "200" + When user "Brian" searches for federated user "alice" using Graph API + Then the HTTP status code should be "200" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "value" + ], + "properties": { + "value": { + "type": "array", + "minItems": 0, + "maxItems": 0 + } + } + } + """ + + @issue-10216 + Scenario: local user should not be able to find federated user after federated user has deleted connection + Given using server "LOCAL" + And "Alice" has created the federation share invitation + And using server "REMOTE" + And "Brian" has accepted invitation + And user "Brian" has deleted federated connection with user "Alice" + And using server "LOCAL" + When user "Alice" searches for federated user "brian" using Graph API + Then the HTTP status code should be "200" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "value" + ], + "properties": { + "value": { + "type": "array", + "minItems": 0, + "maxItems": 0 + } + } + } + """ + + @issue-10216 + Scenario: federated user should not be able to find federated share after federated user has deleted connection + Given using server "LOCAL" + And "Alice" has created the federation share invitation + And using server "REMOTE" + And "Brian" has accepted invitation + And using server "LOCAL" + And user "Alice" has created folder "folderToShare" + And user "Alice" has sent the following resource share invitation to federated user: + | resource | folderToShare | + | space | Personal | + | sharee | Brian | + | shareType | user | + | permissionsRole | Viewer | + | federatedServer | @federation-ocis-server:10200 | + And using server "REMOTE" + When user "Brian" deletes federated connection with user "Alice" using the Graph API + Then the HTTP status code should be "200" + When user "Brian" lists the shares shared with him without retry using the Graph API + Then the HTTP status code should be "200" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "value" + ], + "properties": { + "value": { + "type": "array", + "minItems": 0, + "maxItems": 0, + } + } + } + """ + + @issue-10213 + Scenario: federated user should not be able to find federated share after local user has deleted connection + Given using server "LOCAL" + And "Alice" has created the federation share invitation + And using server "REMOTE" + And "Brian" has accepted invitation + And using server "LOCAL" + And user "Alice" has created folder "folderToShare" + And user "Alice" has sent the following resource share invitation to federated user: + | resource | folderToShare | + | space | Personal | + | sharee | Brian | + | shareType | user | + | permissionsRole | Viewer | + | federatedServer | @federation-ocis-server:10200 | + When user "Alice" deletes federated connection with user "Brian" using the Graph API + Then the HTTP status code should be "200" + And using server "REMOTE" + When user "Brian" lists the shares shared with him without retry using the Graph API + Then the HTTP status code should be "200" + And the JSON data of the response should match + """ + { + "type": "object", + "required": [ + "value" + ], + "properties": { + "value": { + "type": "array", + "minItems": 0, + "maxItems": 0, + } + } + } + """ diff --git a/tests/acceptance/features/apiOcm/share.feature b/tests/acceptance/features/apiOcm/share.feature index 97c554b4ed5..309f00c8a8d 100755 --- a/tests/acceptance/features/apiOcm/share.feature +++ b/tests/acceptance/features/apiOcm/share.feature @@ -9,15 +9,16 @@ Feature: an user shares resources usin ScienceMesh application And user "Brian" has been created with default attributes and without skeleton files @issue-9534 - Scenario: users shares folder to federation users after receiver accepted invitation + Scenario Outline: local user shares resources to federation user Given using server "LOCAL" And "Alice" has created the federation share invitation And using server "REMOTE" And "Brian" has accepted invitation And using server "LOCAL" And user "Alice" has created folder "folderToShare" + And user "Alice" has uploaded file with content "ocm test" to "/textfile.txt" When user "Alice" sends the following resource share invitation to federated user using the Graph API: - | resource | folderToShare | + | resource | | | space | Personal | | sharee | Brian | | shareType | user | @@ -50,11 +51,15 @@ Feature: an user shares resources usin ScienceMesh application "properties": { "@UI.Hidden": { "type": "boolean", - "enum": [false] + "enum": [ + false + ] }, "@client.synchronize": { "type": "boolean", - "enum": [false] + "enum": [ + false + ] }, "createdBy": { "type": "object", @@ -82,7 +87,7 @@ Feature: an user shares resources usin ScienceMesh application } }, "name": { - "const": "folderToShare" + "const": "" } } } @@ -90,16 +95,21 @@ Feature: an user shares resources usin ScienceMesh application } } """ + Examples: + | resource | + | folderToShare | + | textfile.txt | @issue-9534 - Scenario: users shares folder to federation users after accepting invitation + Scenario Outline: federation user shares resource to local user after accepting invitation Given using server "LOCAL" And "Alice" has created the federation share invitation And using server "REMOTE" And "Brian" has accepted invitation And user "Brian" has created folder "folderToShare" + And user "Brian" has uploaded file with content "ocm test" to "/textfile.txt" When user "Brian" sends the following resource share invitation to federated user using the Graph API: - | resource | folderToShare | + | resource | | | space | Personal | | sharee | Alice | | shareType | user | @@ -107,7 +117,7 @@ Feature: an user shares resources usin ScienceMesh application | federatedServer | @ocis-server:9200 | Then the HTTP status code should be "200" When using server "LOCAL" - And user "Alice" lists the shares shared with her using the Graph API + And user "Alice" lists the shares shared with her without retry using the Graph API Then the HTTP status code should be "200" And the JSON data of the response should match """ @@ -132,11 +142,15 @@ Feature: an user shares resources usin ScienceMesh application "properties": { "@UI.Hidden": { "type": "boolean", - "enum": [false] + "enum": [ + false + ] }, "@client.synchronize": { "type": "boolean", - "enum": [false] + "enum": [ + false + ] }, "createdBy": { "type": "object", @@ -163,7 +177,7 @@ Feature: an user shares resources usin ScienceMesh application } }, "name": { - "const": "folderToShare" + "const": "" } } } @@ -171,3 +185,7 @@ Feature: an user shares resources usin ScienceMesh application } } """ + Examples: + | resource | + | folderToShare | + | textfile.txt |