summaryrefslogtreecommitdiffstats
path: root/lib/private/Remote/Api
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2017-10-20 17:48:49 +0200
committerMorris Jobke <hey@morrisjobke.de>2017-12-08 16:37:14 +0100
commit5ce69e7c426059474c1ac59a2086ac66f672e8b8 (patch)
tree8eb512879c3e3104a6b4c3b924d46e50e3d9685d /lib/private/Remote/Api
parentf1eb55fad77c25e63c90e4c132b16262c56d9cdf (diff)
downloadnextcloud-server-5ce69e7c426059474c1ac59a2086ac66f672e8b8.tar.gz
nextcloud-server-5ce69e7c426059474c1ac59a2086ac66f672e8b8.zip
Add some more tests for ocs remote api
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib/private/Remote/Api')
-rw-r--r--lib/private/Remote/Api/OCS.php21
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/private/Remote/Api/OCS.php b/lib/private/Remote/Api/OCS.php
index 5ce56621a71..a3a15302810 100644
--- a/lib/private/Remote/Api/OCS.php
+++ b/lib/private/Remote/Api/OCS.php
@@ -43,7 +43,7 @@ class OCS extends ApiBase implements ICapabilitiesApi, IUserApi {
*/
protected function request($method, $url, array $body = [], array $query = [], array $headers = []) {
try {
- $response = json_decode(parent::request($method, '/ocs/v2.php/' . $url, $body, $query, $headers), true);
+ $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();
@@ -69,14 +69,23 @@ class OCS extends ApiBase implements ICapabilitiesApi, IUserApi {
return $response['ocs']['data'];
}
- public function getUser($userId) {
- $result = $this->request('get', 'cloud/users/' . $userId);
- $keys = ['id', 'email', 'displayname', 'phone', 'address', 'website', 'groups', 'language', 'quota'];
+ /**
+ * @param array $data
+ * @param string $type
+ * @param string[] $keys
+ * @throws \Exception
+ */
+ private function checkResponseArray(array $data, $type, array $keys) {
foreach ($keys as $key) {
- if (!isset($result[$key])) {
- throw new \Exception('Invalid user response, expected field ' . $key . ' not found');
+ if (!array_key_exists($key, $data)) {
+ throw new \Exception('Invalid ' . $type . ' response, expected field ' . $key . ' not found');
}
}
+ }
+
+ public function getUser($userId) {
+ $result = $this->request('get', 'cloud/users/' . $userId);
+ $this->checkResponseArray($result, 'user', User::EXPECTED_KEYS);
return new User($result);
}