Skip to content

Commit

Permalink
added API test for public link mtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Talank committed Jun 29, 2020
1 parent f570e04 commit a0ed56e
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 2 deletions.
33 changes: 33 additions & 0 deletions tests/TestHelpers/WebDavHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,4 +493,37 @@ public static function isValidDavChunkingCombination(
($davPathVersion === $chunkingVersion)
);
}

/**
* get Mtime of File in a public link share
*
* @param string $baseUrl
* @param string $fileName
* @param string $token
* @param int $davVersionToUse
*
* @return string
* @throws Exception
*/
public function getMtimeOfFileinPublicLinkShare(
$baseUrl,
$fileName,
$token,
$davVersionToUse=2
) {
$response = self::propfind(
$baseUrl,
null,
null,
"/public-files/{$token}/{$fileName}",
['d:getlastmodified'],
1,
null,
$davVersionToUse
);
$responseXmlObject = HttpRequestHelper::getResponseXml($response);
$xmlPart = $responseXmlObject->xpath("//d:getlastmodified");

return $xmlPart[0]->__toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,78 @@ Feature: create a public link share
When the public gets the size of the last shared public link using the WebDAV API
Then the HTTP status code should be "207"
And the size of the file should be "19"

@issue-ocis-reva-49
Scenario Outline: Get the mtime of a file shared by public link
Given using <dav_version> DAV path
And user "Alice" has uploaded a file to "file.txt" with mtime "Thu, 08 Aug 2019 04:18:13 GMT" using the WebDAV API
When user "Alice" creates a public link share using the sharing API with settings
| path | file.txt |
| permissions | read |
Then the HTTP status code should be "200"
And the mtime of the last shared public link for file "file.txt" using the WebDAV API should be "Thu, 08 Aug 2019 04:18:13 GMT"
Examples:
| dav_version |
| old |
| new |

@issue-ocis-reva-49
Scenario Outline: Get the mtime of a file inside a folder shared by public link
Given using <dav_version> DAV path
And user "Alice" has created folder "testFolder"
And user "Alice" has uploaded a file to "testFolder/file.txt" with mtime "Thu, 08 Aug 2019 04:18:13 GMT" using the WebDAV API
When user "Alice" creates a public link share using the sharing API with settings
| path | /testFolder |
| permissions | read |
Then the HTTP status code should be "200"
And the mtime of the last shared public link for file "file.txt" using the WebDAV API should be "Thu, 08 Aug 2019 04:18:13 GMT"
Examples:
| dav_version |
| old |
| new |

@issue-ocis-reva-49
Scenario: Get the mtime of a file inside a folder shared by public link using old dav version
Given user "Alice" has created folder "testFolder"
And user "Alice" has created a public link share with settings
| path | /testFolder |
| permissions | read,update,create,delete |
When the public uploads a file "file.txt" to last shared folder with mtime "Thu, 08 Aug 2019 04:18:13 GMT" using the old public WebDAV API
Then as "Alice" file "testFolder/file.txt" should exist
And the mtime of the last shared public link for file "file.txt" using the WebDAV API should be "Thu, 08 Aug 2019 04:18:13 GMT"

@issue-ocis-reva-49 @issue-37605
Scenario: Get the mtime of a file inside a folder shared by public link using old dav version
Given user "Alice" has created folder "testFolder"
And user "Alice" has created a public link share with settings
| path | /testFolder |
| permissions | read,update,create,delete |
When the public uploads a file "file.txt" to last shared folder with mtime "Thu, 08 Aug 2019 04:18:13 GMT" using the new public WebDAV API
Then as "Alice" file "testFolder/file.txt" should exist
And the mtime of the last shared public link for file "file.txt" using the WebDAV API should not be "Thu, 08 Aug 2019 04:18:13 GMT"
# And the mtime of the last shared public link for file "file.txt" using the WebDAV API should be "Thu, 08 Aug 2019 04:18:13 GMT"

@issue-ocis-reva-49
Scenario: overwriting a file changes its mtime
Given user "Alice" has created folder "testFolder"
When user "Alice" uploads file with content "uploaded content for file name ending with a dot" to "testFolder/file.txt" using the WebDAV API
And user "Alice" has created a public link share with settings
| path | /testFolder |
| permissions | read,update,create,delete |
And the public uploads a file "file.txt" to last shared folder with mtime "Thu, 08 Aug 2019 04:18:13 GMT" using the old public WebDAV API
Then the HTTP status code should be "204"
Then as "Alice" file "/testFolder/file.txt" should exist
And the mtime of the last shared public link for file "file.txt" using the WebDAV API should be "Thu, 08 Aug 2019 04:18:13 GMT"

@issue-ocis-reva-49 @issue-37605
Scenario: overwriting a file changes its mtime
Given user "Alice" has created folder "testFolder"
When user "Alice" uploads file with content "uploaded content for file name ending with a dot" to "testFolder/file.txt" using the WebDAV API
And user "Alice" has created a public link share with settings
| path | /testFolder |
| permissions | read,update,create,delete |
And the public uploads a file "file.txt" to last shared folder with mtime "Thu, 08 Aug 2019 04:18:13 GMT" using the new public WebDAV API
Then the HTTP status code should be "204"
Then as "Alice" file "/testFolder/file.txt" should exist
And the mtime of the last shared public link for file "file.txt" using the WebDAV API should not be "Thu, 08 Aug 2019 04:18:13 GMT"
# And the mtime of the last shared public link for file "file.txt" using the WebDAV API should be "Thu, 08 Aug 2019 04:18:13 GMT"
70 changes: 70 additions & 0 deletions tests/acceptance/features/bootstrap/PublicWebDavContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,76 @@ public function publiclyUploadingShouldWork($publicWebDAVAPIVersion) {
}
}

