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:
commit
5daa4f27e1
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 = [];
|
||||
|
||||
|
|
|
@ -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 = [];
|
||||
|
||||
|
|
|
@ -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']);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue