Commit 0d5695ce authored by Sergio Bertolin's avatar Sergio Bertolin
Browse files

Adapted favorites and dav2 features

parent 1a59d565
......@@ -12,6 +12,8 @@ trait WebDav {
/** @var string*/
private $davPath = "remote.php/webdav";
/** @var boolean*/
private $usingOldDavPath = true;
/** @var ResponseInterface */
private $response;
......@@ -22,6 +24,38 @@ trait WebDav {
$this->davPath = $davPath;
}
/**
* @Given /^using old dav path$/
*/
public function usingOldDavPath() {
$this->davPath = "remote.php/webdav";
$this->usingOldDavPath = true;
}
/**
* @Given /^using new dav path$/
*/
public function usingNewDavPath() {
$this->davPath = "remote.php/dav";
$this->usingOldDavPath = false;
}
/*public function getDavFilesPath($user){
if ($this->usingOldDavPath === true){
return $this->davPath . '/';
} else {
return $this->davPath . '/files/' . $user . '/';
}
}*/
public function getDavFilesPath($user){
if ($this->usingOldDavPath === true){
return $this->davPath;
} else {
return $this->davPath . '/files/' . $user;
}
}
public function getFilesPath($user){
$basePath = '';
if ($this->davPath === "remote.php/dav"){
......@@ -33,7 +67,7 @@ trait WebDav {
}
public function makeDavRequest($user, $method, $path, $headers, $body = null){
$fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath . "$path";
$fullUrl = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user) . "$path";
$client = new GClient();
$options = [];
if ($user === 'admin') {
......@@ -62,7 +96,7 @@ trait WebDav {
* @param string $fileDestination
*/
public function userMovedFile($user, $entry, $fileSource, $fileDestination){
$fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath;
$fullUrl = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user);
$headers['Destination'] = $fullUrl . $fileDestination;
$this->response = $this->makeDavRequest($user, "MOVE", $fileSource, $headers);
PHPUnit_Framework_Assert::assertEquals(201, $this->response->getStatusCode());
......@@ -75,7 +109,7 @@ trait WebDav {
* @param string $fileDestination
*/
public function userMovesFile($user, $entry, $fileSource, $fileDestination){
$fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath;
$fullUrl = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user);
$headers['Destination'] = $fullUrl . $fileDestination;
try {
$this->response = $this->makeDavRequest($user, "MOVE", $fileSource, $headers);
......@@ -91,7 +125,7 @@ trait WebDav {
* @param string $fileDestination
*/
public function userCopiesFile($user, $fileSource, $fileDestination){
$fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath;
$fullUrl = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user);
$headers['Destination'] = $fullUrl . $fileDestination;
try {
$this->response = $this->makeDavRequest($user, "COPY", $fileSource, $headers);
......@@ -344,7 +378,7 @@ trait WebDav {
}
public function makeSabrePath($user, $path) {
return $this->encodePath($this->davPath . $this->getFilesPath($user) . ltrim($path, '/'));
return $this->encodePath($this->getDavFilesPath($user));
}
public function getSabreClient($user) {
......@@ -375,7 +409,7 @@ trait WebDav {
$elementRows = $expectedElements->getRows();
$elementsSimplified = $this->simplifyArray($elementRows);
foreach($elementsSimplified as $expectedElement) {
$webdavPath = "/" . $this->davPath . $expectedElement;
$webdavPath = "/" . $this->getDavFilesPath($user) . $expectedElement;
if (!array_key_exists($webdavPath,$elementList)){
PHPUnit_Framework_Assert::fail("$webdavPath" . " is not in propfind answer");
}
......@@ -451,7 +485,7 @@ trait WebDav {
*/
public function userCreatedAFolder($user, $destination){
try {
$this->response = $this->makeDavRequest($user, "MKCOL", $this->getFilesPath($user) . ltrim($destination, $this->getFilesPath($user)), []);
$this->response = $this->makeDavRequest($user, "MKCOL", $destination, []);
} catch (\GuzzleHttp\Exception\ServerException $e) {
// 4xx and 5xx responses cause an exception
$this->response = $e->getResponse();
......@@ -499,7 +533,7 @@ trait WebDav {
public function userMovesNewChunkFileWithIdToMychunkedfile($user, $id, $dest)
{
$source = '/uploads/'.$user.'/'.$id.'/.file';
$destination = substr($this->baseUrl, 0, -4) . $this->davPath . '/files/'.$user.$dest;
$destination = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user) . $dest;
$this->makeDavRequest($user, 'MOVE', $source, [
'Destination' => $destination
]);
......@@ -561,7 +595,7 @@ trait WebDav {
];
}
$response = $client->proppatch($this->davPath . $this->getFilesPath($user) . ltrim($path, '/'), $properties, $folderDepth);
$response = $client->proppatch($this->getDavFilesPath($user), $properties, $folderDepth);
return $response;
}
......
......@@ -3,24 +3,24 @@ Feature: dav-v2
Given using api version "1"
Scenario: moving a file new endpoint way
Given using dav path "remote.php/dav"
Given using new dav path
And As an "admin"
And user "user0" exists
When User "user0" moves file "/files/user0/textfile0.txt" to "/files/user0/FOLDER/textfile0.txt"
When User "user0" moves file "/textfile0.txt" to "/FOLDER/textfile0.txt"
Then the HTTP status code should be "201"
Scenario: download a file with range using new endpoint
Given using dav path "remote.php/dav"
Given using new dav path
And As an "admin"
And user "user0" exists
And As an "user0"
When Downloading file "/files/user0/welcome.txt" with range "bytes=51-77"
When Downloading file "/welcome.txt" with range "bytes=51-77"
Then Downloaded content should be "example file for developers"
Scenario: Downloading a file on the new endpoint should serve security headers
Given using dav path "remote.php/dav/files/admin/"
Given using new dav path
And As an "admin"
When Downloading file "welcome.txt"
When Downloading file "/welcome.txt"
Then The following headers should be set
|Content-Disposition|attachment; filename*=UTF-8''welcome.txt; filename="welcome.txt"|
|Content-Security-Policy|default-src 'none';|
......@@ -55,16 +55,16 @@ Feature: dav-v2
Then the HTTP status code should be "207"
Scenario: Uploading a file having 0B as quota
Given using dav path "remote.php/dav"
Given using new dav path
And As an "admin"
And user "user0" exists
And user "user0" has a quota of "0 B"
And As an "user0"
When User "user0" uploads file "data/textfile.txt" to "/files/user0/asdf.txt"
When User "user0" uploads file "data/textfile.txt" to "/asdf.txt"
Then the HTTP status code should be "507"
Scenario: Uploading a file as recipient using webdav new endpoint having quota
Given using dav path "remote.php/dav"
Given using new dav path
And As an "admin"
And user "user0" exists
And user "user1" exists
......@@ -78,5 +78,5 @@ Feature: dav-v2
| permissions | 31 |
| shareWith | user0 |
And As an "user0"
When User "user0" uploads file "data/textfile.txt" to "/files/user0/testquota/asdf.txt"
When User "user0" uploads file "data/textfile.txt" to "/testquota/asdf.txt"
Then the HTTP status code should be "201"
......@@ -3,7 +3,7 @@ Feature: favorite
Given using api version "1"
Scenario: Favorite a folder
Given using dav path "remote.php/webdav"
Given using old dav path
And As an "admin"
And user "user0" exists
When user "user0" favorites element "/FOLDER"
......@@ -12,7 +12,7 @@ Feature: favorite
And the single response should contain a property "{http://owncloud.org/ns}favorite" with value "1"
Scenario: Favorite and unfavorite a folder
Given using dav path "remote.php/webdav"
Given using old dav path
And As an "admin"
And user "user0" exists
When user "user0" favorites element "/FOLDER"
......@@ -22,7 +22,7 @@ Feature: favorite
And the single response should contain a property "{http://owncloud.org/ns}favorite" with value ""
Scenario: Favorite a file
Given using dav path "remote.php/webdav"
Given using old dav path
And As an "admin"
And user "user0" exists
When user "user0" favorites element "/textfile0.txt"
......@@ -31,7 +31,7 @@ Feature: favorite
And the single response should contain a property "{http://owncloud.org/ns}favorite" with value "1"
Scenario: Favorite and unfavorite a file
Given using dav path "remote.php/webdav"
Given using old dav path
And As an "admin"
And user "user0" exists
When user "user0" favorites element "/textfile0.txt"
......@@ -41,7 +41,7 @@ Feature: favorite
And the single response should contain a property "{http://owncloud.org/ns}favorite" with value ""
Scenario: Favorite a folder new endpoint
Given using dav path "remote.php/dav"
Given using new dav path
And As an "admin"
And user "user0" exists
When user "user0" favorites element "/FOLDER"
......@@ -50,7 +50,7 @@ Feature: favorite
And the single response should contain a property "{http://owncloud.org/ns}favorite" with value "1"
Scenario: Favorite and unfavorite a folder new endpoint
Given using dav path "remote.php/dav"
Given using new dav path
And As an "admin"
And user "user0" exists
When user "user0" favorites element "/FOLDER"
......@@ -60,7 +60,7 @@ Feature: favorite
And the single response should contain a property "{http://owncloud.org/ns}favorite" with value ""
Scenario: Favorite a file new endpoint
Given using dav path "remote.php/dav"
Given using new dav path
And As an "admin"
And user "user0" exists
When user "user0" favorites element "/textfile0.txt"
......@@ -69,7 +69,7 @@ Feature: favorite
And the single response should contain a property "{http://owncloud.org/ns}favorite" with value "1"
Scenario: Favorite and unfavorite a file new endpoint
Given using dav path "remote.php/dav"
Given using new dav path
And As an "admin"
And user "user0" exists
When user "user0" favorites element "/textfile0.txt"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment