Merge pull request #11882 from nextcloud/feature/noid/consider-net-connection

Do not try to contact lookup server without internet connection or URL
This commit is contained in:
blizzz 2018-10-18 18:24:41 +02:00 committed by GitHub
commit 5daa4f27e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 108 additions and 27 deletions

View File

@ -50,10 +50,16 @@ class RetryJob extends Job {
$this->clientService = $clientService;
$this->jobList = $jobList;
if ($config->getSystemValue('has_internet_connection', true) === false) {
return;
}
$this->lookupServer = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com');
if (!empty($this->lookupServer)) {
$this->lookupServer = rtrim($this->lookupServer, '/');
$this->lookupServer .= '/users';
}
}
/**
* run the job, then remove it from the jobList
@ -69,7 +75,7 @@ class RetryJob extends Job {
}
protected function run($argument) {
if($argument['retryNo'] === 5) {
if ($argument['retryNo'] === 5 || empty($this->lookupServer)) {
return;
}

View File

@ -64,15 +64,25 @@ class UpdateLookupServer {
$this->signer = $signer;
$this->jobList = $jobList;
if($config->getSystemValue('has_internet_connection', true) === false) {
return;
}
$this->lookupServer = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com');
if(!empty($this->lookupServer)) {
$this->lookupServer = rtrim($this->lookupServer, '/');
$this->lookupServer .= '/users';
}
}
/**
* @param IUser $user
*/
public function userUpdated(IUser $user) {
if(empty($this->lookupServer)) {
return;
}
$userData = $this->accountManager->getUser($user);
$publicData = [];

View File

@ -63,12 +63,17 @@ class LookupPlugin implements ISearchPlugin {
public function search($search, $limit, $offset, ISearchResult $searchResult) {
$isGlobalScaleEnabled = $this->config->getSystemValue('gs.enabled', false);
$isLookupServerEnabled = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no') === 'yes';
$hasInternetConnection = (bool)$this->config->getSystemValue('has_internet_connection', true);
// if case of Global Scale we always search the lookup server
if (!$isLookupServerEnabled && !$isGlobalScaleEnabled) {
if ((!$isLookupServerEnabled && !$isGlobalScaleEnabled) || !$hasInternetConnection) {
return false;
}
$lookupServerUrl = $this->config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com');
if(empty($lookupServerUrl)) {
return false;
}
$lookupServerUrl = rtrim($lookupServerUrl, '/');
$result = [];

View File

@ -182,6 +182,9 @@ class VerifyUserData extends Job {
* @return bool true if we could check the verification code, otherwise false
*/
protected function verifyViaLookupServer(array $argument, $dataType) {
if(empty($this->lookupServerUrl) || $this->config->getSystemValue('has_internet_connection', true) === false) {
return false;
}
$user = $this->userManager->get($argument['uid']);

View File

@ -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,7 +160,12 @@ 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']);
@ -138,8 +195,6 @@ class LookupPluginTest extends TestCase {
$searchResult
);
$this->assertFalse($moreResults);
}
@ -170,6 +225,10 @@ class LookupPluginTest extends TestCase {
->with($type, $searchParams['expectedResult'], []);
$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);
}