From 6d5a021a21ea8373d09ba53e24d864cc1a5055d6 Mon Sep 17 00:00:00 2001 From: Viktor Scharf Date: Wed, 2 Oct 2024 17:45:26 +0200 Subject: [PATCH] delete connection tests --- tests/acceptance/TestHelpers/OcmHelper.php | 34 ++++ tests/acceptance/bootstrap/OcmContext.php | 66 ++++++ .../acceptance/bootstrap/SharingNgContext.php | 25 +-- .../apiOcm/deleteFederatedConnections.feature | 137 +++++++++++++ .../acceptance/features/apiOcm/share.feature | 188 +++++++++++++++++- 5 files changed, 425 insertions(+), 25 deletions(-) create mode 100755 tests/acceptance/features/apiOcm/deleteFederatedConnections.feature diff --git a/tests/acceptance/TestHelpers/OcmHelper.php b/tests/acceptance/TestHelpers/OcmHelper.php index 5432d293f77..fdd95f5714a 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..d9b83a5ec72 100644 --- a/tests/acceptance/bootstrap/OcmContext.php +++ b/tests/acceptance/bootstrap/OcmContext.php @@ -230,6 +230,25 @@ 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, $ocmUserName): array { + $this->userFindsAcceptedUsers($user); + $responseArray = ($this->featureContext->getJsonDecodedResponse($this->featureContext->getResponse())); + foreach ($responseArray as $findUser) { + if (strpos($findUser["display_name"], $ocmUserName) !== false) { + return $findUser; + } + } + throw new \Exception("User with name '{$ocmUserName}' not found in the accepted users."); + } + /** * @param string $user * @@ -268,4 +287,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 deliting 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..80e7574b6fb 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,7 +282,7 @@ public function sendShareInvitation(string $user, array $shareInfo, string $file $shareeId = ""; if ($shareType === "user") { $shareeId = $this->featureContext->getAttributeOfCreatedUser($sharee, 'id'); - if ($isFederated) { + if ($shareInfo['federatedServer']) { $shareeId = base64_encode($shareeId . $shareInfo['federatedServer']); } } elseif ($shareType === "group") { @@ -379,6 +378,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 +414,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 +431,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/features/apiOcm/deleteFederatedConnections.feature b/tests/acceptance/features/apiOcm/deleteFederatedConnections.feature new file mode 100755 index 00000000000..ddd51322fa8 --- /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: users deletes 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: user cannot find the federated user if the user has deleted the 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: user cannot find share if he has deleted the 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: user cannot find share if the user has deleted the 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..f7d3a077888 100755 --- a/tests/acceptance/features/apiOcm/share.feature +++ b/tests/acceptance/features/apiOcm/share.feature @@ -50,11 +50,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", @@ -91,6 +95,93 @@ Feature: an user shares resources usin ScienceMesh application } """ + + Scenario: users shares file to federation users after receiver accepted invitation + 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 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 | textfile.txt | + | space | Personal | + | sharee | Brian | + | shareType | user | + | permissionsRole | Viewer | + | federatedServer | @federation-ocis-server:10200 | + Then the HTTP status code should be "200" + When using server "REMOTE" + And 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": 1, + "maxItems": 1, + "items": { + "type": "object", + "required": [ + "@UI.Hidden", + "@client.synchronize", + "createdBy", + "name" + ], + "properties": { + "@UI.Hidden": { + "type": "boolean", + "enum": [ + false + ] + }, + "@client.synchronize": { + "type": "boolean", + "enum": [ + false + ] + }, + "createdBy": { + "type": "object", + "required": [ + "user" + ], + "properties": { + "user": { + "type": "object", + "required": [ + "displayName", + "id" + ], + "properties": { + "displayName": { + "type": "string", + "const": "Alice Hansen" + }, + "id": { + "type": "string", + "pattern": "^%federated_user_id_pattern%$" + } + } + } + } + }, + "name": { + "const": "textfile.txt" + } + } + } + } + } + } + """ + @issue-9534 Scenario: users shares folder to federation users after accepting invitation Given using server "LOCAL" @@ -132,11 +223,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", @@ -171,3 +266,88 @@ Feature: an user shares resources usin ScienceMesh application } } """ + + + Scenario: users shares file to federation users 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 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 | textfile.txt | + | space | Personal | + | sharee | Alice | + | shareType | user | + | permissionsRole | Viewer | + | 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 + 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": 1, + "maxItems": 1, + "items": { + "type": "object", + "required": [ + "@UI.Hidden", + "@client.synchronize", + "createdBy", + "name" + ], + "properties": { + "@UI.Hidden": { + "type": "boolean", + "enum": [ + false + ] + }, + "@client.synchronize": { + "type": "boolean", + "enum": [ + false + ] + }, + "createdBy": { + "type": "object", + "required": [ + "user" + ], + "properties": { + "user": { + "type": "object", + "required": [ + "displayName", + "id" + ], + "properties": { + "displayName": { + "const": "Brian Murphy" + }, + "id": { + "type": "string", + "pattern": "^%federated_user_id_pattern%$" + } + } + } + } + }, + "name": { + "const": "textfile.txt" + } + } + } + } + } + } + """