diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2020-07-13 14:07:19 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-13 14:07:19 +0300 |
commit | 70bbfeba83daae7eef64b6446e83c2f5992315e1 (patch) | |
tree | 8f523ae7422744f444f9c9c4dde9aead31bbd8e5 | |
parent | 3e834da3cf99205b82da67b70be3654d2dde9b42 (diff) | |
parent | c743a8f5726f26a397961a4a7a8a42deb26e5f01 (diff) |
Merge pull request #694 from nextcloud/backport/689/stable19
[stable19] Don't push without internet connection
-rw-r--r-- | lib/Push.php | 4 | ||||
-rw-r--r-- | tests/Unit/PushTest.php | 55 |
2 files changed, 59 insertions, 0 deletions
diff --git a/lib/Push.php b/lib/Push.php index 67241e0..f3922bd 100644 --- a/lib/Push.php +++ b/lib/Push.php @@ -108,6 +108,10 @@ class Push { } public function pushToDevice(int $id, INotification $notification, ?OutputInterface $output = null): void { + if (!$this->config->getSystemValueBool('has_internet_connection', true)) { + return; + } + $user = $this->userManager->get($notification->getUser()); if (!($user instanceof IUser)) { return; diff --git a/tests/Unit/PushTest.php b/tests/Unit/PushTest.php index 57efa14..be6c36d 100644 --- a/tests/Unit/PushTest.php +++ b/tests/Unit/PushTest.php @@ -125,6 +125,26 @@ class PushTest extends TestCase { ); } + public function testPushToDeviceNoInternet() { + $push = $this->getPush(); + + $this->config->expects($this->once()) + ->method('getSystemValueBool') + ->with('has_internet_connection', true) + ->willReturn(false); + $this->keyManager->expects($this->never()) + ->method('getKey'); + $this->clientService->expects($this->never()) + ->method('newClient'); + $this->userManager->expects($this->never()) + ->method('get'); + + /** @var INotification|MockObject$notification */ + $notification = $this->createMock(INotification::class); + + $push->pushToDevice(23, $notification); + } + public function testPushToDeviceInvalidUser() { $push = $this->getPush(); $this->keyManager->expects($this->never()) @@ -132,6 +152,11 @@ class PushTest extends TestCase { $this->clientService->expects($this->never()) ->method('newClient'); + $this->config->expects($this->once()) + ->method('getSystemValueBool') + ->with('has_internet_connection', true) + ->willReturn(true); + /** @var INotification|MockObject$notification */ $notification = $this->createMock(INotification::class); $notification->expects($this->once()) @@ -153,6 +178,11 @@ class PushTest extends TestCase { $this->clientService->expects($this->never()) ->method('newClient'); + $this->config->expects($this->once()) + ->method('getSystemValueBool') + ->with('has_internet_connection', true) + ->willReturn(true); + /** @var INotification|MockObject $notification */ $notification = $this->createMock(INotification::class); $notification->expects($this->exactly(2)) @@ -181,6 +211,11 @@ class PushTest extends TestCase { $this->clientService->expects($this->never()) ->method('newClient'); + $this->config->expects($this->once()) + ->method('getSystemValueBool') + ->with('has_internet_connection', true) + ->willReturn(true); + /** @var INotification|MockObject $notification */ $notification = $this->createMock(INotification::class); $notification->expects($this->exactly(3)) @@ -224,6 +259,11 @@ class PushTest extends TestCase { $this->clientService->expects($this->never()) ->method('newClient'); + $this->config->expects($this->once()) + ->method('getSystemValueBool') + ->with('has_internet_connection', true) + ->willReturn(true); + /** @var INotification|MockObject $notification */ $notification = $this->createMock(INotification::class); $notification->expects($this->exactly(3)) @@ -288,6 +328,11 @@ class PushTest extends TestCase { $this->clientService->expects($this->never()) ->method('newClient'); + $this->config->expects($this->once()) + ->method('getSystemValueBool') + ->with('has_internet_connection', true) + ->willReturn(true); + /** @var INotification|MockObject $notification */ $notification = $this->createMock(INotification::class); $notification->expects($this->exactly(2)) @@ -447,6 +492,11 @@ class PushTest extends TestCase { ->method('newClient') ->willReturn($client); + $this->config->expects($this->once()) + ->method('getSystemValueBool') + ->with('has_internet_connection', true) + ->willReturn(true); + $e = new \Exception(); $client->expects($this->at(0)) ->method('post') @@ -656,6 +706,11 @@ class PushTest extends TestCase { ->willReturn($response); } + $this->config->expects($this->once()) + ->method('getSystemValueBool') + ->with('has_internet_connection', true) + ->willReturn(true); + $push->pushToDevice(200718, $notification); } |