diff options
Diffstat (limited to 'build/integration/features/bootstrap/ChecksumsContext.php')
-rw-r--r-- | build/integration/features/bootstrap/ChecksumsContext.php | 86 |
1 files changed, 26 insertions, 60 deletions
diff --git a/build/integration/features/bootstrap/ChecksumsContext.php b/build/integration/features/bootstrap/ChecksumsContext.php index af8f9e5590d..c8abf91127e 100644 --- a/build/integration/features/bootstrap/ChecksumsContext.php +++ b/build/integration/features/bootstrap/ChecksumsContext.php @@ -1,12 +1,17 @@ <?php +/** + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-or-later + */ require __DIR__ . '/../../vendor/autoload.php'; use GuzzleHttp\Client; use GuzzleHttp\Message\ResponseInterface; class ChecksumsContext implements \Behat\Behat\Context\Context { - /** @var string */ + /** @var string */ private $baseUrl; /** @var Client */ private $client; @@ -27,7 +32,7 @@ class ChecksumsContext implements \Behat\Behat\Context\Context { } /** @BeforeScenario */ - public function tearUpScenario() { + public function setUpScenario() { $this->client = new Client(); } @@ -41,7 +46,7 @@ class ChecksumsContext implements \Behat\Behat\Context\Context { * @return string */ private function getPasswordForUser($userName) { - if($userName === 'admin') { + if ($userName === 'admin') { return 'admin'; } return '123456'; @@ -54,9 +59,8 @@ class ChecksumsContext implements \Behat\Behat\Context\Context { * @param string $destination * @param string $checksum */ - public function userUploadsFileToWithChecksum($user, $source, $destination, $checksum) - { - $file = \GuzzleHttp\Stream\Stream::factory(fopen($source, 'r')); + public function userUploadsFileToWithChecksum($user, $source, $destination, $checksum) { + $file = \GuzzleHttp\Psr7\Utils::streamFor(fopen($source, 'r')); try { $this->response = $this->client->put( $this->baseUrl . '/remote.php/webdav' . $destination, @@ -83,8 +87,8 @@ class ChecksumsContext implements \Behat\Behat\Context\Context { * @throws \Exception */ public function theWebdavResponseShouldHaveAStatusCode($statusCode) { - if((int)$statusCode !== $this->response->getStatusCode()) { - throw new \Exception("Expected $statusCode, got ".$this->response->getStatusCode()); + if ((int)$statusCode !== $this->response->getStatusCode()) { + throw new \Exception("Expected $statusCode, got " . $this->response->getStatusCode()); } } @@ -93,9 +97,8 @@ class ChecksumsContext implements \Behat\Behat\Context\Context { * @param string $user * @param string $path */ - public function userRequestTheChecksumOfViaPropfind($user, $path) - { - $request = $this->client->createRequest( + public function userRequestTheChecksumOfViaPropfind($user, $path) { + $this->response = $this->client->request( 'PROPFIND', $this->baseUrl . '/remote.php/webdav' . $path, [ @@ -111,7 +114,6 @@ class ChecksumsContext implements \Behat\Behat\Context\Context { ] ] ); - $this->response = $this->client->send($request); } /** @@ -119,8 +121,7 @@ class ChecksumsContext implements \Behat\Behat\Context\Context { * @param string $checksum * @throws \Exception */ - public function theWebdavChecksumShouldMatch($checksum) - { + public function theWebdavChecksumShouldMatch($checksum) { $service = new Sabre\Xml\Service(); $parsed = $service->parse($this->response->getBody()->getContents()); @@ -131,7 +132,7 @@ class ChecksumsContext implements \Behat\Behat\Context\Context { $checksums = $parsed[0]['value'][1]['value'][0]['value'][0]; if ($checksums['value'][0]['value'] !== $checksum) { - throw new \Exception("Expected $checksum, got ".$checksums['value'][0]['value']); + throw new \Exception("Expected $checksum, got " . $checksums['value'][0]['value']); } } @@ -140,8 +141,7 @@ class ChecksumsContext implements \Behat\Behat\Context\Context { * @param string $user * @param string $path */ - public function userDownloadsTheFile($user, $path) - { + public function userDownloadsTheFile($user, $path) { $this->response = $this->client->get( $this->baseUrl . '/remote.php/webdav' . $path, [ @@ -158,10 +158,9 @@ class ChecksumsContext implements \Behat\Behat\Context\Context { * @param string $checksum * @throws \Exception */ - public function theHeaderChecksumShouldMatch($checksum) - { - if ($this->response->getHeader('OC-Checksum') !== $checksum) { - throw new \Exception("Expected $checksum, got ".$this->response->getHeader('OC-Checksum')); + public function theHeaderChecksumShouldMatch($checksum) { + if ($this->response->getHeader('OC-Checksum')[0] !== $checksum) { + throw new \Exception("Expected $checksum, got " . $this->response->getHeader('OC-Checksum')[0]); } } @@ -171,9 +170,8 @@ class ChecksumsContext implements \Behat\Behat\Context\Context { * @param string $source * @param string $destination */ - public function userCopiedFileTo($user, $source, $destination) - { - $request = $this->client->createRequest( + public function userCopiedFileTo($user, $source, $destination) { + $this->response = $this->client->request( 'MOVE', $this->baseUrl . '/remote.php/webdav' . $source, [ @@ -186,14 +184,12 @@ class ChecksumsContext implements \Behat\Behat\Context\Context { ], ] ); - $this->response = $this->client->send($request); } /** * @Then The webdav checksum should be empty */ - public function theWebdavChecksumShouldBeEmpty() - { + public function theWebdavChecksumShouldBeEmpty() { $service = new Sabre\Xml\Service(); $parsed = $service->parse($this->response->getBody()->getContents()); @@ -204,46 +200,16 @@ class ChecksumsContext implements \Behat\Behat\Context\Context { $status = $parsed[0]['value'][1]['value'][1]['value']; if ($status !== 'HTTP/1.1 404 Not Found') { - throw new \Exception("Expected 'HTTP/1.1 404 Not Found', got ".$status); + throw new \Exception("Expected 'HTTP/1.1 404 Not Found', got " . $status); } } /** * @Then The OC-Checksum header should not be there */ - public function theOcChecksumHeaderShouldNotBeThere() - { + public function theOcChecksumHeaderShouldNotBeThere() { if ($this->response->hasHeader('OC-Checksum')) { - throw new \Exception("Expected no checksum header but got ".$this->response->getHeader('OC-Checksum')); + throw new \Exception('Expected no checksum header but got ' . $this->response->getHeader('OC-Checksum')[0]); } } - - /** - * @Given user :user uploads chunk file :num of :total with :data to :destination with checksum :checksum - * @param string $user - * @param int $num - * @param int $total - * @param string $data - * @param string $destination - * @param string $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', - ] - ] - ); - - } } |