diff --git a/lib/private/Session/CryptoSessionData.php b/lib/private/Session/CryptoSessionData.php index f6c585c161..23731ef456 100644 --- a/lib/private/Session/CryptoSessionData.php +++ b/lib/private/Session/CryptoSessionData.php @@ -141,6 +141,16 @@ class CryptoSessionData implements \ArrayAccess, ISession { $this->session->regenerateId($deleteOldSession); } + /** + * Wrapper around session_id + * + * @return string + * @since 9.1.0 + */ + public function getId() { + return $this->session->getId(); + } + /** * Close the session and release the lock, also writes all changed data in batch */ diff --git a/lib/private/Session/Internal.php b/lib/private/Session/Internal.php index 09175bf1f2..4fadb1ac80 100644 --- a/lib/private/Session/Internal.php +++ b/lib/private/Session/Internal.php @@ -111,6 +111,16 @@ class Internal extends Session { @session_regenerate_id($deleteOldSession); } + /** + * Wrapper around session_id + * + * @return string + * @since 9.1.0 + */ + public function getId() { + return @session_id(); + } + /** * @throws \Exception */ diff --git a/lib/private/Session/Memory.php b/lib/private/Session/Memory.php index 777458a9aa..3dba274f39 100644 --- a/lib/private/Session/Memory.php +++ b/lib/private/Session/Memory.php @@ -88,6 +88,16 @@ class Memory extends Session { */ public function regenerateId($deleteOldSession = true) {} + /** + * Wrapper around session_id + * + * @return string + * @since 9.1.0 + */ + public function getId() { + throw new \Exception('Memory session does not have an ID'); + } + /** * Helper function for PHPUnit execution - don't use in non-test code */ diff --git a/lib/public/isession.php b/lib/public/isession.php index 25c76906d6..16c6f9bc6a 100644 --- a/lib/public/isession.php +++ b/lib/public/isession.php @@ -95,4 +95,12 @@ interface ISession { * @since 9.0.0 */ public function regenerateId($deleteOldSession = true); + + /** + * Wrapper around session_id + * + * @return string + * @since 9.1.0 + */ + public function getId(); } diff --git a/tests/lib/session/memory.php b/tests/lib/session/memory.php index 1ca4956c6e..750fcf2ec6 100644 --- a/tests/lib/session/memory.php +++ b/tests/lib/session/memory.php @@ -10,8 +10,17 @@ namespace Test\Session; class Memory extends Session { + protected function setUp() { parent::setUp(); $this->instance = new \OC\Session\Memory($this->getUniqueID()); } + + /** + * @expectedException \Exception + */ + public function testThrowsExceptionOnGetId() { + $this->instance->getId(); + } + }