Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/gallery.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests/api
diff options
context:
space:
mode:
authorOlivier Paroz <github@oparoz.com>2015-08-19 23:44:24 +0300
committerOlivier Paroz <github@oparoz.com>2015-08-19 23:44:24 +0300
commit79b85c933c8eb2dadda746508ce39d3cc5580a36 (patch)
tree8a281e8c1a0f69c6d84104ae1bf26d618cfb8e6b /tests/api
parent309e8b4f81579dca11ffecb60ca9851156ac4cec (diff)
Test various config configuration and invalid folders
Diffstat (limited to 'tests/api')
-rw-r--r--tests/api/DownloadWithTokenCest.php27
-rw-r--r--tests/api/GetConfigCest.php134
-rw-r--r--tests/api/GetFilesCest.php40
-rw-r--r--tests/api/OcsCreateUserCest.php6
4 files changed, 166 insertions, 41 deletions
diff --git a/tests/api/DownloadWithTokenCest.php b/tests/api/DownloadWithTokenCest.php
index f2f12a0c..610bd1f9 100644
--- a/tests/api/DownloadWithTokenCest.php
+++ b/tests/api/DownloadWithTokenCest.php
@@ -27,7 +27,6 @@ class DownloadWithTokenCest {
*/
public function _before(\Step\Api\TokenUser $I) {
$this->apiUrl = GalleryApp::$URL . 's/';
- $I->haveHttpHeader('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8');
}
public function _after(ApiTester $I) {
@@ -38,7 +37,7 @@ class DownloadWithTokenCest {
$I->wantTo('insert a file in a forum');
$fileMetaData = $I->getSharedFileInformation();
- $I->haveHttpHeader('Accept',$this->browserHeader);
+ $I->haveHttpHeader('Accept', $this->browserHeader);
$I->sendGET($this->apiUrl . $fileMetaData['token']);
$I->downloadAFile($fileMetaData);
}
@@ -51,7 +50,7 @@ class DownloadWithTokenCest {
// Note: The share file is a PNG
$filename = 'jackinabox.png';
$url = $this->apiUrl . $fileMetaData['token'] . '/' . $filename;
- $I->haveHttpHeader('Accept',$this->browserHeader);
+ $I->haveHttpHeader('Accept', $this->browserHeader);
$I->sendGET($url);
$I->downloadAFile($fileMetaData, $filename);
}
@@ -66,9 +65,29 @@ class DownloadWithTokenCest {
$I->wantTo('insert a file in a forum');
$I->amGoingTo("send a bogus token");
$I->expectTo("be redirected to an error 400 page");
- $I->haveHttpHeader('Accept',$this->browserHeader);
+ $I->haveHttpHeader('Accept', $this->browserHeader);
$I->sendGET($this->apiUrl . '1AmaW1cK3d70k3N');
$I->seeResponseCodeIs(400);
$I->seeHttpHeader('Content-type', 'text/html; charset=UTF-8');
}
+
+ /**
+ * This is a special case to make sure we get a 404 in case of a missing token on the public
+ * download page
+ *
+ * @param \Step\Api\TokenUser $I
+ */
+ public function TryTodownloadFileWithoutAToken(\Step\Api\TokenUser $I) {
+ $I->am('a thief');
+ $I->wantTo('steal all the files I can get my hands on');
+
+ $fileMetaData = $I->getSharedFileInformation();
+ $params = [
+ 'fileId' => $fileMetaData['fileId']
+ ];
+ $I->haveHttpHeader('Accept', $this->browserHeader);
+ $I->sendGET(GalleryApp::$URL . '/files.public/download/{fileId}', $params);
+ $I->seeResponseCodeIs(404);
+ $I->seeHttpHeader('Content-type', 'text/html; charset=UTF-8');
+ }
}
diff --git a/tests/api/GetConfigCest.php b/tests/api/GetConfigCest.php
index 17bbc7ed..494369cd 100644
--- a/tests/api/GetConfigCest.php
+++ b/tests/api/GetConfigCest.php
@@ -20,6 +20,23 @@ use Page\Gallery as GalleryApp;
class GetConfigCest {
private $apiUrl;
+ private $params = [
+ 'extramediatypes' => false
+ ];
+ private $features = [
+ 'features' => [
+ 'external_shares' => 'yes',
+ 'native_svg' => 'no',
+ ]
+ ];
+ private $mediaTypes = [
+ "mediatypes" => [
+ "image/png" => "/core/img/filetypes/image.png",
+ "image/jpeg" => "/core/img/filetypes/image.png",
+ "image/gif" => "/core/img/filetypes/image.png",
+ "application/postscript" => "/core/img/filetypes/image-vector.png"
+ ]
+ ];
public function _before(ApiTester $I) {
$this->apiUrl = GalleryApp::$URL . 'api/config';
@@ -49,39 +66,16 @@ class GetConfigCest {
$I->am('an app');
$I->wantTo('get the current Gallery configuration');
- $I->getUserCredentialsAndUseHttpAuthentication();
- $params = ['extramediatypes' => false];
- $I->sendGET($this->apiUrl, $params);
- $I->seeResponseCodeIs(200);
- $I->seeResponseIsJson();
-
-
+ $this->tryToGetAValidConfig($I);
/**
* Warning: Needs to match what is in the test config
* If we automate the detection, we're dependant on the results created by a 3rd party lib
*/
- $I->seeResponseContainsJson(
- [
- 'features' => [
- 'external_shares' => 'yes',
- 'native_svg' => 'no',
- ]
- ]
- );
-
+ $I->seeResponseContainsJson($this->features);
/**
* TODO Replace with JSONPath once the library is fixed
*/
- $I->seeResponseContainsJson(
- [
- "mediatypes" => [
- "image/png" => "/core/img/filetypes/image.png",
- "image/jpeg" => "/core/img/filetypes/image.png",
- "image/gif" => "/core/img/filetypes/image.png",
- "application/postscript" => "/core/img/filetypes/image-vector.png"
- ]
- ]
- );
+ $I->seeResponseContainsJson($this->mediaTypes);
}
/**
@@ -95,12 +89,8 @@ class GetConfigCest {
$I->am('an app');
$I->wantTo('get the current Gallery configuration which should include extra media types');
- $I->getUserCredentialsAndUseHttpAuthentication();
$params = ['extramediatypes' => true];
- $I->sendGET($this->apiUrl, $params);
- $I->seeResponseCodeIs(200);
- $I->seeResponseIsJson();
-
+ $this->tryToGetAValidConfig($I, $params);
/**
* TODO Replace with JSONPath once the library is fixed
*/
@@ -118,4 +108,86 @@ class GetConfigCest {
);
}
+ /**
+ * @depends getConfig
+ *
+ * @param \Step\Api\User $I
+ */
+ public function getBadConfig(\Step\Api\User $I) {
+ $I->breakMyConfigFile();
+
+ $I->am('an app');
+ $I->wantTo('get the current Gallery configuration');
+ $I->expectTo('receive an error message');
+
+ $this->tryToGetAValidConfig($I);
+ /**
+ * Might be worth bringing the error object one level up
+ */
+ $I->seeResponseContainsJson(
+ [
+ 'features' => [
+ [
+ 'error' => [
+ 'message' => 'Problem while parsing the configuration file</br></br>Config location: /'
+ ]
+
+ ]
+ ]
+ ]
+ );
+
+ $I->fixMyConfigFile();
+ }
+
+ /**
+ * @depends getConfig
+ *
+ * @param \Step\Api\User $I
+ */
+ public function getConfigWithBom(\Step\Api\User $I) {
+ $I->createMyConfigFileWithABom();
+
+ $I->am('an app');
+ $I->wantTo('get the current Gallery configuration');
+ $I->expectTo('see the same config as in getConfig()');
+
+ $this->tryToGetAValidConfig($I);
+ $I->seeResponseContainsJson($this->features);
+ $I->seeResponseContainsJson($this->mediaTypes);
+
+ $I->fixMyConfigFile();
+ }
+
+ /**
+ * @depends getConfig
+ *
+ * @param \Step\Api\User $I
+ */
+ public function getEmptyConfig(\Step\Api\User $I) {
+ $I->emptyMyConfigFile();
+
+ $I->am('an app');
+ $I->wantTo('get the current Gallery configuration');
+ $I->expectTo('see empty features');
+
+ $this->tryToGetAValidConfig($I);
+ $I->seeResponseContainsJson(['features' => []]);
+ $I->seeResponseContainsJson($this->mediaTypes);
+
+ $I->fixMyConfigFile();
+ }
+
+ /**
+ * @param \Step\Api\User $I
+ */
+ private function tryToGetAValidConfig($I, $params = null) {
+ if (!$params) {
+ $params = $this->params;
+ }
+ $I->getUserCredentialsAndUseHttpAuthentication();
+ $I->sendGET($this->apiUrl, $params);
+ $I->seeResponseCodeIs(200);
+ $I->seeResponseIsJson();
+ }
}
diff --git a/tests/api/GetFilesCest.php b/tests/api/GetFilesCest.php
index c2eb5031..c6079b81 100644
--- a/tests/api/GetFilesCest.php
+++ b/tests/api/GetFilesCest.php
@@ -52,9 +52,7 @@ class GetFilesCest {
public function getStandardList(\Step\Api\User $I) {
$I->am('an app');
- $I->wantTo(
- 'get the list of available media files'
- );
+ $I->wantTo('get the list of available media files');
$I->getUserCredentialsAndUseHttpAuthentication();
$I->sendGET($this->apiUrl, $this->params);
@@ -91,4 +89,40 @@ class GetFilesCest {
$I->seeResponseContainsJson(['path' => 'folder2/testimagelarge.svg']);
}
+ public function getListOfRootWhenGivenBogusPath(\Step\Api\User $I) {
+ $params = $this->params;
+ $params['location'] = '/completely/lost in/tests';
+
+ $I->am('an app');
+ $I->wantTo(
+ 'get the list of files of the root folder when typing a deep path which is completely wrong'
+ );
+
+ $I->getUserCredentialsAndUseHttpAuthentication();
+ $I->sendGET($this->apiUrl, $params);
+ $I->seeResponseCodeIs(200);
+ $I->seeResponseIsJson();
+ $I->seeResponseContainsJson(['path' => 'testimage-corrupt.jpg']);
+ }
+
+ public function getListOfParentFolderWhenFolderHasTypo(\Step\Api\User $I) {
+ $params = $this->params;
+ // The correct path is /folder1/shared1/shared1.1, containing testimage.png
+ $params['location'] = '/folder1/shared1/shared1.2';
+
+ $I->am('an app');
+ $I->wantTo(
+ 'get the list of files of the parent folder when the last folder contains a typo'
+ );
+
+ $I->getUserCredentialsAndUseHttpAuthentication();
+ $I->sendGET($this->apiUrl, $params);
+ $I->seeResponseCodeIs(200);
+ $I->seeResponseIsJson();
+ // /folder1/shared1 only contains 2 files. Warning, alphabetical order
+ $I->seeResponseJsonMatchesXpath('//files[path[1]="folder1/shared1/testimage.eps"]');
+ // This is weird and might come from a bug in Codeception
+ $I->seeResponseJsonMatchesXpath('//files[path[1][1]="folder1/shared1/testimage.gif"]');
+ }
+
}
diff --git a/tests/api/OcsCreateUserCest.php b/tests/api/OcsCreateUserCest.php
index 1950f7b3..131baf07 100644
--- a/tests/api/OcsCreateUserCest.php
+++ b/tests/api/OcsCreateUserCest.php
@@ -33,7 +33,7 @@ class OcsCreateUserCest {
}
public function createUser(ApiTester $I, \Codeception\Scenario $scenario) {
- //$scenario->skip('ownCloud master is broken');
+ $scenario->skip('ownCloud master is broken');
$I->wantTo('create a user via the provisioning API');
$I->amHttpAuthenticated('admin', 'admin');
$I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded');
@@ -51,7 +51,7 @@ class OcsCreateUserCest {
}
public function checkUserExists(ApiTester $I, \Codeception\Scenario $scenario) {
- //$scenario->skip('ownCloud master is broken');
+ $scenario->skip('ownCloud master is broken');
$I->wantTo('make sure the user exists');
$I->amHttpAuthenticated('admin', 'admin');
$I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded');
@@ -67,7 +67,7 @@ class OcsCreateUserCest {
}
public function deleteUser(ApiTester $I, \Codeception\Scenario $scenario) {
- //$scenario->skip('ownCloud master is broken');
+ $scenario->skip('ownCloud master is broken');
$I->wantTo('delete the user');
$I->amHttpAuthenticated('admin', 'admin');
$I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded');