From 7aeda7c99a44b66ce122d6a24131648438d51d09 Mon Sep 17 00:00:00 2001 From: Sergio Bertolin Date: Wed, 11 Nov 2015 14:21:10 +0000 Subject: [PATCH 1/3] Added a test and logic for checking answer of public shares --- .../features/bootstrap/FeatureContext.php | 80 ++++++++++++++++--- build/integration/features/sharing-v1.feature | 19 +++++ 2 files changed, 89 insertions(+), 10 deletions(-) diff --git a/build/integration/features/bootstrap/FeatureContext.php b/build/integration/features/bootstrap/FeatureContext.php index 4a0299d6e49..96f46ce28ed 100644 --- a/build/integration/features/bootstrap/FeatureContext.php +++ b/build/integration/features/bootstrap/FeatureContext.php @@ -562,7 +562,30 @@ class FeatureContext implements Context, SnippetAcceptingContext { * @param \Behat\Gherkin\Node\TableNode|null $formData */ public function createPublicShare($body) { - $this->sendingToWith("POST", "/apps/files_sharing/api/v1/shares", $body); + $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v1/shares"; + $client = new Client(); + $options = []; + if ($this->currentUser === 'admin') { + $options['auth'] = $this->adminUser; + } else { + $options['auth'] = [$this->currentUser, $this->regularUser]; + } + + if ($body instanceof \Behat\Gherkin\Node\TableNode) { + $fd = $body->getRowsHash(); + if (array_key_exists('expireDate', $fd)){ + $dateModification = $fd['expireDate']; + $fd['expireDate'] = date('Y-m-d', strtotime($dateModification)); + } + $options['body'] = $fd; + } + + try { + $this->response = $client->send($client->createRequest("POST", $fullUrl, $options)); + } catch (\GuzzleHttp\Exception\ClientException $ex) { + $this->response = $ex->getResponse(); + } + $this->lastShareData = $this->response->xml(); } @@ -669,17 +692,48 @@ class FeatureContext implements Context, SnippetAcceptingContext { } - public function isFieldInResponse($field, $content_expected){ + public function isExpectedUrl($possibleUrl, $finalPart){ + $baseUrlChopped = substr($this->baseUrl, 0, -4); + $endCharacter = strlen($baseUrlChopped) + strlen($finalPart); + return (substr($possibleUrl,0,$endCharacter) == "$baseUrlChopped" . "$finalPart"); + } + + public function isFieldInResponse($field, $contentExpected){ $data = $this->response->xml()->data[0]; - foreach($data as $element) { - if ($content_expected == "A_NUMBER"){ - return is_numeric((string)$element->$field); - } - elseif ($element->$field == $content_expected){ - return True; - } + if ((string)$field == 'expiration'){ + $contentExpected = date('Y-m-d', strtotime($contentExpected)) . " 00:00:00"; + } + if (count($data->element) > 0){ + foreach($data as $element) { + if ($contentExpected == "A_TOKEN"){ + return (strlen((string)$element->$field) == 15); + } + elseif ($contentExpected == "A_NUMBER"){ + return is_numeric((string)$element->$field); + } + elseif($contentExpected == "AN_URL"){ + return $this->isExpectedUrl((string)$element->$field, "index.php/s/"); + } + elseif ($element->$field == $contentExpected){ + return True; + } + } + return False; + } else { + if ($contentExpected == "A_TOKEN"){ + return (strlen((string)$data->$field) == 15); + } + elseif ($contentExpected == "A_NUMBER"){ + return is_numeric((string)$data->$field); + } + elseif($contentExpected == "AN_URL"){ + return $this->isExpectedUrl((string)$data->$field, "index.php/s/"); + } + elseif ($data->$field == $contentExpected){ + return True; + } + return False; } - return False; } /** @@ -786,6 +840,9 @@ class FeatureContext implements Context, SnippetAcceptingContext { for ($i=0; $i<5; $i++){ file_put_contents("../../core/skeleton/" . "textfile" . "$i" . ".txt", "ownCloud test text file\n"); } + if (!file_exists("../../core/skeleton/FOLDER")) { + mkdir("../../core/skeleton/FOLDER", 0777, true); + } } @@ -796,6 +853,9 @@ class FeatureContext implements Context, SnippetAcceptingContext { for ($i=0; $i<5; $i++){ self::removeFile("../../core/skeleton/", "textfile" . "$i" . ".txt"); } + if (!is_dir("../../core/skeleton/FOLDER")) { + rmdir("../../core/skeleton/FOLDER"); + } } /** diff --git a/build/integration/features/sharing-v1.feature b/build/integration/features/sharing-v1.feature index 36e729d2a13..4ca1966b942 100644 --- a/build/integration/features/sharing-v1.feature +++ b/build/integration/features/sharing-v1.feature @@ -46,6 +46,25 @@ Feature: sharing And the HTTP status code should be "200" And Public shared file "welcome.txt" with password "publicpw" can be downloaded + Scenario: Creating a new public share of a folder + Given user "user0" exists + And As an "user0" + When creating a public share with + | path | FOLDER | + | shareType | 3 | + | password | publicpw | + | expireDate | +3 days | + | publicUpload | true | + | permissions | 7 | + Then the OCS status code should be "100" + And the HTTP status code should be "200" + And Share fields of last share match with + | id | A_NUMBER | + | permissions | 7 | + | expiration | +3 days | + | url | AN_URL | + | token | A_TOKEN | + Scenario: Creating a new public share with password and adding an expiration date Given user "user0" exists And As an "user0" From eb6a13c23147eaf7f8aa28cfaacea22ffcf3c43a Mon Sep 17 00:00:00 2001 From: Sergio Bertolin Date: Wed, 11 Nov 2015 17:29:38 +0000 Subject: [PATCH 2/3] Added a test including all the fields of the share update and checking output --- .../features/bootstrap/FeatureContext.php | 51 ++++++++++++++++++- build/integration/features/sharing-v1.feature | 38 +++++++++++++- 2 files changed, 86 insertions(+), 3 deletions(-) diff --git a/build/integration/features/bootstrap/FeatureContext.php b/build/integration/features/bootstrap/FeatureContext.php index 96f46ce28ed..46c86f1300b 100644 --- a/build/integration/features/bootstrap/FeatureContext.php +++ b/build/integration/features/bootstrap/FeatureContext.php @@ -595,7 +595,12 @@ class FeatureContext implements Context, SnippetAcceptingContext { public function checkPublicSharedFile($filename) { $client = new Client(); $options = []; - $url = $this->lastShareData->data[0]->url; + if (count($this->lastShareData->data->element) > 0){ + $url = $this->lastShareData->data[0]->url; + } + else{ + $url = $this->lastShareData->data->url; + } $fullUrl = $url . "/download"; $options['save_to'] = "./$filename"; $this->response = $client->get($fullUrl, $options); @@ -613,7 +618,13 @@ class FeatureContext implements Context, SnippetAcceptingContext { public function checkPublicSharedFileWithPassword($filename, $password) { $client = new Client(); $options = []; - $token = $this->lastShareData->data[0]->token; + if (count($this->lastShareData->data->element) > 0){ + $token = $this->lastShareData->data[0]->token; + } + else{ + $token = $this->lastShareData->data->token; + } + $fullUrl = substr($this->baseUrl, 0, -4) . "public.php/webdav"; $options['auth'] = [$token, $password]; $options['save_to'] = "./$filename"; @@ -645,6 +656,40 @@ class FeatureContext implements Context, SnippetAcceptingContext { PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); } + /** + * @When /^Updating last share with$/ + * @param \Behat\Gherkin\Node\TableNode|null $formData + */ + public function updatingLastShare($body) { + $share_id = $this->lastShareData->data[0]->id; + $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/apps/files_sharing/api/v{$this->sharingApiVersion}/shares/$share_id"; + $client = new Client(); + $options = []; + if ($this->currentUser === 'admin') { + $options['auth'] = $this->adminUser; + } else { + $options['auth'] = [$this->currentUser, $this->regularUser]; + } + + if ($body instanceof \Behat\Gherkin\Node\TableNode) { + $fd = $body->getRowsHash(); + if (array_key_exists('expireDate', $fd)){ + $dateModification = $fd['expireDate']; + $fd['expireDate'] = date('Y-m-d', strtotime($dateModification)); + } + $options['body'] = $fd; + } + + try { + $this->response = $client->send($client->createRequest("PUT", $fullUrl, $options)); + } catch (\GuzzleHttp\Exception\ClientException $ex) { + $this->response = $ex->getResponse(); + } + + PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode()); + } + + public function createShare($user, $path = null, $shareType = null, @@ -718,6 +763,7 @@ class FeatureContext implements Context, SnippetAcceptingContext { return True; } } + return False; } else { if ($contentExpected == "A_TOKEN"){ @@ -821,6 +867,7 @@ class FeatureContext implements Context, SnippetAcceptingContext { public function checkShareFields($body){ if ($body instanceof \Behat\Gherkin\Node\TableNode) { $fd = $body->getRowsHash(); + foreach($fd as $field => $value) { PHPUnit_Framework_Assert::assertEquals(True, $this->isFieldInResponse($field, $value)); } diff --git a/build/integration/features/sharing-v1.feature b/build/integration/features/sharing-v1.feature index 4ca1966b942..df75a25e8e7 100644 --- a/build/integration/features/sharing-v1.feature +++ b/build/integration/features/sharing-v1.feature @@ -72,11 +72,47 @@ Feature: sharing | path | welcome.txt | | shareType | 3 | | password | publicpw | - And Adding expiration date to last share + #And Adding expiration date to last share + And Updating last share with + | expireDate | +3 days | Then the OCS status code should be "100" And the HTTP status code should be "200" And Public shared file "welcome.txt" with password "publicpw" can be downloaded + Scenario: Creating a new public share, updating it and getting it's info + Given user "user0" exists + And As an "user0" + When creating a public share with + | path | FOLDER | + | shareType | 3 | + And Updating last share with + | expireDate | +3 days | + | password | publicpw | + | publicUpload | true | + | permissions | 7 | + And Getting info of last share + Then the OCS status code should be "100" + And the HTTP status code should be "200" + And Share fields of last share match with + | id | A_NUMBER | + | item_type | folder | + | item_source | A_NUMBER | + | share_type | 3 | + | file_source | A_NUMBER | + | file_target | /FOLDER | + | permissions | 7 | + | stime | A_NUMBER | + | expiration | +3 days | + | token | A_TOKEN | + | storage | A_NUMBER | + | mail_send | 0 | + | uid_owner | user0 | + | storage_id | home::user0 | + | file_parent | A_NUMBER | + | displayname_owner | user0 | + | url | AN_URL | + + Scenario: getting all shares of a user using that user Given user "user0" exists And user "user1" exists From ce8435530ba87c3574352d479d531caf2e0ab668 Mon Sep 17 00:00:00 2001 From: Sergio Bertolin Date: Thu, 12 Nov 2015 10:36:17 +0000 Subject: [PATCH 3/3] Modified test to PUT only 1 parameter with each update --- build/integration/features/sharing-v1.feature | 90 ++++++++++++++++++- 1 file changed, 86 insertions(+), 4 deletions(-) diff --git a/build/integration/features/sharing-v1.feature b/build/integration/features/sharing-v1.feature index df75a25e8e7..07c05af2f54 100644 --- a/build/integration/features/sharing-v1.feature +++ b/build/integration/features/sharing-v1.feature @@ -72,14 +72,13 @@ Feature: sharing | path | welcome.txt | | shareType | 3 | | password | publicpw | - #And Adding expiration date to last share And Updating last share with | expireDate | +3 days | Then the OCS status code should be "100" And the HTTP status code should be "200" And Public shared file "welcome.txt" with password "publicpw" can be downloaded - Scenario: Creating a new public share, updating it and getting it's info + Scenario: Creating a new public share, updating its expiration date and getting its info Given user "user0" exists And As an "user0" When creating a public share with @@ -87,8 +86,64 @@ Feature: sharing | shareType | 3 | And Updating last share with | expireDate | +3 days | + And Getting info of last share + Then the OCS status code should be "100" + And the HTTP status code should be "200" + And Share fields of last share match with + | id | A_NUMBER | + | item_type | folder | + | item_source | A_NUMBER | + | share_type | 3 | + | file_source | A_NUMBER | + | file_target | /FOLDER | + | permissions | 1 | + | stime | A_NUMBER | + | expiration | +3 days | + | token | A_TOKEN | + | storage | A_NUMBER | + | mail_send | 0 | + | uid_owner | user0 | + | storage_id | home::user0 | + | file_parent | A_NUMBER | + | displayname_owner | user0 | + | url | AN_URL | + + Scenario: Creating a new public share, updating its password and getting its info + Given user "user0" exists + And As an "user0" + When creating a public share with + | path | FOLDER | + | shareType | 3 | + And Updating last share with | password | publicpw | - | publicUpload | true | + And Getting info of last share + Then the OCS status code should be "100" + And the HTTP status code should be "200" + And Share fields of last share match with + | id | A_NUMBER | + | item_type | folder | + | item_source | A_NUMBER | + | share_type | 3 | + | file_source | A_NUMBER | + | file_target | /FOLDER | + | permissions | 1 | + | stime | A_NUMBER | + | token | A_TOKEN | + | storage | A_NUMBER | + | mail_send | 0 | + | uid_owner | user0 | + | storage_id | home::user0 | + | file_parent | A_NUMBER | + | displayname_owner | user0 | + | url | AN_URL | + + Scenario: Creating a new public share, updating its permissions and getting its info + Given user "user0" exists + And As an "user0" + When creating a public share with + | path | FOLDER | + | shareType | 3 | + And Updating last share with | permissions | 7 | And Getting info of last share Then the OCS status code should be "100" @@ -102,7 +157,6 @@ Feature: sharing | file_target | /FOLDER | | permissions | 7 | | stime | A_NUMBER | - | expiration | +3 days | | token | A_TOKEN | | storage | A_NUMBER | | mail_send | 0 | @@ -112,6 +166,34 @@ Feature: sharing | displayname_owner | user0 | | url | AN_URL | + Scenario: Creating a new public share, updating publicUpload option and getting its info + Given user "user0" exists + And As an "user0" + When creating a public share with + | path | FOLDER | + | shareType | 3 | + And Updating last share with + | publicUpload | true | + And Getting info of last share + Then the OCS status code should be "100" + And the HTTP status code should be "200" + And Share fields of last share match with + | id | A_NUMBER | + | item_type | folder | + | item_source | A_NUMBER | + | share_type | 3 | + | file_source | A_NUMBER | + | file_target | /FOLDER | + | permissions | 7 | + | stime | A_NUMBER | + | token | A_TOKEN | + | storage | A_NUMBER | + | mail_send | 0 | + | uid_owner | user0 | + | storage_id | home::user0 | + | file_parent | A_NUMBER | + | displayname_owner | user0 | + | url | AN_URL | Scenario: getting all shares of a user using that user Given user "user0" exists