1717use OCP \ICertificateManager ;
1818use OCP \IConfig ;
1919use OCP \Security \IRemoteHostValidator ;
20+ use OCP \ServerVersion ;
2021use PHPUnit \Framework \MockObject \MockObject ;
2122use Psr \Log \LoggerInterface ;
2223use function parse_url ;
@@ -36,6 +37,7 @@ class ClientTest extends \Test\TestCase {
3637 /** @var IRemoteHostValidator|MockObject */
3738 private IRemoteHostValidator $ remoteHostValidator ;
3839 private LoggerInterface $ logger ;
40+ private ServerVersion $ serverVersion ;
3941 /** @var array */
4042 private $ defaultRequestOptions ;
4143
@@ -46,12 +48,15 @@ protected function setUp(): void {
4648 $ this ->certificateManager = $ this ->createMock (ICertificateManager::class);
4749 $ this ->remoteHostValidator = $ this ->createMock (IRemoteHostValidator::class);
4850 $ this ->logger = $ this ->createMock (LoggerInterface::class);
51+ $ this ->serverVersion = $ this ->createMock (ServerVersion::class);
52+
4953 $ this ->client = new Client (
5054 $ this ->config ,
5155 $ this ->certificateManager ,
5256 $ this ->guzzleClient ,
5357 $ this ->remoteHostValidator ,
5458 $ this ->logger ,
59+ $ this ->serverVersion ,
5560 );
5661 }
5762
@@ -276,14 +281,17 @@ private function setUpDefaultRequestOptions(): void {
276281 ->with ()
277282 ->willReturn ('/my/path.crt ' );
278283
284+ $ this ->serverVersion ->method ('getVersionString ' )
285+ ->willReturn ('123.45.6 ' );
286+
279287 $ this ->defaultRequestOptions = [
280288 'verify ' => '/my/path.crt ' ,
281289 'proxy ' => [
282290 'http ' => 'foo ' ,
283291 'https ' => 'foo '
284292 ],
285293 'headers ' => [
286- 'User-Agent ' => 'Nextcloud Server Crawler ' ,
294+ 'User-Agent ' => 'Nextcloud- Server- Crawler/123.45.6 ' ,
287295 'Accept-Encoding ' => 'gzip ' ,
288296 ],
289297 'timeout ' => 30 ,
@@ -466,10 +474,13 @@ public function testSetDefaultOptionsWithNotInstalled(): void {
466474 ->expects ($ this ->never ())
467475 ->method ('listCertificates ' );
468476
477+ $ this ->serverVersion ->method ('getVersionString ' )
478+ ->willReturn ('123.45.6 ' );
479+
469480 $ this ->assertEquals ([
470481 'verify ' => \OC ::$ SERVERROOT . '/resources/config/ca-bundle.crt ' ,
471482 'headers ' => [
472- 'User-Agent ' => 'Nextcloud Server Crawler ' ,
483+ 'User-Agent ' => 'Nextcloud- Server- Crawler/123.45.6 ' ,
473484 'Accept-Encoding ' => 'gzip ' ,
474485 ],
475486 'timeout ' => 30 ,
@@ -513,14 +524,17 @@ public function testSetDefaultOptionsWithProxy(): void {
513524 ->with ()
514525 ->willReturn ('/my/path.crt ' );
515526
527+ $ this ->serverVersion ->method ('getVersionString ' )
528+ ->willReturn ('123.45.6 ' );
529+
516530 $ this ->assertEquals ([
517531 'verify ' => '/my/path.crt ' ,
518532 'proxy ' => [
519533 'http ' => 'foo ' ,
520534 'https ' => 'foo '
521535 ],
522536 'headers ' => [
523- 'User-Agent ' => 'Nextcloud Server Crawler ' ,
537+ 'User-Agent ' => 'Nextcloud- Server- Crawler/123.45.6 ' ,
524538 'Accept-Encoding ' => 'gzip ' ,
525539 ],
526540 'timeout ' => 30 ,
@@ -564,6 +578,9 @@ public function testSetDefaultOptionsWithProxyAndExclude(): void {
564578 ->with ()
565579 ->willReturn ('/my/path.crt ' );
566580
581+ $ this ->serverVersion ->method ('getVersionString ' )
582+ ->willReturn ('123.45.6 ' );
583+
567584 $ this ->assertEquals ([
568585 'verify ' => '/my/path.crt ' ,
569586 'proxy ' => [
@@ -572,7 +589,7 @@ public function testSetDefaultOptionsWithProxyAndExclude(): void {
572589 'no ' => ['bar ' ]
573590 ],
574591 'headers ' => [
575- 'User-Agent ' => 'Nextcloud Server Crawler ' ,
592+ 'User-Agent ' => 'Nextcloud- Server- Crawler/123.45.6 ' ,
576593 'Accept-Encoding ' => 'gzip ' ,
577594 ],
578595 'timeout ' => 30 ,
0 commit comments