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

[tests-only] tests: refactor test script for removing permission from share #8134

Merged
merged 2 commits into from
Jan 9, 2024
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
40 changes: 1 addition & 39 deletions tests/TestHelpers/GraphHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1540,44 +1540,6 @@ public static function getPermissionsList(
);
}

/**
* @param string $baseUrl
* @param string $xRequestId
* @param string $sharer
* @param string $userIdOfShareeUser this is a uuidv4 of sharee
* @param string $password
* @param string $spaceId
* @param string $itemId
* @param string $shareType (user|group)
*
* @return string
*
* @throws GuzzleException
* @throws \JsonException
*/
public static function getSharePermissionId(
string $baseUrl,
string $xRequestId,
string $sharer,
string $userIdOfShareeUser,
string $password,
string $spaceId,
string $itemId,
string $shareType
): string {
$response = self::getPermissionsList($baseUrl, $xRequestId, $sharer, $password, $spaceId, $itemId);
$permissionList = json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
foreach ($permissionList["value"] as $value) {
if ($value["grantedToV2"][$shareType]["id"] === $userIdOfShareeUser) {
return $value["id"];
}
}
throw new \Exception(
__METHOD__
. " Cannot find share permission id for user"
);
}

/**
* Get the role id by name
*
Expand Down Expand Up @@ -1787,7 +1749,7 @@ public static function setPassword(
*
* @throws GuzzleException
*/
public static function removeSharePermission(
public static function deleteSharePermission(
string $baseUrl,
string $xRequestId,
string $user,
Expand Down
34 changes: 33 additions & 1 deletion tests/acceptance/features/bootstrap/Sharing.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ trait Sharing {
*/
private array $shareNgCreatedLinkShares = [];

/**
* @var array
*/
private array $shareNgCreatedUserGroupShares = [];

/**
* @return string
*/
Expand Down Expand Up @@ -119,6 +124,22 @@ public function shareNgGetLastCreatedLinkShare():?ResponseInterface {
return \end($this->shareNgCreatedLinkShares);
}

/**
* @param ResponseInterface $response
*
* @return void
*/
public function shareNgAddToCreatedUserGroupShares(ResponseInterface $response): void {
$this->shareNgCreatedUserGroupShares[] = $response;
}

/**
* @return ResponseInterface|null
*/
public function shareNgGetLastCreatedUserGroupShare():?ResponseInterface {
return \end($this->shareNgCreatedUserGroupShares);
}

/**
* @param string $sharer
* @param SimpleXMLElement $shareData
Expand Down Expand Up @@ -179,7 +200,7 @@ public function getSharesEndpointPath(?string $postfix = ''):string {
public function shareNgGetLastCreatedLinkShareID(): string {
$lastResponse = $this->shareNgGetLastCreatedLinkShare();
if (!isset($this->getJsonDecodedResponse($lastResponse)['id'])) {
throw new Error('Response did not contain share id ' . $this->getJsonDecodedResponse($lastResponse)['id'] . ' for the created public link');
Copy link
Contributor Author

@SwikritiT SwikritiT Jan 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed this because if $this->getJsonDecodedResponse($lastResponse)['id'] is not set it'll probably come undefined. so the error message might not make use of that

throw new Error('Response did not contain share id for the created public link');
}
return $this->getJsonDecodedResponse($lastResponse)['id'];
}
Expand All @@ -196,6 +217,17 @@ public function shareNgGetLastCreatedLinkShareToken(): string {
return substr(strrchr($last_created_link_webURL, "/"), 1);
}

/**
* @return string
*/
public function shareNgGetLastCreatedUserGroupShareID(): string {
$lastResponse = $this->shareNgGetLastCreatedUserGroupShare();
if (!isset($this->getJsonDecodedResponse($lastResponse)['value'][0]['id'])) {
throw new Error('Response did not contain share id for the last created share.');
}
return $this->getJsonDecodedResponse($lastResponse)['value'][0]['id'];
}

/**
* Split given permissions string each separated with "," into array of strings
*
Expand Down
22 changes: 7 additions & 15 deletions tests/acceptance/features/bootstrap/SharingNgContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function sendShareInvitation(string $user, TableNode $table): ResponseInt
$permission = $rows['permission'] ?? null;
$expireDate = $rows["expireDate"] ?? null;

return GraphHelper::sendSharingInvitation(
$response = GraphHelper::sendSharingInvitation(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$user,
Expand All @@ -165,6 +165,10 @@ public function sendShareInvitation(string $user, TableNode $table): ResponseInt
$permission,
$expireDate
);
if ($response->getStatusCode() === 200) {
$this->featureContext->shareNgAddToCreatedUserGroupShares($response);
}
return $response;
}

/**
Expand Down Expand Up @@ -351,21 +355,9 @@ public function userRemovesSharePermissionOfUserFromResourceOfSpaceUsingGraphAPI
$itemId = ($resourceType === 'folder')
? $this->spacesContext->getResourceId($sharer, $space, $resource)
: $this->spacesContext->getFileId($sharer, $space, $resource);
$userIdOfSharee = ($shareType === 'user')
? $this->featureContext->getUserIdByUserName($sharee)
: $this->featureContext->getGroupIdByGroupName($sharee);
$permId = GraphHelper::getSharePermissionId(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$sharer,
$userIdOfSharee,
$this->featureContext->getPasswordForUser($sharer),
$spaceId,
$itemId,
$shareType
);
$permId = $this->featureContext->shareNgGetLastCreatedUserGroupShareID();
$this->featureContext->setResponse(
GraphHelper::removeSharePermission(
GraphHelper::deleteSharePermission(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
$sharer,
Expand Down