protected function run($argument)
 {
     $target = $argument['url'];
     $source = $this->urlGenerator->getAbsoluteURL('/');
     $source = rtrim($source, '/');
     $token = $argument['token'];
     try {
         $result = $this->httpClient->get($target . $this->endPoint, ['query' => ['url' => $source, 'token' => $token], 'timeout' => 3, 'connect_timeout' => 3]);
         $status = $result->getStatusCode();
     } catch (ClientException $e) {
         $status = $e->getCode();
         $this->logger->logException($e);
     }
     // if we received a unexpected response we try again later
     if ($status !== Http::STATUS_OK && $status !== Http::STATUS_FORBIDDEN) {
         $this->jobList->add('OCA\\Federation\\BackgroundJob\\GetSharedSecret', $argument);
     } else {
         // reset token if we received a valid response
         $this->dbHandler->addToken($target, '');
     }
     if ($status === Http::STATUS_OK) {
         $body = $result->getBody();
         $result = json_decode($body, true);
         if (isset($result['ocs']['data']['sharedSecret'])) {
             $this->trustedServers->addSharedSecret($target, $result['ocs']['data']['sharedSecret']);
         } else {
             $this->logger->error('remote server "' . $target . '"" does not return a valid shared secret', ['app' => 'federation']);
             $this->trustedServers->setServerStatus($target, TrustedServers::STATUS_FAILURE);
         }
     }
 }
示例#2
0
 protected function run($argument)
 {
     $target = $argument['url'];
     $source = $this->urlGenerator->getAbsoluteURL('/');
     $source = rtrim($source, '/');
     $token = $argument['token'];
     $result = null;
     try {
         $result = $this->httpClient->get($target . $this->endPoint, ['query' => ['url' => $source, 'token' => $token], 'timeout' => 3, 'connect_timeout' => 3]);
         $status = $result->getStatusCode();
     } catch (ClientException $e) {
         $status = $e->getCode();
         if ($status === Http::STATUS_FORBIDDEN) {
             $this->logger->info($target . ' refused to exchange a shared secret with you.', ['app' => 'federation']);
         } else {
             $this->logger->logException($e, ['app' => 'federation']);
         }
     } catch (\Exception $e) {
         $status = Http::STATUS_INTERNAL_SERVER_ERROR;
         $this->logger->logException($e, ['app' => 'federation']);
     }
     // if we received a unexpected response we try again later
     if ($status !== Http::STATUS_OK && $status !== Http::STATUS_FORBIDDEN) {
         $this->retainJob = true;
     } else {
         // reset token if we received a valid response
         $this->dbHandler->addToken($target, '');
     }
     if ($status === Http::STATUS_OK && $result instanceof IResponse) {
         $body = $result->getBody();
         $result = json_decode($body, true);
         if (isset($result['ocs']['data']['sharedSecret'])) {
             $this->trustedServers->addSharedSecret($target, $result['ocs']['data']['sharedSecret']);
         } else {
             $this->logger->error('remote server "' . $target . '"" does not return a valid shared secret', ['app' => 'federation']);
             $this->trustedServers->setServerStatus($target, TrustedServers::STATUS_FAILURE);
         }
     }
 }
示例#3
0
 public function testSetServerStatus()
 {
     $this->dbHandler->expects($this->once())->method('setServerStatus')->with('url', 'status');
     $this->trustedServers->setServerStatus('url', 'status');
 }