From 83432b3c257101dcd90b1309adfcc69e863ebc5c Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Tue, 1 Dec 2015 13:36:55 +0100 Subject: add behat tests for 0 quota upload failure --- build/integration/data/textfile.txt | 3 +++ .../features/bootstrap/Provisioning.php | 14 ++++++++++++++ build/integration/features/bootstrap/WebDav.php | 22 ++++++++++++++++++++-- build/integration/features/webdav-related.feature | 7 +++++++ 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 build/integration/data/textfile.txt (limited to 'build') diff --git a/build/integration/data/textfile.txt b/build/integration/data/textfile.txt new file mode 100644 index 00000000000..efffdeff159 --- /dev/null +++ b/build/integration/data/textfile.txt @@ -0,0 +1,3 @@ +This is a testfile. + +Cheers. \ No newline at end of file diff --git a/build/integration/features/bootstrap/Provisioning.php b/build/integration/features/bootstrap/Provisioning.php index 05a8885d96d..86d476944fd 100644 --- a/build/integration/features/bootstrap/Provisioning.php +++ b/build/integration/features/bootstrap/Provisioning.php @@ -510,6 +510,20 @@ trait Provisioning { PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); } + /** + * @Given user :user has a quota of :quota + */ + public function userHasAQuotaOf($user, $quota) + { + $body = new \Behat\Gherkin\Node\TableNode([ + 0 => ['key', 'quota'], + 1 => ['value', $quota], + ]); + + // method used from BasicStructure trait + $this->sendingToWith("PUT", "/cloud/users/" . $user, $body); + } + /** * @BeforeScenario * @AfterScenario diff --git a/build/integration/features/bootstrap/WebDav.php b/build/integration/features/bootstrap/WebDav.php index 567f189c61e..8f0f30b377a 100644 --- a/build/integration/features/bootstrap/WebDav.php +++ b/build/integration/features/bootstrap/WebDav.php @@ -21,7 +21,7 @@ trait WebDav{ $this->davPath = $davPath; } - public function makeDavRequest($user, $method, $path, $headers){ + public function makeDavRequest($user, $method, $path, $headers, $body = null){ $fullUrl = substr($this->baseUrl, 0, -4) . $this->davPath . "$path"; $client = new GClient(); $options = []; @@ -36,6 +36,11 @@ trait WebDav{ $request->addHeader($key, $value); } } + + if (!is_null($body)) { + $request->setBody($body); + } + return $client->send($request); } @@ -115,7 +120,20 @@ trait WebDav{ } } } - + + /** + * @When User :user uploads file :source to :destination + */ + public function userUploadsAFileTo($user, $source, $destination) + { + $file = \GuzzleHttp\Stream\Stream::factory(fopen($source, 'r')); + try { + $this->response = $this->makeDavRequest($user, "PUT", $destination, [], $file); + } catch (\GuzzleHttp\Exception\ServerException $e) { + // 4xx and 5xx responses cause an exception + $this->response = $e->getResponse(); + } + } } diff --git a/build/integration/features/webdav-related.feature b/build/integration/features/webdav-related.feature index 16955e27063..56c4d07f0eb 100644 --- a/build/integration/features/webdav-related.feature +++ b/build/integration/features/webdav-related.feature @@ -16,6 +16,13 @@ Feature: sharing Then Downloaded content should be "example file for developers" + Scenario: Upload forbidden if quota is 0 + Given using dav path "remote.php/webdav" + And As an "admin" + And user "user0" exists + And user "user0" has a quota of "0" + When User "user0" uploads file "data/textfile.txt" to "/asdf.txt" + Then the HTTP status code should be "507" -- cgit v1.2.3