-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
PVince81
merged 5 commits into
master
from
inttest-checksums-from-26655_ComputeChecksum2
Mar 17, 2017
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cee9935
Removed checksums context and integrate it with the rest
SergioBertolinSG a2257f0
Adapted tests to use new dav endpoint
SergioBertolinSG 2ba31b6
Added Ilja's tests here
SergioBertolinSG d3dd0c8
Copy will copy and not move
SergioBertolinSG 014530b
Webdav returns all checksums + integration tests
IljaN File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
} | ||
|
||
/** | ||
|
@@ -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"); | ||
} | ||
|
||
/** | ||
|
@@ -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"> | ||
|
@@ -111,7 +72,7 @@ public function userRequestTheChecksumOfViaPropfind($user, $path) | |
] | ||
] | ||
); | ||
$this->response = $this->client->send($request); | ||
$this->response = $client->send($request); | ||
} | ||
|
||
/** | ||
|
@@ -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 | ||
|
@@ -171,22 +114,22 @@ public function theHeaderChecksumShouldMatch($checksum) | |
* @param string $source | ||
* @param string $destination | ||
*/ | ||
public function userCopiedFileTo($user, $source, $destination) | ||
{ | ||
$request = $this->client->createRequest( | ||
public function userCopiedFileTo($user, $source, $destination) { | ||
$client = new Client(); | ||
$request = $client->createRequest( | ||
'MOVE', | ||
$this->baseUrl . '/remote.php/webdav' . $source, | ||
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); | ||
} | ||
|
||
/** | ||
|
@@ -227,23 +170,16 @@ 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) { | ||
//$client = new Client(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. commented out code |
||
$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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy does a move ? 🤕
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thats why I removed copy tests #27345 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll modify this function.