Skip to content
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
115 changes: 79 additions & 36 deletions build/integration/features/bootstrap/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ trait WebDav {

/** @var string*/
private $davPath = "remote.php/webdav";
/** @var boolean*/
private $usingOldDavPath = true;
/** @var ResponseInterface */
private $response;
/** @var map with user as key and another map as value, which has path as key and etag as value */
private $storedETAG = NULL;

/**
* @Given /^using dav path "([^"]*)"$/
Expand All @@ -22,18 +26,36 @@ public function usingDavPath($davPath) {
$this->davPath = $davPath;
}

public function getFilesPath(){
$basePath = '';
if ($this->davPath === "remote.php/dav"){
$basePath = '/files/' . $this->currentUser . '/';
/**
* @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 {
$basePath = '/';
return $this->davPath . '/files/' . $user;
}
return $basePath;
}

public function makeDavRequest($user, $method, $path, $headers, $body = null){
$fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath . "$path";
public function makeDavRequest($user, $method, $path, $headers, $body = null, $type = "files"){
if ( $type === "files" ){
$fullUrl = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user) . "$path";
} else if ( $type === "uploads" ){
$fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath . "$path";
}
$client = new GClient();
$options = [];
if ($user === 'admin') {
Expand Down Expand Up @@ -62,7 +84,7 @@ public function makeDavRequest($user, $method, $path, $headers, $body = null){
* @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());
Expand All @@ -75,7 +97,7 @@ public function userMovedFile($user, $entry, $fileSource, $fileDestination){
* @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);
Expand All @@ -91,7 +113,7 @@ public function userMovesFile($user, $entry, $fileSource, $fileDestination){
* @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);
Expand Down Expand Up @@ -220,12 +242,12 @@ public function downloadedContentShouldStartWith($start) {
}

/**
* @Then /^as "([^"]*)" gets properties of folder "([^"]*)" with$/
* @Then /^as "([^"]*)" gets properties of (file|folder|entry) "([^"]*)" with$/
* @param string $user
* @param string $path
* @param \Behat\Gherkin\Node\TableNode|null $propertiesTable
*/
public function asGetsPropertiesOfFolderWith($user, $path, $propertiesTable) {
public function asGetsPropertiesOfFolderWith($user, $elementType, $path, $propertiesTable) {
$properties = null;
if ($propertiesTable instanceof \Behat\Gherkin\Node\TableNode) {
foreach ($propertiesTable->getRows() as $row) {
Expand All @@ -243,7 +265,7 @@ public function asGetsPropertiesOfFolderWith($user, $path, $propertiesTable) {
*/
public function asTheFileOrFolderDoesNotExist($user, $entry, $path) {
$client = $this->getSabreClient($user);
$response = $client->request('HEAD', $this->makeSabrePath($path));
$response = $client->request('HEAD', $this->makeSabrePath($user, $path));
if ($response['statusCode'] !== 404) {
throw new \Exception($entry . ' "' . $path . '" expected to not exist (status code ' . $response['statusCode'] . ', expected 404)');
}
Expand Down Expand Up @@ -338,13 +360,14 @@ public function listFolder($user, $path, $folderDepth, $properties = null){
];
}

$response = $client->propfind($this->makeSabrePath($path), $properties, $folderDepth);
$response = $client->propfind($this->makeSabrePath($user, $path), $properties, $folderDepth);

return $response;
}

public function makeSabrePath($path) {
return $this->encodePath($this->davPath . '/' . ltrim($path, '/'));

public function makeSabrePath($user, $path) {
return $this->encodePath($this->getDavFilesPath($user) . $path);
}

public function getSabreClient($user) {
Expand Down Expand Up @@ -375,7 +398,7 @@ public function checkElementList($user, $expectedElements){
$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");
}
Expand Down Expand Up @@ -430,11 +453,12 @@ public function userUploadsAFileWithContentTo($user, $content, $destination)
}

/**
* @When User :user deletes file :file
* @When /^User "([^"]*)" deletes (file|folder) "([^"]*)"$/
* @param string $user
* @param string $type
* @param string $file
*/
public function userDeletesFile($user, $file) {
public function userDeletesFile($user, $type, $file) {
try {
$this->response = $this->makeDavRequest($user, 'DELETE', $file, []);
} catch (\GuzzleHttp\Exception\ServerException $e) {
Expand All @@ -450,7 +474,7 @@ public function userDeletesFile($user, $file) {
*/
public function userCreatedAFolder($user, $destination){
try {
$this->response = $this->makeDavRequest($user, "MKCOL", $this->getFilesPath() . ltrim($destination, $this->getFilesPath()), []);
$this->response = $this->makeDavRequest($user, "MKCOL", $destination, []);
} catch (\GuzzleHttp\Exception\ServerException $e) {
// 4xx and 5xx responses cause an exception
$this->response = $e->getResponse();
Expand All @@ -469,8 +493,8 @@ public function userUploadsChunkFileOfWithToWithChecksum($user, $num, $total, $d
{
$num -= 1;
$data = \GuzzleHttp\Stream\Stream::factory($data);
$file = $destination . '-chunking-42-'.$total.'-'.$num;
$this->makeDavRequest($user, 'PUT', $file, ['OC-Chunked' => '1'], $data);
$file = $destination . '-chunking-42-' . $total . '-' . $num;
$this->makeDavRequest($user, 'PUT', $file, ['OC-Chunked' => '1'], $data, "uploads");
}

/**
Expand All @@ -479,7 +503,7 @@ public function userUploadsChunkFileOfWithToWithChecksum($user, $num, $total, $d
public function userCreatesANewChunkingUploadWithId($user, $id)
{
$destination = '/uploads/'.$user.'/'.$id;
$this->makeDavRequest($user, 'MKCOL', $destination, []);
$this->makeDavRequest($user, 'MKCOL', $destination, [], null, "uploads");
}

/**
Expand All @@ -488,20 +512,20 @@ public function userCreatesANewChunkingUploadWithId($user, $id)
public function userUploadsNewChunkFileOfWithToId($user, $num, $data, $id)
{
$data = \GuzzleHttp\Stream\Stream::factory($data);
$destination = '/uploads/'.$user.'/'.$id.'/'.$num;
$this->makeDavRequest($user, 'PUT', $destination, [], $data);
$destination = '/uploads/'. $user .'/'. $id .'/' . $num;
$this->makeDavRequest($user, 'PUT', $destination, [], $data, "uploads");
}

/**
* @Given user :user moves new chunk file with id :id to :dest
*/
public function userMovesNewChunkFileWithIdToMychunkedfile($user, $id, $dest)
{
$source = '/uploads/'.$user.'/'.$id.'/.file';
$destination = substr($this->baseUrl, 0, -4) . $this->davPath . '/files/'.$user.$dest;
$source = '/uploads/' . $user . '/' . $id . '/.file';
$destination = substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user) . $dest;
$this->makeDavRequest($user, 'MOVE', $source, [
'Destination' => $destination
]);
], null, "uploads");
}


Expand Down Expand Up @@ -560,17 +584,36 @@ public function changeFavStateOfAnElement($user, $path, $favOrUnfav, $folderDept
];
}

$response = $client->proppatch($this->davPath . '/' . ltrim($path, '/'), $properties, $folderDepth);
$response = $client->proppatch($this->getDavFilesPath($user) . $path, $properties, $folderDepth);
return $response;
}

/**
* @Given user :user stores etag of element :path
*/
public function userStoresEtagOfElement($user, $path){
$propertiesTable = new \Behat\Gherkin\Node\TableNode([['{DAV:}getetag']]);
$this->asGetsPropertiesOfFolderWith($user, NULL, $path, $propertiesTable);
$pathETAG[$path] = $this->response['{DAV:}getetag'];
$this->storedETAG[$user]= $pathETAG;
print_r($this->storedETAG[$user][$path]);
}

/**
* @Then /^as "([^"]*)" gets properties of file "([^"]*)" with$/
* @param string $user
* @param string $path
* @param \Behat\Gherkin\Node\TableNode|null $propertiesTable
* @Then etag of element :path of user :user has not changed
*/
public function checkIfETAGHasNotChanged($path, $user){
$propertiesTable = new \Behat\Gherkin\Node\TableNode([['{DAV:}getetag']]);
$this->asGetsPropertiesOfFolderWith($user, NULL, $path, $propertiesTable);
PHPUnit_Framework_Assert::assertEquals($this->response['{DAV:}getetag'], $this->storedETAG[$user][$path]);
}

/**
* @Then etag of element :path of user :user has changed
*/
public function asGetsPropertiesOfFileWith($user, $path, $propertiesTable) {
$this->asGetsPropertiesOfFolderWith($user, $path, $propertiesTable);
public function checkIfETAGHasChanged($path, $user){
$propertiesTable = new \Behat\Gherkin\Node\TableNode([['{DAV:}getetag']]);
$this->asGetsPropertiesOfFolderWith($user, NULL, $path, $propertiesTable);
PHPUnit_Framework_Assert::assertNotEquals($this->response['{DAV:}getetag'], $this->storedETAG[$user][$path]);
}
}
17 changes: 9 additions & 8 deletions build/integration/features/dav-v2.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ Feature: dav-v2
When User "user0" moves file "/files/user0/textfile0.txt" to "/files/user0/abcde.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 'self'; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; frame-src *; img-src * data: blob:; font-src 'self' data:; media-src *; connect-src *|
Expand Down Expand Up @@ -55,16 +56,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
Expand All @@ -78,5 +79,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"
2 changes: 1 addition & 1 deletion build/integration/features/external-storage.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feature: external-storage
Background:
Given using api version "1"
Given using dav path "remote.php/webdav"
Given using old dav path

@local_storage
Scenario: Share by link a file inside a local external storage
Expand Down
45 changes: 41 additions & 4 deletions build/integration/features/favorites.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -40,3 +40,40 @@ Feature: favorite
|{http://owncloud.org/ns}favorite|
And the single response should contain a property "{http://owncloud.org/ns}favorite" with value ""

Scenario: Favorite a folder new endpoint
Given using new dav path
And As an "admin"
And user "user0" exists
When user "user0" favorites element "/FOLDER"
Then as "user0" gets properties of folder "/FOLDER" with
|{http://owncloud.org/ns}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 new dav path
And As an "admin"
And user "user0" exists
When user "user0" favorites element "/FOLDER"
And user "user0" unfavorites element "/FOLDER"
Then as "user0" gets properties of folder "/FOLDER" with
|{http://owncloud.org/ns}favorite|
And the single response should contain a property "{http://owncloud.org/ns}favorite" with value "0"

Scenario: Favorite a file new endpoint
Given using new dav path
And As an "admin"
And user "user0" exists
When user "user0" favorites element "/textfile0.txt"
Then as "user0" gets properties of file "/textfile0.txt" with
|{http://owncloud.org/ns}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 new dav path
And As an "admin"
And user "user0" exists
When user "user0" favorites element "/textfile0.txt"
And user "user0" unfavorites element "/textfile0.txt"
Then as "user0" gets properties of file "/textfile0.txt" with
|{http://owncloud.org/ns}favorite|
And the single response should contain a property "{http://owncloud.org/ns}favorite" with value "0"
Loading