Catch exceptions on error of cloud id resolution

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2017-08-14 14:35:28 +02:00 committed by Morris Jobke
parent e0f479a4eb
commit 2e73112256
1 changed files with 21 additions and 5 deletions

View File

@ -336,7 +336,12 @@ class ShareesAPIController extends OCSController {
} }
$lowerSearch = strtolower($search); $lowerSearch = strtolower($search);
foreach ($cloudIds as $cloudId) { foreach ($cloudIds as $cloudId) {
list(, $serverUrl) = $this->splitUserRemote($cloudId); try {
list(, $serverUrl) = $this->splitUserRemote($cloudId);
} catch (\InvalidArgumentException $e) {
continue;
}
if (strtolower($contact['FN']) === $lowerSearch || strtolower($cloudId) === $lowerSearch) { if (strtolower($contact['FN']) === $lowerSearch || strtolower($cloudId) === $lowerSearch) {
if (strtolower($cloudId) === $lowerSearch) { if (strtolower($cloudId) === $lowerSearch) {
$result['exactIdMatch'] = true; $result['exactIdMatch'] = true;
@ -387,14 +392,14 @@ class ShareesAPIController extends OCSController {
* *
* @param string $address federated share address * @param string $address federated share address
* @return array [user, remoteURL] * @return array [user, remoteURL]
* @throws \Exception * @throws \InvalidArgumentException
*/ */
public function splitUserRemote($address) { public function splitUserRemote($address) {
try { try {
$cloudId = $this->cloudIdManager->resolveCloudId($address); $cloudId = $this->cloudIdManager->resolveCloudId($address);
return [$cloudId->getUser(), $cloudId->getRemote()]; return [$cloudId->getUser(), $cloudId->getRemote()];
} catch (\InvalidArgumentException $e) { } catch (\InvalidArgumentException $e) {
throw new \Exception('Invalid Federated Cloud ID', 0, $e); throw new \InvalidArgumentException('Invalid Federated Cloud ID', 0, $e);
} }
} }
@ -611,7 +616,12 @@ class ShareesAPIController extends OCSController {
if (isset($contact['isLocalSystemBook'])) { if (isset($contact['isLocalSystemBook'])) {
if ($exactEmailMatch) { if ($exactEmailMatch) {
$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]); try {
$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
} catch (\InvalidArgumentException $e) {
continue;
}
if (!$this->hasUserInResult($cloud->getUser())) { if (!$this->hasUserInResult($cloud->getUser())) {
$this->result['exact']['users'][] = [ $this->result['exact']['users'][] = [
'label' => $contact['FN'] . " ($emailAddress)", 'label' => $contact['FN'] . " ($emailAddress)",
@ -623,8 +633,14 @@ class ShareesAPIController extends OCSController {
} }
return ['results' => [], 'exact' => [], 'exactIdMatch' => true]; return ['results' => [], 'exact' => [], 'exactIdMatch' => true];
} }
if ($this->shareeEnumeration) { if ($this->shareeEnumeration) {
$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]); try {
$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
} catch (\InvalidArgumentException $e) {
continue;
}
if (!$this->hasUserInResult($cloud->getUser())) { if (!$this->hasUserInResult($cloud->getUser())) {
$this->result['users'][] = [ $this->result['users'][] = [
'label' => $contact['FN'] . " ($emailAddress)", 'label' => $contact['FN'] . " ($emailAddress)",