From b17d059b20e0366381e4ed0192b385436973f6e2 Mon Sep 17 00:00:00 2001 From: Tom Needham Date: Fri, 5 Jan 2018 12:23:12 +0000 Subject: [PATCH] Catch session unavailable exception --- lib/private/Session/Memory.php | 2 +- tests/lib/Session/CryptoSessionDataTest.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/private/Session/Memory.php b/lib/private/Session/Memory.php index 60aba4acbb65..a8f3c2584105 100644 --- a/lib/private/Session/Memory.php +++ b/lib/private/Session/Memory.php @@ -116,7 +116,7 @@ public function reopen() { */ private function validateSession() { if ($this->sessionClosed) { - throw new Exception('Session has been closed - no further changes to the session are allowed'); + throw new SessionNotAvailableException('Session has been closed - no further changes to the session are allowed'); } } } diff --git a/tests/lib/Session/CryptoSessionDataTest.php b/tests/lib/Session/CryptoSessionDataTest.php index 9447e8b6de96..bd5d6bb933dc 100644 --- a/tests/lib/Session/CryptoSessionDataTest.php +++ b/tests/lib/Session/CryptoSessionDataTest.php @@ -22,6 +22,7 @@ namespace Test\Session; use OC\Session\CryptoSessionData; +use OCP\Session\Exceptions\SessionNotAvailableException; class CryptoSessionDataTest extends Session { /** @var \PHPUnit_Framework_MockObject_MockObject|\OCP\Security\ICrypto */ @@ -50,4 +51,14 @@ protected function setUp() { $this->instance = new CryptoSessionData($this->wrappedSession, $this->crypto, 'PASS'); } + + /** + * Thrown exception during session destruct/close should be handled silently + */ + protected function testDestructExceptionCatching() { + $instance = new CryptoSessionData($this->wrappedSession, $this->crypto, 'PASS'); + $e = new SessionNotAvailableException(); + $this->wrappedSession->expects($this->once())->method('set')->willThrowException($e); + $instance->__destruct(); + } }