/**
* @When the public uploads a file :fileName to last shared folder with mtime :mtime using the :davVersion public WebDAV API
*
* @param String $fileName
* @param String $mtime
* @param String $davVersion
*
* @return void
*/
public function thePublicUploadsFileToLastSharedFolderWithMtimeUsingTheWebdavApi(
$fileName,
$mtime,
$davVersion="old"
) {
$mtime = new DateTime($mtime);
$mtime = $mtime->format('U');

$this->publicUploadContent(
$fileName,
'',
'test',
false,
["X-OC-Mtime" => $mtime],
$davVersion
);
}

/**
* @When the mtime of the last shared public link for file :fileName using the WebDAV API should be :mtime
*
* @param string $fileName
* @param string $mtime
*
* @return void
* @throws Exception
*/
public function publicGetsTheMtimeOfTheLastSharedPublicLinkUsingTheWebdavApi(
$fileName,
$mtime
) {
$tokenArray = $this->featureContext->getLastShareData()->data->token;
$token = (string)$tokenArray[0];
$baseUrl = $this->featureContext->getBaseUrl();
Assert::assertEquals(
$mtime, (new TestHelpers\WebDavHelper)->getMtimeOfFileinPublicLinkShare($baseUrl, $fileName, $token)
);
}

/**
* @When the mtime of the last shared public link for file :fileName using the WebDAV API should not be :mtime
*
* @param string $fileName
* @param string $mtime
*
* @return void
* @throws Exception
*/
public function publicDoNotGetsTheMtimeOfTheLastSharedPublicLinkUsingTheWebdavApi(
$fileName,
$mtime
) {
$tokenArray = $this->featureContext->getLastShareData()->data->token;
$token = (string)$tokenArray[0];
$baseUrl = $this->featureContext->getBaseUrl();
Assert::assertNotEquals(
$mtime,
(new TestHelpers\WebDavHelper)->getMtimeOfFileinPublicLinkShare($baseUrl, $fileName, $token)
);
}

/**
* Uploads a file through the public WebDAV API and sets the response in FeatureContext
*
Expand Down
5 changes: 3 additions & 2 deletions tests/acceptance/features/bootstrap/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -2077,6 +2077,7 @@ public function userUploadsAFileWithContentTo(

/**
* @When user :user uploads file to :destination with mtime :mtime using the WebDAV API
* @Given user :user has uploaded a file to :destination with mtime :mtime using the WebDAV API
*
* @param string $user
* @param string $destination
Expand Down Expand Up @@ -2109,8 +2110,8 @@ public function theMtimeOfTheFileShouldBe(
$this->response = WebDavHelper::propfind(
$this->getBaseUrl(), $user, $password, $resource, ["getlastmodified"]
);
$reponseXmlObject = HttpRequestHelper::getResponseXml($this->response);
$xmlpart = $reponseXmlObject->xpath("//d:getlastmodified");
$responseXmlObject = HttpRequestHelper::getResponseXml($this->response);
$xmlpart = $responseXmlObject->xpath("//d:getlastmodified");
Assert::assertEquals(
$mtime, $xmlpart[0]->__toString()
);
Expand Down

0 comments on commit a0ed56e

Please sign in to comment.