diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2018-10-17 13:09:11 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2018-10-18 17:49:28 +0200 |
commit | 8e4ae23c487b29bd8ea1a6d7d81e6996957e86fb (patch) | |
tree | 988f2f5d48e5e0cd958867849f36674245d8ee05 /tests | |
parent | 7c8b3c1056d2549734ec4bb9ed547468ca2c2331 (diff) | |
download | nextcloud-server-8e4ae23c487b29bd8ea1a6d7d81e6996957e86fb.tar.gz nextcloud-server-8e4ae23c487b29bd8ea1a6d7d81e6996957e86fb.zip |
Do not try to contact lookup server without internet connection or URL
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Collaboration/Collaborators/LookupPluginTest.php | 99 |
1 files changed, 78 insertions, 21 deletions
diff --git a/tests/lib/Collaboration/Collaborators/LookupPluginTest.php b/tests/lib/Collaboration/Collaborators/LookupPluginTest.php index 9019176d246..98e4adf2a7c 100644 --- a/tests/lib/Collaboration/Collaborators/LookupPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/LookupPluginTest.php @@ -70,7 +70,7 @@ class LookupPluginTest extends TestCase { $this->userSession->expects($this->any())->method('getUser') ->willReturn($user); $this->cloudIdManager->expects($this->any())->method('resolveCloudId') - ->willReturnCallback(function($cloudId) { + ->willReturnCallback(function ($cloudId) { if ($cloudId === 'user@myNextcloud.net') { return new CloudId('user@myNextcloud.net', 'user', 'myNextcloud.net'); } @@ -87,6 +87,58 @@ class LookupPluginTest extends TestCase { ); } + public function testSearchNoLookupServerURI() { + $this->config->expects($this->once()) + ->method('getAppValue') + ->with('files_sharing', 'lookupServerEnabled', 'no') + ->willReturn('yes'); + $this->config->expects($this->at(0)) + ->method('getSystemValue') + ->with('gs.enabled', false) + ->willReturn(false); + + $this->config->expects($this->at(2)) + ->method('getSystemValue') + ->with('has_internet_connection', true) + ->willReturn(true); + $this->config->expects($this->at(3)) + ->method('getSystemValue') + ->with('lookup_server', 'https://lookup.nextcloud.com') + ->willReturn(''); + + $this->clientService->expects($this->never()) + ->method('newClient'); + + /** @var ISearchResult|\PHPUnit_Framework_MockObject_MockObject $searchResult */ + $searchResult = $this->createMock(ISearchResult::class); + + $this->plugin->search('foobar', 10, 0, $searchResult); + } + + public function testSearchNoInternet() { + $this->config->expects($this->once()) + ->method('getAppValue') + ->with('files_sharing', 'lookupServerEnabled', 'no') + ->willReturn('yes'); + $this->config->expects($this->at(0)) + ->method('getSystemValue') + ->with('gs.enabled', false) + ->willReturn(false); + + $this->config->expects($this->at(2)) + ->method('getSystemValue') + ->with('has_internet_connection', true) + ->willReturn(false); + + $this->clientService->expects($this->never()) + ->method('newClient'); + + /** @var ISearchResult|\PHPUnit_Framework_MockObject_MockObject $searchResult */ + $searchResult = $this->createMock(ISearchResult::class); + + $this->plugin->search('foobar', 10, 0, $searchResult); + } + /** * @dataProvider searchDataProvider * @param array $searchParams @@ -108,8 +160,13 @@ class LookupPluginTest extends TestCase { ->method('getSystemValue') ->with('gs.enabled', false) ->willReturn(false); + $this->config->expects($this->at(2)) ->method('getSystemValue') + ->with('has_internet_connection', true) + ->willReturn(true); + $this->config->expects($this->at(3)) + ->method('getSystemValue') ->with('lookup_server', 'https://lookup.nextcloud.com') ->willReturn($searchParams['server']); @@ -121,7 +178,7 @@ class LookupPluginTest extends TestCase { $client = $this->createMock(IClient::class); $client->expects($this->once()) ->method('get') - ->willReturnCallback(function($url) use ($searchParams, $response) { + ->willReturnCallback(function ($url) use ($searchParams, $response) { $this->assertSame(strpos($url, $searchParams['server'] . '/users?search='), 0); $this->assertNotFalse(strpos($url, urlencode($searchParams['search']))); return $response; @@ -138,8 +195,6 @@ class LookupPluginTest extends TestCase { $searchResult ); - - $this->assertFalse($moreResults); } @@ -171,6 +226,10 @@ class LookupPluginTest extends TestCase { $this->config->expects($this->at(2)) ->method('getSystemValue') + ->with('has_internet_connection', true) + ->willReturn(true); + $this->config->expects($this->at(3)) + ->method('getSystemValue') ->with('lookup_server', 'https://lookup.nextcloud.com') ->willReturn($searchParams['server']); @@ -201,8 +260,6 @@ class LookupPluginTest extends TestCase { $searchResult ); - - $this->assertFalse($moreResults); } @@ -237,9 +294,9 @@ class LookupPluginTest extends TestCase { 'offset' => 0, 'server' => 'https://lookup.example.io', 'resultBody' => [ - [ 'federationId' => $fedIDs[0] ], - [ 'federationId' => $fedIDs[1] ], - [ 'federationId' => $fedIDs[2] ], + ['federationId' => $fedIDs[0]], + ['federationId' => $fedIDs[1]], + ['federationId' => $fedIDs[2]], ], 'expectedResult' => [ [ @@ -276,9 +333,9 @@ class LookupPluginTest extends TestCase { 'offset' => 0, 'server' => 'https://lookup.example.io', 'resultBody' => [ - [ 'federationId' => $fedIDs[0] ], - [ 'federationId' => $fedIDs[1] ], - [ 'federationId' => $fedIDs[2] ], + ['federationId' => $fedIDs[0]], + ['federationId' => $fedIDs[1]], + ['federationId' => $fedIDs[2]], ], 'expectedResult' => [ [ @@ -315,9 +372,9 @@ class LookupPluginTest extends TestCase { 'offset' => 0, 'server' => 'https://lookup.example.io', 'resultBody' => [ - [ 'federationId' => $fedIDs[0] ], - [ 'federationId' => $fedIDs[1] ], - [ 'federationId' => $fedIDs[2] ], + ['federationId' => $fedIDs[0]], + ['federationId' => $fedIDs[1]], + ['federationId' => $fedIDs[2]], ], 'expectedResult' => [ [ @@ -354,9 +411,9 @@ class LookupPluginTest extends TestCase { 'offset' => 0, 'server' => 'https://lookup.example.io', 'resultBody' => [ - [ 'federationId' => $fedIDs[0] ], - [ 'federationId' => $fedIDs[1] ], - [ 'federationId' => $fedIDs[2] ], + ['federationId' => $fedIDs[0]], + ['federationId' => $fedIDs[1]], + ['federationId' => $fedIDs[2]], ], 'expectedResult' => [ [ @@ -405,9 +462,9 @@ class LookupPluginTest extends TestCase { 'offset' => 0, 'server' => 'https://lookup.example.io', 'resultBody' => [ - [ 'federationId' => $fedIDs[0] ], - [ 'federationId' => $fedIDs[1] ], - [ 'federationId' => $fedIDs[2] ], + ['federationId' => $fedIDs[0]], + ['federationId' => $fedIDs[1]], + ['federationId' => $fedIDs[2]], ], 'expectedResult' => [ [ |