tests: fix tests

This commit is contained in:
Saw-jan
2024-11-29 16:47:02 +05:45
parent bc9c9fe58f
commit bedddc4728
9 changed files with 98 additions and 111 deletions

View File

@@ -45,6 +45,8 @@ class GraphHelper {
'Space Editor Without Versions' => '3284f2d5-0070-4ad8-ac40-c247f7c1fb27',
];
public const SHARES_SPACE_ID = 'a0ca6a90-a365-4782-871e-d44447bbc668$a0ca6a90-a365-4782-871e-d44447bbc668';
/**
* @return string[]
*/

View File

@@ -504,35 +504,6 @@ class WebDavHelper {
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}
/**
*
* @param string $baseUrl
* @param string $user
* @param string $password
* @param string $xRequestId
*
* @return string
* @throws GuzzleException
* @throws Exception
*/
public static function getSharesSpaceIdForUser(string $baseUrl, string $user, string $password, string $xRequestId): string {
if (\array_key_exists($user, self::$spacesIdRef) && \array_key_exists("virtual", self::$spacesIdRef[$user])) {
return self::$spacesIdRef[$user]["virtual"];
}
$response = GraphHelper::getMySpaces($baseUrl, $user, $password, '', $xRequestId);
$body = HttpRequestHelper::getJsonDecodedResponseBodyContent($response);
$spaceId = null;
foreach ($body->value as $spaces) {
if ($spaces->driveType === "virtual") {
$spaceId = $spaces->id;
break;
}
}
return $spaceId;
}
/**
* fetches personal space id for provided user
*
@@ -558,10 +529,18 @@ class WebDavHelper {
$user,
$password
);
$bodyContents = $response->getBody()->getContents();
$json = \json_decode($bodyContents);
Assert::assertEquals(200, $response->getStatusCode(), "Cannot list drives for user '$user'");
$personalSpaceId = '';
if ($json === null) {
$drives = HttpRequestHelper::getJsonDecodedResponseBodyContent($response);
foreach ($drives->value as $drive) {
if ($drive->driveType === "personal") {
$personalSpaceId = $drive->id;
break;
}
}
if (!$personalSpaceId) {
// the graph endpoint did not give a useful answer
// try getting the information from the webdav endpoint
$fullUrl = "$trimmedBaseUrl/" . self::getDavPath(self::DAV_VERSION_NEW, $user);
@@ -582,13 +561,6 @@ class WebDavHelper {
Assert::assertNotEmpty($xmlPart, "The 'oc:spaceid' for user '$user' was not found in the PROPFIND response");
$personalSpaceId = $xmlPart[0]->__toString();
} else {
foreach ($json->value as $spaces) {
if ($spaces->driveType === "personal") {
$personalSpaceId = $spaces->id;
break;
}
}
}
Assert::assertNotEmpty($personalSpaceId, "The personal space id for user '$user' was not found");
@@ -611,21 +583,16 @@ class WebDavHelper {
* @throws Exception|GuzzleException
*/
public static function getPersonalSpaceIdForUserOrFakeIfNotFound(string $baseUrl, string $user, string $password, string $xRequestId):string {
try {
$spaceId = self::getPersonalSpaceIdForUser(
$baseUrl,
$user,
$password,
$xRequestId,
);
} catch (SpaceNotFoundException $e) {
// if the fetch fails, and the user is not found, then a fake space id is prepared
// this is useful for testing when the personal space is of a non-existing user
$fakeSpaceId = self::generateUUIDv4();
self::$spacesIdRef[$user]["personal"] = $fakeSpaceId;
$spaceId = $fakeSpaceId;
if (\str_starts_with($user, "non-exist") || \str_starts_with($user, "nonexist")) {
return self::generateUUIDv4();
}
return $spaceId;
return self::getPersonalSpaceIdForUser(
$baseUrl,
$user,
$password,
$xRequestId,
);
}
/**
@@ -692,12 +659,7 @@ class WebDavHelper {
if ($spaceId === null && $davPathVersionToUse === self::DAV_VERSION_SPACES && !\in_array($type, ["public-files", "versions"])) {
$path = \ltrim($path, "/");
if (\str_starts_with($path, "Shares/")) {
$spaceId = self::getSharesSpaceIdForUser(
$baseUrl,
$user,
$password,
$xRequestId
);
$spaceId = GraphHelper::SHARES_SPACE_ID;
$path = "/" . preg_replace("/^Shares\//", "", $path);
} else {
$spaceId = self::getPersonalSpaceIdForUserOrFakeIfNotFound(

View File

@@ -207,7 +207,6 @@ class FeatureContext extends BehatVariablesContext {
$this->autoSyncSettings[$user] = $value;
}
public const SHARES_SPACE_ID = 'a0ca6a90-a365-4782-871e-d44447bbc668$a0ca6a90-a365-4782-871e-d44447bbc668';
private bool $useSharingNG = false;
/**

View File

@@ -1124,7 +1124,7 @@ class SharingNgContext implements Context {
* @throws JsonException
*/
public function hideOrUnhideSharedResource(string $sharee, string $shareID, bool $hide = true): ResponseInterface {
$shareSpaceId = FeatureContext::SHARES_SPACE_ID;
$shareSpaceId = GraphHelper::SHARES_SPACE_ID;
$itemId = $shareSpaceId . '!' . $shareID;
$body['@UI.Hidden'] = $hide;
return GraphHelper::hideOrUnhideShare(
@@ -1148,7 +1148,7 @@ class SharingNgContext implements Context {
*/
public function userHasDisabledSyncOfLastSharedResource(string $user):void {
$shareItemId = $this->featureContext->shareNgGetLastCreatedUserGroupShareID();
$shareSpaceId = FeatureContext::SHARES_SPACE_ID;
$shareSpaceId = GraphHelper::SHARES_SPACE_ID;
$itemId = $shareSpaceId . '!' . $shareItemId;
$response = GraphHelper::disableShareSync(
$this->featureContext->getBaseUrl(),
@@ -1172,7 +1172,7 @@ class SharingNgContext implements Context {
*/
public function userDisablesSyncOfShareUsingTheGraphApi(string $user):void {
$shareItemId = $this->featureContext->shareNgGetLastCreatedUserGroupShareID();
$shareSpaceId = FeatureContext::SHARES_SPACE_ID;
$shareSpaceId = GraphHelper::SHARES_SPACE_ID;
$itemId = $shareSpaceId . '!' . $shareItemId;
$response = GraphHelper::disableShareSync(
$this->featureContext->getBaseUrl(),
@@ -1247,7 +1247,7 @@ class SharingNgContext implements Context {
public function userEnablesSyncOfShareUsingTheGraphApi(string $user, string $share, string $offeredBy, string $space):void {
$share = ltrim($share, '/');
$itemId = $this->spacesContext->getResourceId($offeredBy, $space, $share);
$shareSpaceId = FeatureContext::SHARES_SPACE_ID;
$shareSpaceId = GraphHelper::SHARES_SPACE_ID;
$response = GraphHelper::enableShareSync(
$this->featureContext->getBaseUrl(),
$this->featureContext->getStepLineRef(),
@@ -1272,7 +1272,7 @@ class SharingNgContext implements Context {
* @throws Exception|GuzzleException
*/
public function userTriesToEnableShareSyncOfResourceUsingTheGraphApi(string $user, string $resource):void {
$shareSpaceId = FeatureContext::SHARES_SPACE_ID;
$shareSpaceId = GraphHelper::SHARES_SPACE_ID;
$itemId = ($resource === 'nonexistent') ? WebDavHelper::generateUUIDv4() : $resource;
$response = GraphHelper::enableShareSync(
@@ -1296,7 +1296,7 @@ class SharingNgContext implements Context {
* @throws Exception|GuzzleException
*/
public function userTriesToDisableShareSyncOfResourceUsingTheGraphApi(string $user, string $resource):void {
$shareSpaceId = FeatureContext::SHARES_SPACE_ID;
$shareSpaceId = GraphHelper::SHARES_SPACE_ID;
$shareID = ($resource === 'nonexistent') ? WebDavHelper::generateUUIDv4() : $resource;
$itemId = $shareSpaceId . '!' . $shareID;
$response = GraphHelper::disableShareSync(
@@ -1736,13 +1736,22 @@ class SharingNgContext implements Context {
* @param string $share
* @param string $sharee
* @param string $sharer
* @param string $space
* @param bool $shouldExist
*
* @return void
* @throws GuzzleException
* @throws JsonException
* @throws Exception
*/
public function checkIfShareExists(string $share, string $sharee, string $sharer): void {
public function checkIfShareExists(string $share, string $sharee, string $sharer, string $space, bool $shouldExist = true): void {
$share = \ltrim($share, "/");
if (\strtolower($space) === "personal") {
$remoteDriveAlias = "personal/" . \strtolower($sharer);
} else {
$remoteDriveAlias = "project/" . \strtolower($space);
}
// check share mountpoint
$response = GraphHelper::getMySpaces(
$this->featureContext->getBaseUrl(),
@@ -1754,11 +1763,11 @@ class SharingNgContext implements Context {
$driveList = HttpRequestHelper::getJsonDecodedResponseBodyContent($response)->value;
$foundShareMountpoint = false;
foreach ($driveList as $drive) {
if ($drive->driveType === "mountpoint" && $drive->name === $share && $drive->root->remoteItem->driveAlias === "personal/" . \strtolower($sharer)) {
if ($drive->driveType === "mountpoint" && $drive->name === $share && $drive->root->remoteItem->driveAlias === $remoteDriveAlias) {
$foundShareMountpoint = true;
}
}
Assert::assertTrue($foundShareMountpoint, "Share mountpoint '$share' was not found in the drives list.");
Assert::assertSame($shouldExist, $foundShareMountpoint, "Share mountpoint '$share' was not found in the drives list.");
// check share in shared-with-me list
$response = GraphHelper::getSharesSharedWithMe(
@@ -1770,24 +1779,46 @@ class SharingNgContext implements Context {
$sharedWithMeList = HttpRequestHelper::getJsonDecodedResponseBodyContent($response)->value;
$foundShareInSharedWithMe = false;
foreach ($sharedWithMeList as $item) {
if ($item->name === $share && $item->createdBy->user->displayName === $this->featureContext->getDisplayNameForUser($sharer)) {
$foundShareInSharedWithMe = true;
if ($item->name === $share) {
foreach ($item->remoteItem->permissions as $permission) {
$shareCreator = $permission->invitation->invitedBy->user->displayName;
if ($shareCreator === $this->featureContext->getDisplayNameForUser($sharer)) {
$foundShareInSharedWithMe = true;
break;
}
}
break;
}
}
Assert::assertTrue($foundShareInSharedWithMe, "Share '$share' was not found in the shared-with-me list");
Assert::assertSame($shouldExist, $foundShareInSharedWithMe, "Share '$share' was not found in the shared-with-me list");
}
/**
* @Then user :sharee should have a share :share shared by user :sharer
* @Then user :sharee should have a share :share shared by user :sharer from space :space
*
* @param string $sharee
* @param string $share
* @param string $sharer
* @param string $space
*
* @return void
*/
public function userShouldHaveShare(string $sharee, string $share, string $sharer): void {
$this->checkIfShareExists($share, $sharee, $sharer);
public function userShouldHaveShareSharedByUserFromSpace(string $sharee, string $share, string $sharer, string $space): void {
$this->checkIfShareExists($share, $sharee, $sharer, $space);
}
/**
* @Then user :sharee should not have a share :share shared by user :sharer from space :space
*
* @param string $sharee
* @param string $share
* @param string $sharer
* @param string $space
*
* @return void
*/
public function userShouldNotHaveShareSharedByUserFromSpace(string $sharee, string $share, string $sharer, string $space): void {
$this->checkIfShareExists($share, $sharee, $sharer, $space, false);
}
/**

View File

@@ -22,7 +22,7 @@ Feature: Send a sharing invitations
| shareType | user |
| permissionsRole | <permissions-role> |
Then the HTTP status code should be "200"
And user "Brian" should have a share "<resource>" shared by user "Alice"
And user "Brian" should have a share "<resource>" shared by user "Alice" from space "Personal"
And the JSON data of the response should match
"""
{
@@ -111,9 +111,8 @@ Feature: Send a sharing invitations
| shareType | group |
| permissionsRole | <permissions-role> |
Then the HTTP status code should be "200"
And user "Brian" should have a share "<resource>" shared by user "Alice"
And for user "Carol" the space Shares should contain these entries:
| <resource> |
And user "Brian" should have a share "<resource>" shared by user "Alice" from space "Personal"
And user "Carol" should have a share "<resource>" shared by user "Alice" from space "Personal"
And the JSON data of the response should match
"""
{
@@ -1901,8 +1900,7 @@ Feature: Send a sharing invitations
| shareType | user |
| permissionsRole | Viewer |
Then the HTTP status code should be "404"
And for user "Brian" the space Shares should not contain these entries:
| textfile1.txt |
And user "Brian" should not have a share "textfile1.txt" shared by user "Alice" from space "Personal"
And the JSON data of the response should match
"""
{
@@ -1947,10 +1945,8 @@ Feature: Send a sharing invitations
| shareType | group |
| permissionsRole | Viewer |
Then the HTTP status code should be "404"
And for user "Brian" the space Shares should not contain these entries:
| textfile1.txt |
And for user "Carol" the space Shares should not contain these entries:
| textfile1.txt |
And user "Brian" should not have a share "textfile1.txt" shared by user "Alice" from space "Personal"
And user "Carol" should not have a share "textfile1.txt" shared by user "Alice" from space "Personal"
And the JSON data of the response should match
"""
{
@@ -1992,7 +1988,7 @@ Feature: Send a sharing invitations
| shareType | user |
| permissionsRole | <permissions-role> |
Then the HTTP status code should be "200"
And user "Brian" should have a share "<resource>" shared by user "Alice"
And user "Brian" should have a share "<resource>" shared by user "Alice" from space "NewSpace"
And the JSON data of the response should match
"""
{
@@ -2079,9 +2075,8 @@ Feature: Send a sharing invitations
| shareType | group |
| permissionsRole | <permissions-role> |
Then the HTTP status code should be "200"
And user "Brian" should have a share "<resource>" shared by user "Alice"
And for user "Carol" the space Shares should contain these entries:
| <resource> |
And user "Brian" should have a share "<resource>" shared by user "Alice" from space "NewSpace"
And user "Carol" should have a share "<resource>" shared by user "Alice" from space "NewSpace"
And the JSON data of the response should match
"""
{
@@ -2240,10 +2235,10 @@ Feature: Send a sharing invitations
}
"""
Examples:
| permissions-role | error-message |
| Space Viewer | role not applicable to this resource |
| Space Editor | role not applicable to this resource |
| Manager | role not applicable to this resource |
| permissions-role | error-message |
| Space Viewer | role not applicable to this resource |
| Space Editor | role not applicable to this resource |
| Manager | role not applicable to this resource |
Scenario Outline: try to send share invitation with different re-sharing permissions
@@ -3115,7 +3110,7 @@ Feature: Send a sharing invitations
| shareType | user |
| permissionsRole | Viewer |
Then the HTTP status code should be "200"
And user "Brian" should have a share "<resource>" shared by user "Alice"
And user "Brian" should have a share "textfile.txt" shared by user "Alice" from space "Personal"
When user "Alice" sends the following resource share invitation using the Graph API:
| resource | textfile.txt |
| space | Personal |
@@ -3123,8 +3118,7 @@ Feature: Send a sharing invitations
| shareType | group |
| permissionsRole | Viewer |
Then the HTTP status code should be "200"
And for user "Carol" the space Shares should contain these entries:
| textfile.txt |
And user "Carol" should have a share "textfile.txt" shared by user "Alice" from space "Personal"
Scenario: share a file to group containing special characters in name (Personal space)
@@ -3140,7 +3134,7 @@ Feature: Send a sharing invitations
| shareType | group |
| permissionsRole | Viewer |
Then the HTTP status code should be "200"
And user "Brian" should have a share "textfile.txt" shared by user "Alice"
And user "Brian" should have a share "textfile.txt" shared by user "Alice" from space "Personal"
Scenario: share a file to user and group having same name (Project space)
@@ -3160,7 +3154,7 @@ Feature: Send a sharing invitations
| shareType | user |
| permissionsRole | Viewer |
Then the HTTP status code should be "200"
And user "Brian" should have a share "textfile.txt" shared by user "Alice"
And user "Brian" should have a share "textfile.txt" shared by user "Alice" from space "NewSpace"
When user "Alice" sends the following resource share invitation using the Graph API:
| resource | textfile.txt |
| space | NewSpace |
@@ -3168,8 +3162,7 @@ Feature: Send a sharing invitations
| shareType | group |
| permissionsRole | Viewer |
Then the HTTP status code should be "200"
And for user "Carol" the space Shares should contain these entries:
| textfile.txt |
And user "Carol" should have a share "textfile.txt" shared by user "Alice" from space "NewSpace"
Scenario: share a file to group containing special characters in name (Project space)
@@ -3188,4 +3181,4 @@ Feature: Send a sharing invitations
| shareType | group |
| permissionsRole | Viewer |
Then the HTTP status code should be "200"
And user "Brian" should have a share "textfile.txt" shared by user "Alice"
And user "Brian" should have a share "textfile.txt" shared by user "Alice" from space "NewSpace"

View File

@@ -714,7 +714,7 @@ Feature: copy file
And as "Brian" folder "BRIAN-Folder/sample-folder" should exist
But as "Alice" file "Shares/BRIAN-Folder" should not exist
And as "Alice" file "Shares/textfile1.txt" should not exist
And user "Alice" should have a share "BRIAN-Folder" shared by user "Brian"
And user "Alice" should have a share "BRIAN-Folder" shared by user "Brian" from space "Personal"
@issue-7208
Scenario: copy a folder over the top of an existing file received as a user share
@@ -734,7 +734,7 @@ Feature: copy file
And for user "Alice" the content of the file "sharedfile1.txt" of the space "Shares" should be "file to share"
And for user "Brian" the content of the file "sharedfile1.txt" of the space "Personal" should be "file to share"
But as "Alice" folder "Shares/FOLDER/sample-folder" should not exist
And user "Alice" should have a share "sharedfile1.txt" shared by user "Brian"
And user "Alice" should have a share "sharedfile1.txt" shared by user "Brian" from space "Personal"
Scenario: copy a folder into another folder at different level which is received as a user share

View File

@@ -71,7 +71,7 @@ Feature: create folder using MKCOL
| /dav/spaces/%spaceid%/PARENT/parent.txt |
Then the HTTP status code of responses on all endpoints should be "404"
@issue-5049 @issue-1347 @issue-1292
@issue-5049 @issue-1347 @issue-1292
Scenario: send MKCOL requests to non-existent user's webDav endpoints as normal user using the spaces WebDAV API
Given user "Brian" has been created with default attributes
When user "Brian" requests these endpoints with "MKCOL" including body "" about user "non-existent-user"

View File

@@ -218,7 +218,7 @@ Feature: files and folders exist in the trashbin after being deleted
@issue-3561
Scenario Outline: listing non-existent user's trashbin is prohibited
Given using <dav-path-version> DAV path
When user "Alice" tries to list the trashbin content for user "testtrashbinnotauser"
When user "Alice" tries to list the trashbin content for user "nonexistent"
Then the HTTP status code should be "404"
Examples:
| dav-path-version |

View File

@@ -233,7 +233,7 @@ Feature: copy file
Then the HTTP status code should be "400"
And as "Alice" folder "/Shares/BRIAN-Folder/sample-folder" should exist
And as "Alice" file "/Shares/BRIAN-Folder" should not exist
And user "Alice" should have a share "BRIAN-Folder" shared by user "Brian"
And user "Alice" should have a share "BRIAN-Folder" shared by user "Brian" from space "Personal"
And as "Brian" folder "BRIAN-Folder" should exist
Examples:
| dav-path-version |
@@ -257,7 +257,7 @@ Feature: copy file
When user "Alice" copies file "copy.txt" to "Shares/lorem.txt" using the WebDAV API
Then the HTTP status code should be "204"
And the content of file "Shares/lorem.txt" for user "Alice" should be "file to copy"
And user "Alice" should have a share "lorem.txt" shared by user "Brian"
And user "Alice" should have a share "lorem.txt" shared by user "Brian" from space "Personal"
And the content of file "lorem.txt" for user "Brian" should be "file to copy"
Examples:
| dav-path-version |
@@ -282,7 +282,7 @@ Feature: copy file
Then the HTTP status code should be "400"
And the content of file "Shares/sharedfile1.txt" for user "Alice" should be "file to share"
And as "Alice" folder "/Shares/sharedfile1.txt" should not exist
And user "Alice" should have a share "sharedfile1.txt" shared by user "Brian"
And user "Alice" should have a share "sharedfile1.txt" shared by user "Brian" from space "Personal"
And the content of file "sharedfile1.txt" for user "Brian" should be "file to share"
Examples:
| dav-path-version |
@@ -308,7 +308,7 @@ Feature: copy file
Then the HTTP status code should be "400"
And as "Alice" folder "Shares/BRIAN-Folder/brian-folder" should exist
And as "Alice" folder "Shares/BRIAN-Folder/alice-folder" should not exist
And user "Alice" should have a share "BRIAN-Folder" shared by user "Brian"
And user "Alice" should have a share "BRIAN-Folder" shared by user "Brian" from space "Personal"
And as "Brian" folder "BRIAN-Folder" should exist
Examples:
| dav-path-version |
@@ -460,7 +460,7 @@ Feature: copy file
Then the HTTP status code should be "400"
And as "Alice" folder "/Shares/BRIAN-Folder/sample-folder" should exist
And as "Alice" file "/Shares/BRIAN-Folder" should not exist
And user "Alice" should have a share "BRIAN-Folder" shared by user "Brian"
And user "Alice" should have a share "BRIAN-Folder" shared by user "Brian" from space "Personal"
And as "Brian" folder "BRIAN-Folder/sample-folder" should exist
Examples:
| dav-path-version |
@@ -488,7 +488,7 @@ Feature: copy file
Then the HTTP status code should be "400"
And as "Alice" file "/Shares/sharedfile1.txt" should exist
And as "Alice" folder "/Shares/sharedfile1.txt" should not exist
And user "Alice" should have a share "sharedfile1.txt" shared by user "Brian"
And user "Alice" should have a share "sharedfile1.txt" shared by user "Brian" from space "Personal"
And as "Brian" file "sharedfile1.txt" should exist
Examples:
| dav-path-version |