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][full-ci] added test for previewing shared resource using spaces dav version #7234

Merged
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
42 changes: 42 additions & 0 deletions tests/TestHelpers/GraphHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1426,4 +1426,46 @@ 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 getShareMountId(
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"
PrajwolAmatya marked this conversation as resolved.
Show resolved Hide resolved
// In case of two shares with same name, the response for the second shared resource will contain, "driveAlias": "mountpoint/folder-(2)"
$path = strtolower($path);
foreach ($drives["value"] as $value) {
if ($value["driveAlias"] === "mountpoint/" . $path) {
return $value["id"];
}
}
throw new \Exception(
__METHOD__
. " Cannot find share mountpoint id of '$path' for user '$user'"
);
}
}
200 changes: 195 additions & 5 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 @@ -499,7 +500,7 @@ public function downloadPreviews(string $user, ?string $path, ?string $doDavRequ
[],
null,
"files",
'2',
null,
false,
null,
$urlParameter,
Expand Down Expand Up @@ -4629,6 +4630,195 @@ public function downloadPreviewOfFiles(string $user, string $path, string $width
$this->setResponse($response);
}

/**
* @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 {
if ($this->getDavPathVersion() === 3) {
$this->setResponse($this->downloadSharedFilePreview($user, $path, $width, $height));
} else {
$this->setResponse($this->downloadPreviews($user, $path, null, $width, $height));
}
}

/**
* @Given user :user has downloaded the preview of shared resource :path with width :width and height :height
*
* @param string $user
* @param string $path
* @param string $width
* @param string $height
*
* @return void
*/
public function userHasDownloadedThePreviewOfSharedResourceWithWidthAndHeight(string $user, string $path, string $width, string $height): void {
if ($this->getDavPathVersion() === 3) {
$response = $this->downloadSharedFilePreview($user, $path, $width, $height);
} else {
$response = $this->downloadPreviews($user, $path, null, $width, $height);
}
$this->setResponse($response);
$this->theHTTPStatusCodeShouldBe(200, '', $response);
$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 shared resource :path with width :width and height :height should have been changed
*
* @param string $user
* @param string $path
* @param string $width
* @param string $height
*
* @return void
*/
public function asUserThePreviewOfSharedResourceWithWidthAndHeightShouldHaveBeenChanged(string $user, string $path, string $width, string $height):void {
if ($this->getDavPathVersion() === 3) {
$response = $this->downloadSharedFilePreview($user, $path, $width, $height);
} else {
$response = $this->downloadPreviews($user, $path, null, $width, $height);
}
$this->setResponse($response);
$this->theHTTPStatusCodeShouldBe(200, '', $response);
$newResponseBodyContents = $this->response->getBody()->getContents();
Assert::assertNotEquals(
$newResponseBodyContents,
// different users can download files before and after an update is made to a file
// previous response content is fetched from user response body content array for that user
$this->userResponseBodyContents[$user],
__METHOD__ . " previous and current previews content is same but expected to be different",
);
// update the saved content for the next comparison
$this->userResponseBodyContents[$user] = $newResponseBodyContents;
}

/**
* @When user :user uploads file with content :content to shared resource :destination using the WebDAV API
*
* @param string $user
* @param string $content
* @param string $destination
*
* @return void
*/
public function userUploadsFileWithContentSharedResourceToUsingTheWebdavApi(string $user, string $content, string $destination): void {
if ($this->getDavPathVersion() === 3) {
$this->setResponse($this->uploadToSharedFolder($user, $destination, $content));
} else {
$this->uploadFileWithContent($user, $content, $destination);
}
}

/**
* @param string $user
* @param string $path
*
* @return string
* @throws GuzzleException
*/
public function getMountSharesPath(
string $user,
string $path
): string {
$user = $this->getActualUsername($user);
$path = trim($path, "/");
$pathArray = explode("/", $path);

$shareMountId = GraphHelper::getShareMountId(
$this->getBaseUrl(),
$this->getStepLineRef(),
$user,
$this->getPasswordForUser($user),
$pathArray[1]
);

if (\count($pathArray) > 2) {
$pathArray = \array_slice($pathArray, 2);
$path = '/' . implode("/", array_map("strval", $pathArray));
} else {
$path = null;
}
return $shareMountId . $path;
}

/**
* @param string $user
* @param string $path
* @param string|null $width
* @param string|null $height
*
* @return ResponseInterface
* @throws GuzzleException
*/
public function downloadSharedFilePreview(
string $user,
string $path,
?string $width = null,
?string $height = null
): ResponseInterface {
if ($width !== null && $height !== null) {
$urlParameter = [
'x' => $width,
'y' => $height,
'forceIcon' => '0',
'preview' => '1'
];
$urlParameter = \http_build_query($urlParameter, '', '&');
} else {
$urlParameter = null;
}
$sharesPath = $this->getMountSharesPath($user, $path) . '/?' . $urlParameter;

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

return HttpRequestHelper::sendRequest(
$fullUrl,
$this->getStepLineRef(),
'GET',
$user,
$this->getPasswordForUser($user)
);
}

/**
* @param string $user
* @param string $destination
* @param string|null $content
*
* @return ResponseInterface
* @throws GuzzleException
*/
public function uploadToSharedFolder(
string $user,
string $destination,
?string $content = null
): ResponseInterface {
$sharesPath = $this->getMountSharesPath($user, $destination);

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

return HttpRequestHelper::sendRequest(
$fullUrl,
$this->getStepLineRef(),
'PUT',
$user,
$this->getPasswordForUser($user),
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 @@ -4726,8 +4916,8 @@ public function theDownloadedPreviewContentShouldMatchWithFixturesPreviewContent
* @return void
*/
public function userDownloadsThePreviewOfWithWidthAndHeight(string $user, string $path, string $width, string $height):void {
$this->downloadPreviewOfFiles($user, $path, $width, $height);
$this->theHTTPStatusCodeShouldBe(200);
$response = $this->downloadPreviewOfFiles($user, $path, $width, $height);
$this->theHTTPStatusCodeShouldBe(200, '', $response);
$this->imageDimensionsShouldBe($width, $height);
// save response to user response dictionary for further comparisons
$this->userResponseBodyContents[$user] = $this->responseBodyContent;
Expand All @@ -4744,8 +4934,8 @@ public function userDownloadsThePreviewOfWithWidthAndHeight(string $user, string
* @return void
*/
public function asUserThePreviewOfPathWithHeightAndWidthShouldHaveBeenChanged(string $user, string $path, string $width, string $height):void {
$this->downloadPreviewOfFiles($user, $path, $width, $height);
$this->theHTTPStatusCodeShouldBe(200);
$response = $this->downloadPreviewOfFiles($user, $path, $width, $height);
$this->theHTTPStatusCodeShouldBe(200, '', $response);
$newResponseBodyContents = $this->response->getBody()->getContents();
Assert::assertNotEquals(
$newResponseBodyContents,
Expand Down
33 changes: 19 additions & 14 deletions tests/acceptance/features/coreApiWebdavPreviews/previews.feature
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ Feature: previews of files downloaded through the webdav API
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 "/Shares/<resource>" with width "32" and height "32" using the WebDAV API
When user "Brian" downloads the preview of shared resource "/Shares/<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:
Expand All @@ -150,6 +150,8 @@ Feature: previews of files downloaded through the webdav API
| old | example.gif |
| new | lorem.txt |
| new | example.gif |
| spaces | lorem.txt |
| spaces | example.gif |


Scenario Outline: user tries to download previews of other users files
Expand Down Expand Up @@ -213,14 +215,15 @@ Feature: previews of files downloaded through the webdav API
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 "/Shares/parent.txt" with width "32" and height "32"
And user "Brian" has downloaded the preview of shared resource "/Shares/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 "/Shares/parent.txt" with width "32" and height "32" should have been changed
And as user "Brian" the preview of shared resource "/Shares/parent.txt" with width "32" and height "32" should have been changed
Examples:
| dav-path-version |
| old |
| new |
| spaces |


Scenario Outline: it should update the preview content if the file content is updated (content with UTF chars)
Expand All @@ -246,19 +249,20 @@ Feature: previews of files downloaded through the webdav API
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 "Shares/FOLDER/lorem.txt" with width "32" and height "32"
And user "Brian" has downloaded the preview of shared resource "Shares/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 "Shares/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
When user "Brian" uploads file with content "new uploaded content" to "Shares/FOLDER/lorem.txt" using the WebDAV API
And as user "Brian" the preview of shared resource "Shares/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 "Shares/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 "Shares/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
And as user "Brian" the preview of shared resource "Shares/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
Examples:
| dav-path-version |
| old |
| new |
| spaces |


Scenario Outline: updates to a group shared file should change the preview for both sharees and sharers
Expand All @@ -274,19 +278,20 @@ Feature: previews of files downloaded through the webdav API
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 "Shares/FOLDER/lorem.txt" with width "32" and height "32"
And user "Carol" has downloaded the preview of "Shares/FOLDER/lorem.txt" with width "32" and height "32"
And user "Brian" has downloaded the preview of shared resource "Shares/FOLDER/lorem.txt" with width "32" and height "32"
And user "Carol" has downloaded the preview of shared resource "Shares/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 "Shares/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
And as user "Carol" the preview of "Shares/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
When user "Brian" uploads file with content "new uploaded content" to "Shares/FOLDER/lorem.txt" using the WebDAV API
And as user "Brian" the preview of shared resource "Shares/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
And as user "Carol" the preview of shared resource "Shares/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 "Shares/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 "Shares/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
And as user "Carol" the preview of "Shares/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
And as user "Brian" the preview of shared resource "Shares/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
And as user "Carol" the preview of shared resource "Shares/FOLDER/lorem.txt" with width "32" and height "32" should have been changed
Examples:
| dav-path-version |
| old |
| new |
| spaces |