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

Adding integration tests to checksums #27345

Merged
merged 5 commits into from
Mar 17, 2017
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
2 changes: 1 addition & 1 deletion apps/dav/lib/Connector/Sabre/FilesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node)
});

$propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) {
$checksum = $node->getChecksum('sha1');
$checksum = $node->getChecksum();
if ($checksum === NULL || $checksum === '') {
return null;
}
Expand Down
2 changes: 0 additions & 2 deletions tests/integration/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ default:
baseUrl: http://localhost:8080
- CalDavContext:
baseUrl: http://localhost:8080
- ChecksumsContext:
baseUrl: http://localhost:8080
- CommandLineContext:
baseUrl: http://localhost:8080
ocPath: ../../
Expand Down
1 change: 1 addition & 0 deletions tests/integration/features/bootstrap/BasicStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ trait BasicStructure {

use Auth;
use Trashbin;
use Checksums;

/** @var string */
private $currentUser = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,20 @@
use GuzzleHttp\Client;
use GuzzleHttp\Message\ResponseInterface;

class ChecksumsContext implements \Behat\Behat\Context\Context {
/** @var string */
private $baseUrl;
/** @var Client */
private $client;
/** @var ResponseInterface */
private $response;

/**
* @param string $baseUrl
*/
public function __construct($baseUrl) {
$this->baseUrl = $baseUrl;

// in case of ci deployment we take the server url from the environment
$testServerUrl = getenv('TEST_SERVER_URL');
if ($testServerUrl !== false) {
$this->baseUrl = substr($testServerUrl, 0, -5);
}
}

/** @BeforeScenario */
public function setUpScenario() {
$this->client = new Client();
}

/** @AfterScenario */
public function tearDownScenario() {
}
trait Checksums {

use Webdav;

/**
* @param string $userName
* @return string
*/
private function getPasswordForUser($userName) {
if($userName === 'admin') {
return 'admin';
if ($userName === 'admin') {
return $this->adminUser;
} else {
return $this->regularUser;
}
return '123456';
}

/**
Expand All @@ -54,27 +28,14 @@ private function getPasswordForUser($userName) {
* @param string $destination
* @param string $checksum
*/
public function userUploadsFileToWithChecksum($user, $source, $destination, $checksum)
{
public function userUploadsFileToWithChecksum($user, $source, $destination, $checksum) {
$file = \GuzzleHttp\Stream\Stream::factory(fopen($source, 'r'));
try {
$this->response = $this->client->put(
$this->baseUrl . '/remote.php/webdav' . $destination,
[
'auth' => [
$user,
$this->getPasswordForUser($user)
],
'body' => $file,
'headers' => [
'OC-Checksum' => $checksum
]
]
);
} catch (\GuzzleHttp\Exception\ServerException $e) {
// 4xx and 5xx responses cause an exception
$this->response = $e->getResponse();
}
$this->response = $this->makeDavRequest($user,
'PUT',
$destination,
['OC-Checksum' => $checksum],
$file,
"files");
}

/**
Expand All @@ -93,11 +54,11 @@ public function theWebdavResponseShouldHaveAStatusCode($statusCode) {
* @param string $user
* @param string $path
*/
public function userRequestTheChecksumOfViaPropfind($user, $path)
{
$request = $this->client->createRequest(
public function userRequestTheChecksumOfViaPropfind($user, $path) {
$client = new Client();
$request = $client->createRequest(
'PROPFIND',
$this->baseUrl . '/remote.php/webdav' . $path,
substr($this->baseUrl, 0, -4) . $this->getDavFilesPath($user) . $path,
[
'body' => '<?xml version="1.0"?>
<d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns">
Expand All @@ -111,7 +72,7 @@ public function userRequestTheChecksumOfViaPropfind($user, $path)
]
]
);
$this->response = $this->client->send($request);
$this->response = $client->send($request);
}

/**
Expand All @@ -135,24 +96,6 @@ public function theWebdavChecksumShouldMatch($checksum)
}
}

/**
* @When user :user downloads the file :path
* @param string $user
* @param string $path
*/
public function userDownloadsTheFile($user, $path)
{
$this->response = $this->client->get(
$this->baseUrl . '/remote.php/webdav' . $path,
[
'auth' => [
$user,
$this->getPasswordForUser($user),
]
]
);
}

/**
* @Then The header checksum should match :checksum
* @param string $checksum
Expand All @@ -171,22 +114,22 @@ public function theHeaderChecksumShouldMatch($checksum)
* @param string $source
* @param string $destination
*/
public function userCopiedFileTo($user, $source, $destination)
{
$request = $this->client->createRequest(
'MOVE',
$this->baseUrl . '/remote.php/webdav' . $source,
public function userCopiedFileTo($user, $source, $destination) {
$client = new Client();
$request = $client->createRequest(
'COPY',
substr($this->baseUrl, 0, -4) . $this->davPath . $source,
[
'auth' => [
$user,
$this->getPasswordForUser($user),
],
'headers' => [
'Destination' => $this->baseUrl . '/remote.php/webdav' . $destination,
'Destination' => substr($this->baseUrl, 0, -4) . $this->davPath . $destination,
],
]
);
$this->response = $this->client->send($request);
$this->response = $client->send($request);
}

/**
Expand Down Expand Up @@ -227,23 +170,15 @@ public function theOcChecksumHeaderShouldNotBeThere()
* @param string $destination
* @param string $checksum
*/
public function userUploadsChunkFileOfWithToWithChecksum($user, $num, $total, $data, $destination, $checksum)
{
public function userUploadsChunkFileOfWithToWithChecksum($user, $num, $total, $data, $destination, $checksum) {
$num -= 1;
$this->response = $this->client->put(
$this->baseUrl . '/remote.php/webdav' . $destination . '-chunking-42-'.$total.'-'.$num,
[
'auth' => [
$user,
$this->getPasswordForUser($user)
],
'body' => $data,
'headers' => [
'OC-Checksum' => $checksum,
'OC-Chunked' => '1',
]
]
);

$data = \GuzzleHttp\Stream\Stream::factory($data);
$file = $destination . '-chunking-42-' . $total . '-' . $num;
$this->response = $this->makeDavRequest($user,
'PUT',
$file,
['OC-Checksum' => $checksum, 'OC-Chunked' => '1'],
$data,
"files");
}
}
16 changes: 15 additions & 1 deletion tests/integration/features/bootstrap/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function makeDavRequest($user, $method, $path, $headers, $body = null, $t
} else {
$options['auth'] = [$user, $this->regularUser];
}

$request = $client->createRequest($method, $fullUrl, $options);
if (!is_null($headers)){
foreach ($headers as $key => $value) {
Expand Down Expand Up @@ -202,6 +203,19 @@ public function downloadingFile($fileName) {
}
}

/**
* @When user :user downloads the file :fileName
* @param string $user
* @param string $fileName
*/
public function userDownloadsTheFile($user, $fileName) {
try {
$this->response = $this->makeDavRequest($user, 'GET', $fileName, []);
} catch (\GuzzleHttp\Exception\ClientException $e) {
$this->response = $e->getResponse();
}
}

/**
* @Then The following headers should be set
* @param \Behat\Gherkin\Node\TableNode $table
Expand Down Expand Up @@ -563,7 +577,7 @@ public function userCreatedAFolder($user, $destination){
* @param string $data
* @param string $destination
*/
public function userUploadsChunkFileOfWithToWithChecksum($user, $num, $total, $data, $destination)
public function userUploadsChunkedFile($user, $num, $total, $data, $destination)
{
$num -= 1;
$data = \GuzzleHttp\Stream\Stream::factory($data);
Expand Down
Loading