diff options
author | Olivier Paroz <oparoz@users.noreply.github.com> | 2015-09-04 18:09:34 +0300 |
---|---|---|
committer | Olivier Paroz <oparoz@users.noreply.github.com> | 2015-09-04 18:09:34 +0300 |
commit | 98248fe47747189f63f757b2e799abc7300e7ea4 (patch) | |
tree | 19c135ffa8c075c7311244977b4d8f1458844bdc /tests | |
parent | d51094ea8af08e5885633952468effb4a595a85c (diff) | |
parent | 05543877274387b8d3bb236768c66284c01b8f23 (diff) |
Merge pull request #300 from owncloud/fix-public-side
Fix public routes
Diffstat (limited to 'tests')
-rw-r--r-- | tests/_support/Helper/Api.php | 12 | ||||
-rw-r--r-- | tests/_support/Step/Api/TokenUser.php | 16 | ||||
-rw-r--r-- | tests/api/ConnectWithTokenCest.php | 110 |
3 files changed, 138 insertions, 0 deletions
diff --git a/tests/_support/Helper/Api.php b/tests/_support/Helper/Api.php index 55b9c3ec..9e8cda69 100644 --- a/tests/_support/Helper/Api.php +++ b/tests/_support/Helper/Api.php @@ -51,6 +51,18 @@ class Api extends \Codeception\Module { return $sharedFile; } + /** + * @return mixed + * @throws \Codeception\Exception\ModuleException + */ + public function getSharedFolder() { + $sharedFolder['folder'] = $this->getModule('\Helper\DataSetup')->sharedFolder; + $sharedFolder['token'] = $this->getModule('\Helper\DataSetup')->sharedFolderToken; + $sharedFolder['password'] = $this->getModule('\Helper\DataSetup')->passwordForFolderShare; + + return $sharedFolder; + } + public function createBrokenConfig() { $this->getModule('\Helper\DataSetup') ->createBrokenConfig(); diff --git a/tests/_support/Step/Api/TokenUser.php b/tests/_support/Step/Api/TokenUser.php index 8a8120d6..8be4eaf8 100644 --- a/tests/_support/Step/Api/TokenUser.php +++ b/tests/_support/Step/Api/TokenUser.php @@ -31,4 +31,20 @@ class TokenUser extends \ApiTester { return $fileMetaData; } + /** + * Retrieves the shared folder and its token + */ + public function getSharedFolderInformation() { + $I = $this; + $sharedFolder = $I->getSharedFolder(); + + $folderMetaData = [ + 'fileId' => $sharedFolder['folder']->getId(), + 'name' => $sharedFolder['folder']->getName(), + 'token' => $sharedFolder['token'], + 'password' => $sharedFolder['password'] + ]; + + return $folderMetaData; + } } diff --git a/tests/api/ConnectWithTokenCest.php b/tests/api/ConnectWithTokenCest.php new file mode 100644 index 00000000..bf558ddd --- /dev/null +++ b/tests/api/ConnectWithTokenCest.php @@ -0,0 +1,110 @@ +<?php +/** + * ownCloud - gallery + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Olivier Paroz <owncloud@interfasys.ch> + * + * @copyright Olivier Paroz 2015 + */ + +use Page\Gallery as GalleryApp; + +/** + * Class ConnectWithTokenCest + */ +class ConnectWithTokenCest { + + private $folderMetaData; + private $browserHeader = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'; + + public function _before(\Step\Api\TokenUser $I) { + $this->folderMetaData = $I->getSharedFolderInformation(); + } + + public function _after(ApiTester $I) { + } + + public function connectToConfig(\Step\Api\TokenUser $I) { + $I->am('a guest with a token'); + $I->wantTo('make sure I can get the config'); + + $this->connect($I, GalleryApp::$URL . '/config.public'); + $I->seeResponseIsJson(); + $I->seeResponseCodeIs(200); + } + + public function connectToFiles(\Step\Api\TokenUser $I) { + $I->am('a guest with a token'); + $I->wantTo('make sure I can get the files'); + + $this->connect($I, GalleryApp::$URL . '/files.public/list'); + $I->seeResponseIsJson(); + $I->seeResponseCodeIs(200); + } + + public function connectToThumbnails(\Step\Api\TokenUser $I) { + $I->am('a guest with a token'); + $I->wantTo('make sure I can get the thumbails'); + + + $data = $I->getFilesDataForFolder('shared1'); + $id1 = $data['testimage.eps']['id']; + $id2 = $data['testimage.gif']['id']; + $params = [ + 'ids' => $id1 . ';' . $id2, + 'square' => true, + 'scale' => 1.7 + ]; + + $this->connect($I, GalleryApp::$URL . '/thumbnails.public', $params, 'text/event-stream'); + $I->seeResponseCodeIs(200); + $I->seeHttpHeader('Content-type', 'text/event-stream;charset=UTF-8'); + $I->seeResponseContains('"status":200'); + $I->seeResponseContains('"fileid":"' . $id1 . '","status":200'); + $I->seeResponseContains('"fileid":"' . $id2 . '","status":200'); + } + + public function connectToPreview(\Step\Api\TokenUser $I) { + $I->am('a guest with a token'); + $I->wantTo('make sure I can get the preview'); + + $data = $I->getFilesDataForFolder('shared1'); + $file = $data['testimage.gif']; + $url = GalleryApp::$URL . '/preview.public/' . $file['id']; + $params = [ + 'width' => 800, + 'height' => 600 + ]; + $this->connect($I, $url, $params, $this->browserHeader); + $I->downloadAFile($file, 'testimage.gif'); + } + + private function connect( + \Step\Api\TokenUser $I, $url, $params = [], + $acceptHeaders = 'application/json, text/javascript, */*;q=0.01' + ) { + $I->haveHttpHeader('Accept', $this->browserHeader); + $I->sendGET('/'); + + $html = $I->grabResponse(); + $tidy = tidy_parse_string($html); + $head = $tidy->head(); + $requestToken = $head->attribute['data-requesttoken']; + + $I->haveHttpHeader('Accept', $acceptHeaders); + $I->haveHttpHeader('requesttoken', $requestToken); + + $params = array_merge( + $params, [ + 'token' => $this->folderMetaData['token'], + 'password' => $this->folderMetaData['password'] + ] + ); + + $I->sendGET($url, $params); + } + +} |