Skip to content

Commit

Permalink
Merge pull request #365 from unglaublicherdude/fix-behaviour-when-ica…
Browse files Browse the repository at this point in the history
…p-client-cannot-connect-to-socket

Get proper errer message when the connection to an ICAP Server fails
  • Loading branch information
icewind1991 authored Aug 12, 2024
2 parents edce5b6 + 6871a8a commit 1d77c62
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/ICAP/ICAPClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ protected function connect() {
$errorMessage,
$this->connectTimeout
);

socket_set_timeout($stream, 600);


if (!$stream) {
throw new RuntimeException(
"Cannot connect to \"tcp://{$this->host}:{$this->port}\": $errorMessage (code $errorCode)"
);
}

socket_set_timeout($stream, 600);

return $stream;
}

Expand Down
21 changes: 21 additions & 0 deletions tests/ICAP/ICAPClientTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Files_Antivirus\Tests\ICAP;

use OCA\Files_Antivirus\ICAP\ICAPClient;
use Test\TestCase;

class ICAPClientTest extends TestCase {
public function testConnect_ShouldThrowRuntimeException() {
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessageMatches('/Cannot connect to "tcp\:\/\/nothinghere\:8080"\: .*/');
$icapClient = new ICAPClient("nothinghere", 8080, 2);
$icapClient->respmod("myservice", [], [], []);
}
}
2 changes: 1 addition & 1 deletion tests/StatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace OCA\Files_Antivirus\Tests;

use \OCA\Files_Antivirus\Db\RuleMapper;
use OCA\Files_Antivirus\Db\RuleMapper;
use Psr\Log\LoggerInterface;

/**
Expand Down
4 changes: 4 additions & 0 deletions tests/stub.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ namespace OC\Files\Storage\Wrapper{
public function getWatcher() {
throw new \Exception('stub');
}

public function setOwner(?string $user): void {
throw new \Exception('stub');
}
}

class Jail extends Wrapper {
Expand Down

0 comments on commit 1d77c62

Please sign in to comment.