Skip to content

Commit

Permalink
delete connection tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ScharfViktor committed Oct 2, 2024
1 parent 2c03dd0 commit 6d5a021
Show file tree
Hide file tree
Showing 5 changed files with 425 additions and 25 deletions.
34 changes: 34 additions & 0 deletions tests/acceptance/TestHelpers/OcmHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
}
66 changes: 66 additions & 0 deletions tests/acceptance/bootstrap/OcmContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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']
);
}

}
25 changes: 4 additions & 21 deletions tests/acceptance/bootstrap/SharingNgContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,14 @@ public function userTriesToListThePermissionsOfSpaceUsingPermissionsEndpointOfTh
* @param string $user
* @param array $shareInfo
* @param string|null $fileId
* @param bool $isFederated
*
* @return ResponseInterface
*
* @throws JsonException
* @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 {
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:$/
*
Expand Down
137 changes: 137 additions & 0 deletions tests/acceptance/features/apiOcm/deleteFederatedConnections.feature
Original file line number Diff line number Diff line change
@@ -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,
}
}
}
"""
Loading

0 comments on commit 6d5a021

Please sign in to comment.