Ejemplo n.º 1
0
 public function testPostException()
 {
     $client = $this->getMockBuilder('\\OCP\\Http\\Client\\IClient')->disableOriginalConstructor()->getMock();
     $this->clientService->expects($this->once())->method('newClient')->will($this->returnValue($client));
     $client->expects($this->once())->method('post')->with('https://owncloud.org', ['body' => ['Foo' => 'Bar'], 'connect_timeout' => 10])->will($this->throwException(new \Exception('Something failed')));
     $response = $this->httpHelperMock->post('https://owncloud.org', ['Foo' => 'Bar']);
     $expected = ['success' => false, 'result' => 'Something failed'];
     $this->assertSame($expected, $response);
 }
Ejemplo n.º 2
0
 /**
  * @param string $file the xml file to be loaded
  * @return null|array where null is an indicator for an error
  */
 public function parse($file)
 {
     if (!file_exists($file)) {
         return null;
     }
     libxml_use_internal_errors(true);
     $loadEntities = libxml_disable_entity_loader(false);
     $xml = simplexml_load_file($file);
     libxml_disable_entity_loader($loadEntities);
     if ($xml == false) {
         libxml_clear_errors();
         return null;
     }
     $array = $this->xmlToArray($xml);
     if (is_null($array)) {
         return null;
     }
     if (!array_key_exists('info', $array)) {
         $array['info'] = array();
     }
     if (!array_key_exists('remote', $array)) {
         $array['remote'] = array();
     }
     if (!array_key_exists('public', $array)) {
         $array['public'] = array();
     }
     if (!array_key_exists('types', $array)) {
         $array['types'] = array();
     }
     if (array_key_exists('documentation', $array) && is_array($array['documentation'])) {
         foreach ($array['documentation'] as $key => $url) {
             // If it is not an absolute URL we assume it is a key
             // i.e. admin-ldap will get converted to go.php?to=admin-ldap
             if (!$this->httpHelper->isHTTPURL($url)) {
                 $url = $this->urlGenerator->linkToDocs($url);
             }
             $array['documentation'][$key] = $url;
         }
     }
     if (array_key_exists('types', $array)) {
         if (is_array($array['types'])) {
             foreach ($array['types'] as $type => $v) {
                 unset($array['types'][$type]);
                 if (is_string($type)) {
                     $array['types'][] = $type;
                 }
             }
         } else {
             $array['types'] = array();
         }
     }
     return $array;
 }
Ejemplo n.º 3
0
 /**
  * inform remote server whether server-to-server share was accepted/declined
  *
  * @param string $remote
  * @param string $token
  * @param int $remoteId Share id on the remote host
  * @param string $feedback
  * @return boolean
  */
 private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback)
 {
     $url = rtrim($remote, '/') . \OCP\Share::BASE_PATH_TO_SHARE_API . '/' . $remoteId . '/' . $feedback . '?format=' . \OCP\Share::RESPONSE_FORMAT;
     $fields = array('token' => $token);
     $result = $this->httpHelper->post($url, $fields);
     $status = json_decode($result['result'], true);
     return $result['success'] && $status['ocs']['meta']['statuscode'] === 100;
 }
Ejemplo n.º 4
0
 /**
  * inform remote server whether server-to-server share was accepted/declined
  *
  * @param string $remote
  * @param string $token
  * @param int $remoteId Share id on the remote host
  * @param string $feedback
  * @return boolean
  */
 private function sendFeedbackToRemote($remote, $token, $remoteId, $feedback)
 {
     $url = rtrim($remote, '/') . $this->discoveryManager->getShareEndpoint($remote) . '/' . $remoteId . '/' . $feedback . '?format=' . \OCP\Share::RESPONSE_FORMAT;
     $fields = array('token' => $token);
     $result = $this->httpHelper->post($url, $fields);
     $status = json_decode($result['result'], true);
     return $result['success'] && ($status['ocs']['meta']['statuscode'] === 100 || $status['ocs']['meta']['statuscode'] === 200);
 }
Ejemplo n.º 5
0
 public function testCheckWithEmptyInvalidXmlResponse()
 {
     $expectedResult = [];
     $this->config->expects($this->at(0))->method('getAppValue')->with('core', 'lastupdatedat')->will($this->returnValue(0));
     $this->config->expects($this->at(1))->method('setAppValue')->with('core', 'lastupdatedat', $this->isType('integer'));
     $this->config->expects($this->at(3))->method('getAppValue')->with('core', 'installedat')->will($this->returnValue('installedat'));
     $this->config->expects($this->at(4))->method('getAppValue')->with('core', 'lastupdatedat')->will($this->returnValue('lastupdatedat'));
     $this->config->expects($this->at(5))->method('setAppValue')->with('core', 'lastupdateResult', json_encode($expectedResult));
     $updateXml = '';
     $this->httpHelper->expects($this->once())->method('getUrlContent')->with($this->buildUpdateUrl('https://updates.owncloud.com/server/'))->will($this->returnValue($updateXml));
     $this->assertSame($expectedResult, $this->updater->check());
 }
Ejemplo n.º 6
0
	/**
	 * Check if a new version is available
	 *
	 * @param string $updaterUrl the url to check, i.e. 'http://apps.owncloud.com/updater.php'
	 * @return array|bool
	 */
	public function check($updaterUrl = null) {

		// Look up the cache - it is invalidated all 30 minutes
		if (((int)$this->config->getAppValue('core', 'lastupdatedat') + 1800) > time()) {
			return json_decode($this->config->getAppValue('core', 'lastupdateResult'), true);
		}

		if (is_null($updaterUrl)) {
			$updaterUrl = 'https://apps.owncloud.com/updater.php';
		}

		$this->config->setAppValue('core', 'lastupdatedat', time());

		if ($this->config->getAppValue('core', 'installedat', '') == '') {
			$this->config->setAppValue('core', 'installedat', microtime(true));
		}

		$version = \OC_Util::getVersion();
		$version['installed'] = $this->config->getAppValue('core', 'installedat');
		$version['updated'] = $this->config->getAppValue('core', 'lastupdatedat');
		$version['updatechannel'] = \OC_Util::getChannel();
		$version['edition'] = \OC_Util::getEditionString();
		$version['build'] = \OC_Util::getBuild();
		$versionString = implode('x', $version);

		//fetch xml data from updater
		$url = $updaterUrl . '?version=' . $versionString;

		// set a sensible timeout of 10 sec to stay responsive even if the update server is down.

		$tmp = array();
		$xml = $this->httpHelper->getUrlContent($url);
		if ($xml) {
			$loadEntities = libxml_disable_entity_loader(true);
			$data = @simplexml_load_string($xml);
			libxml_disable_entity_loader($loadEntities);
			if ($data !== false) {
				$tmp['version'] = $data->version;
				$tmp['versionstring'] = $data->versionstring;
				$tmp['url'] = $data->url;
				$tmp['web'] = $data->web;
			}
		} else {
			$data = array();
		}

		// Cache the result
		$this->config->setAppValue('core', 'lastupdateResult', json_encode($data));
		return $tmp;
	}
Ejemplo n.º 7
0
 /**
  * @dataProvider isHttpTestData
  */
 public function testIsHTTP($url, $expected)
 {
     $this->assertSame($expected, $this->httpHelperMock->isHTTPURL($url));
 }