Skip to content

Commit

Permalink
added test coverage for previewing shared resources using spaces dav …
Browse files Browse the repository at this point in the history
…path
  • Loading branch information
PrajwolAmatya committed Sep 26, 2023
1 parent 5ca6a98 commit e743576
Show file tree
Hide file tree
Showing 3 changed files with 217 additions and 7 deletions.
41 changes: 41 additions & 0 deletions tests/TestHelpers/GraphHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1426,4 +1426,45 @@ public static function unassignRole(
self::getRequestHeaders(),
);
}

/**
* @param string $baseUrl
* @param string $xRequestId
* @param string $user
* @param string $password
* @param string $path
*
* @return string
* @throws GuzzleException
* @throws Exception
*/
public static function getMountPointId(
string $baseUrl,
string $xRequestId,
string $user,
string $password,
string $path
): string {
$response = self::getMySpaces(
$baseUrl,
$user,
$password,
'',
$xRequestId
);
$drives = json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);

// the response returns the shared resource in driveAlias all in lowercase,
// For example: if we get the property of a shared resource "FOLDER" then the response contains "driveAlias": "mountpoint/folder"
$path = strtolower($path);
foreach ($drives["value"] as $value) {
if ($value["driveAlias"] === "mountpoint/" . $path) {
return $value["id"];
}
}
throw new \Exception(
__METHOD__
. " Failed to get mountpoint id from response."
);
}
}
110 changes: 103 additions & 7 deletions tests/acceptance/features/bootstrap/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use TestHelpers\WebDavHelper;
use TestHelpers\HttpRequestHelper;
use TestHelpers\Asserts\WebDav as WebDavAssert;
use TestHelpers\GraphHelper;

/**
* WebDav functions
Expand Down Expand Up @@ -473,7 +474,7 @@ public function downloadPreviews(string $user, ?string $path, ?string $doDavRequ
[],
null,
"files",
'2',
null,
false,
null,
$urlParameter,
Expand Down Expand Up @@ -4651,6 +4652,91 @@ public function downloadPreviewOfFiles(string $user, string $path, string $width
$this->setResponse($response);
}

/**
* @param string $user
* @param string $path
* @param string $method
* @param string|null $urlParameter
* @param string|null $content
*
* @return ResponseInterface
* @throws GuzzleException
*/
public function userDownloadsOrUploadsSharedResource(
string $user,
string $path,
string $method,
?string $urlParameter = null,
?string $content = null
): ResponseInterface {
$user = $this->getActualUsername($user);
$path = trim($path, "/");
$pathArray = explode("/", $path);

$mountPointId = GraphHelper::getMountPointId(
$this->getBaseUrl(),
$this->getStepLineRef(),
$user,
$this->getPasswordForUser($user),
$pathArray[0]
);

if (\count($pathArray) > 1) {
$pathArray = \array_slice($pathArray, 1);
$path = '/' . implode("/", array_map("strval", $pathArray));
} else {
$path = null;
}
$mountPointId .= $path . '/?' . $urlParameter;

$davPath = WebDavHelper::getDavPath($user, $this->getDavPathVersion());
$fullUrl = $this->getBaseUrl() . $davPath . $mountPointId;

return HttpRequestHelper::sendRequest(
$fullUrl,
$this->getStepLineRef(),
$method,
$user,
$this->getPasswordForUser($user),
null,
$content
);
}

/**
* @When user :user downloads the preview of shared resource :path with width :width and height :height using the WebDAV API
*
* @param string $user
* @param string $path
* @param string $width
* @param string $height
*
* @return void
*/
public function userDownloadsThePreviewOfSharedResourceWithWidthAndHeightUsingTheWebdavApi(string $user, string $path, string $width, string $height): void {
$urlParameter = [
'x' => $width,
'y' => $height,
'forceIcon' => '0',
'preview' => '1'
];
$urlParameter = \http_build_query($urlParameter, '', '&');
$this->setResponse($this->userDownloadsOrUploadsSharedResource($user, $path, 'GET', $urlParameter));
}

