summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2017-09-27 17:46:24 +0200
committerMorris Jobke <hey@morrisjobke.de>2017-12-08 16:34:33 +0100
commit74b5ce8fd4311f0d6f6a59e0636d343807b79d74 (patch)
tree30e2a3f407b94909080aaa7d536c9fe13d8cc731 /lib/private
parentac2c26ffcbe63e64156fc7e0b0be4e3466430dcf (diff)
downloadnextcloud-server-74b5ce8fd4311f0d6f6a59e0636d343807b79d74.tar.gz
nextcloud-server-74b5ce8fd4311f0d6f6a59e0636d343807b79d74.zip
Some tests for the remote cloud api
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Remote/Api/OCS.php21
-rw-r--r--lib/private/Remote/Instance.php3
2 files changed, 21 insertions, 3 deletions
diff --git a/lib/private/Remote/Api/OCS.php b/lib/private/Remote/Api/OCS.php
index d7027ad3f4b..f02538ad03b 100644
--- a/lib/private/Remote/Api/OCS.php
+++ b/lib/private/Remote/Api/OCS.php
@@ -22,6 +22,7 @@
namespace OC\Remote\Api;
+use GuzzleHttp\Exception\ClientException;
use OC\ForbiddenException;
use OC\Remote\User;
use OCP\API;
@@ -39,8 +40,18 @@ class OCS extends ApiBase {
* @throws \Exception
*/
protected function request($method, $url, array $body = [], array $query = [], array $headers = []) {
- $response = json_decode(parent::request($method, '/ocs/v2.php/' . $url, $body, $query, $headers), true);
- if (!isset($result['ocs']) || !isset($result['ocs']['meta'])) {
+ try {
+ $response = json_decode(parent::request($method, '/ocs/v2.php/' . $url, $body, $query, $headers), true);
+ } catch (ClientException $e) {
+ if ($e->getResponse()->getStatusCode() === 404) {
+ throw new NotFoundException();
+ } else if ($e->getResponse()->getStatusCode() === 403 || $e->getResponse()->getStatusCode() === 401) {
+ throw new ForbiddenException();
+ } else {
+ throw $e;
+ }
+ }
+ if (!isset($response['ocs']) || !isset($response['ocs']['meta'])) {
throw new \Exception('Invalid ocs response');
}
if ($response['ocs']['meta']['statuscode'] === API::RESPOND_UNAUTHORISED) {
@@ -60,7 +71,11 @@ class OCS extends ApiBase {
return new User($this->request('get', 'cloud/users/' . $userId));
}
+ /**
+ * @return array The capabilities in the form of [$appId => [$capability => $value]]
+ */
public function getCapabilities() {
- return $this->request('get', 'cloud/capabilities');
+ $result = $this->request('get', 'cloud/capabilities');
+ return $result['capabilities'];
}
}
diff --git a/lib/private/Remote/Instance.php b/lib/private/Remote/Instance.php
index 3e8f22f4df4..f61fbe202ab 100644
--- a/lib/private/Remote/Instance.php
+++ b/lib/private/Remote/Instance.php
@@ -21,6 +21,7 @@
namespace OC\Remote;
+use OC\Remote\Api\NotFoundException;
use OCP\Http\Client\IClientService;
use OCP\ICache;
@@ -111,6 +112,8 @@ class Instance {
if ($status) {
$this->cache->set($key, $status, 5 * 60);
$this->status = $status;
+ } else {
+ throw new NotFoundException('Remote server not found at address ' . $this->url);
}
}
return $status;