/**
* @When user :user uploads file with content :content to shared resource :path using the WebDAV API
*
* @param string $user
* @param string $content
* @param string $path
*
* @return void
*/
public function userUploadsFileWithContentToSharedResourceUsingTheWebdavApi(string $user, string $content, string $path): void {
$this->setResponse($this->userDownloadsOrUploadsSharedResource($user, $path, 'PUT', null, $content));
}

/**
* @When user :user1 downloads the preview of :path of :user2 with width :width and height :height using the WebDAV API
*
Expand Down Expand Up @@ -4738,35 +4824,45 @@ public function theDownloadedPreviewContentShouldMatchWithFixturesPreviewContent
}

/**
* @Given user :user has downloaded the preview of :path with width :width and height :height
* @Given /^user "([^"]*)" has downloaded the preview of ?(|shared resource) "([^"]*)" with width "([^"]*)" and height "([^"]*)"$/
*
* @param string $user
* @param string $sharedResource
* @param string $path
* @param string $width
* @param string $height
*
* @return void
*/
public function userDownloadsThePreviewOfWithWidthAndHeight(string $user, string $path, string $width, string $height):void {
$this->downloadPreviewOfFiles($user, $path, $width, $height);
public function userDownloadsThePreviewOfWithWidthAndHeight(string $user, string $sharedResource, string $path, string $width, string $height):void {
if ($sharedResource) {
$this->userDownloadsThePreviewOfSharedResourceWithWidthAndHeightUsingTheWebdavApi($user, $path, $width, $height);
} else {
$this->downloadPreviewOfFiles($user, $path, $width, $height);
}
$this->theHTTPStatusCodeShouldBe(200);
$this->imageDimensionsShouldBe($width, $height);
// save response to user response dictionary for further comparisons
$this->userResponseBodyContents[$user] = $this->responseBodyContent;
}

/**
* @Then as user :user the preview of :path with width :width and height :height should have been changed
* @Then /^as user "([^"]*)" the preview of ?(|shared resource) "([^"]*)" with width "([^"]*)" and height "([^"]*)" should have been changed$/
*
* @param string $user
* @param string $sharedResource
* @param string $path
* @param string $width
* @param string $height
*
* @return void
*/
public function asUserThePreviewOfPathWithHeightAndWidthShouldHaveBeenChanged(string $user, string $path, string $width, string $height):void {
$this->downloadPreviewOfFiles($user, $path, $width, $height);
public function asUserThePreviewOfPathWithHeightAndWidthShouldHaveBeenChanged(string $user, string $sharedResource, string $path, string $width, string $height):void {
if ($sharedResource) {
$this->userDownloadsThePreviewOfSharedResourceWithWidthAndHeightUsingTheWebdavApi($user, $path, $width, $height);
} else {
$this->downloadPreviewOfFiles($user, $path, $width, $height);
}
$this->theHTTPStatusCodeShouldBe(200);
$newResponseBodyContents = $this->response->getBody()->getContents();
Assert::assertNotEquals(
Expand Down
73 changes: 73 additions & 0 deletions tests/acceptance/features/coreApiWebdavPreviews/previews.feature
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,21 @@ Feature: previews of files downloaded through the webdav API
| new | example.gif |


Scenario Outline: download previews of shared files inside of shared folder
Given using spaces DAV path
And user "Brian" has been created with default attributes and without skeleton files
And user "Alice" has uploaded file "filesForUpload/<resource>" to "/<resource>"
And user "Alice" has shared file "/<resource>" with user "Brian"
And user "Brian" has accepted share "/<resource>" offered by user "Alice"
When user "Brian" downloads the preview of shared resource "/<resource>" with width "32" and height "32" using the WebDAV API
Then the HTTP status code should be "200"
And the downloaded image should be "32" pixels wide and "32" pixels high
Examples:
| resource |
| lorem.txt |
| example.gif |


Scenario Outline: user tries to download previews of other users files
Given using <dav-path-version> DAV path
And user "Brian" has been created with default attributes and without skeleton files
Expand Down Expand Up @@ -223,6 +238,18 @@ Feature: previews of files downloaded through the webdav API
| new |


Scenario: previews of shared file inside of shared folder gets updated for sharee as owner updates the shared file
Given using spaces DAV path
And user "Brian" has been created with default attributes and without skeleton files
And user "Alice" has uploaded file "filesForUpload/lorem.txt" to "/parent.txt"
And user "Alice" has shared file "/parent.txt" with user "Brian"
And user "Brian" has accepted share "/parent.txt" offered by user "Alice"
And user "Brian" has downloaded the preview of shared resource "/parent.txt" with width "32" and height "32"
When user "Alice" uploads file with content "this is a file to upload" to "/parent.txt" using the WebDAV API
Then the HTTP status code should be "204"
And as user "Brian" the preview of shared resource "/parent.txt" with width "32" and height "32" should have been changed


Scenario Outline: it should update the preview content if the file content is updated (content with UTF chars)
Given using <dav-path-version> DAV path
And user "Alice" has uploaded file "filesForUpload/lorem.txt" to "/lorem.txt"
Expand Down Expand Up @@ -261,6 +288,25 @@ Feature: previews of files downloaded through the webdav API
| new |


Scenario: preview of shared file gets updated for both sharees and sharers as file is updated
Given using spaces DAV path
And user "Brian" has been created with default attributes and without skeleton files
And user "Alice" has created folder "FOLDER"
And user "Alice" has uploaded file with content "file to upload" to "/FOLDER/lorem.txt"
And user "Alice" has shared folder "FOLDER" with user "Brian"
And user "Brian" has accepted share "/FOLDER" offered by user "Alice"
And user "Alice" has downloaded the preview of "/FOLDER/lorem.txt" with width "32" and height "32"
And user "Brian" has downloaded the preview of shared resource "/FOLDER/lorem.txt" with width "32" and height "32"
When user "Alice" uploads file "filesForUpload/lorem.txt" to "/FOLDER/lorem.txt" using the WebDAV API
Then the HTTP status code should be "204"
And as user "Alice" the preview of "/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
And as user "Brian" the preview of shared resource "/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
When user "Brian" uploads file with content "new uploaded content" to shared resource "/FOLDER/lorem.txt" using the WebDAV API
Then the HTTP status code should be "204"
And as user "Alice" the preview of "/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
And as user "Brian" the preview of shared resource "/FOLDER/lorem.txt" with width "32" and height "32" should have been changed


Scenario Outline: updates to a group shared file should change the preview for both sharees and sharers
Given using <dav-path-version> DAV path
And group "grp1" has been created
Expand Down Expand Up @@ -290,3 +336,30 @@ Feature: previews of files downloaded through the webdav API
| dav-path-version |
| old |
| new |


Scenario: preview of group shared file gets updated for both sharees and sharers as file is updated
Given using spaces DAV path
And group "grp1" has been created
And user "Brian" has been created with default attributes and without skeleton files
And user "Carol" has been created with default attributes and without skeleton files
And user "Brian" has been added to group "grp1"
And user "Carol" has been added to group "grp1"
And user "Alice" has created folder "FOLDER"
And user "Alice" has uploaded file with content "file to upload" to "/FOLDER/lorem.txt"
And user "Alice" has shared folder "/FOLDER" with group "grp1"
And user "Brian" has accepted share "/FOLDER" offered by user "Alice"
And user "Carol" has accepted share "/FOLDER" offered by user "Alice"
And user "Alice" has downloaded the preview of "/FOLDER/lorem.txt" with width "32" and height "32"
And user "Brian" has downloaded the preview of shared resource "/FOLDER/lorem.txt" with width "32" and height "32"
And user "Carol" has downloaded the preview of shared resource "/FOLDER/lorem.txt" with width "32" and height "32"
When user "Alice" uploads file "filesForUpload/lorem.txt" to "/FOLDER/lorem.txt" using the WebDAV API
Then the HTTP status code should be "204"
And as user "Alice" the preview of "/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
And as user "Brian" the preview of shared resource "/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
And as user "Carol" the preview of shared resource "/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
When user "Brian" uploads file with content "new uploaded content" to shared resource "/FOLDER/lorem.txt" using the WebDAV API
Then the HTTP status code should be "204"
And as user "Alice" the preview of "/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
And as user "Brian" the preview of shared resource "/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
And as user "Carol" the preview of shared resource "/FOLDER/lorem.txt" with width "32" and height "32" should have been changed

0 comments on commit e743576

Please sign in to comment.