throw SessionNotAvailableException if session_id returns empty string
This commit is contained in:
parent
0d53e86421
commit
e93bf80b29
|
@ -24,6 +24,7 @@ namespace OC\Session;
|
||||||
|
|
||||||
use OCP\ISession;
|
use OCP\ISession;
|
||||||
use OCP\Security\ICrypto;
|
use OCP\Security\ICrypto;
|
||||||
|
use OCP\Session\Exceptions\SessionNotAvailableException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class CryptoSessionData
|
* Class CryptoSessionData
|
||||||
|
@ -145,6 +146,7 @@ class CryptoSessionData implements \ArrayAccess, ISession {
|
||||||
* Wrapper around session_id
|
* Wrapper around session_id
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
|
* @throws SessionNotAvailableException
|
||||||
* @since 9.1.0
|
* @since 9.1.0
|
||||||
*/
|
*/
|
||||||
public function getId() {
|
public function getId() {
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
|
|
||||||
namespace OC\Session;
|
namespace OC\Session;
|
||||||
|
|
||||||
|
use OCP\Session\Exceptions\SessionNotAvailableException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Internal
|
* Class Internal
|
||||||
*
|
*
|
||||||
|
@ -115,10 +117,15 @@ class Internal extends Session {
|
||||||
* Wrapper around session_id
|
* Wrapper around session_id
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
|
* @throws SessionNotAvailableException
|
||||||
* @since 9.1.0
|
* @since 9.1.0
|
||||||
*/
|
*/
|
||||||
public function getId() {
|
public function getId() {
|
||||||
return @session_id();
|
$id = @session_id();
|
||||||
|
if ($id === '') {
|
||||||
|
throw new SessionNotAvailableException();
|
||||||
|
}
|
||||||
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -26,6 +26,9 @@
|
||||||
|
|
||||||
namespace OC\Session;
|
namespace OC\Session;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use OCP\Session\Exceptions\SessionNotAvailableException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Internal
|
* Class Internal
|
||||||
*
|
*
|
||||||
|
@ -92,10 +95,11 @@ class Memory extends Session {
|
||||||
* Wrapper around session_id
|
* Wrapper around session_id
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
|
* @throws SessionNotAvailableException
|
||||||
* @since 9.1.0
|
* @since 9.1.0
|
||||||
*/
|
*/
|
||||||
public function getId() {
|
public function getId() {
|
||||||
throw new \Exception('Memory session does not have an ID');
|
throw new SessionNotAvailableException('Memory session does not have an ID');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -108,11 +112,11 @@ class Memory extends Session {
|
||||||
/**
|
/**
|
||||||
* In case the session has already been locked an exception will be thrown
|
* In case the session has already been locked an exception will be thrown
|
||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function validateSession() {
|
private function validateSession() {
|
||||||
if ($this->sessionClosed) {
|
if ($this->sessionClosed) {
|
||||||
throw new \Exception('Session has been closed - no further changes to the session are allowed');
|
throw new Exception('Session has been closed - no further changes to the session are allowed');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Christoph Wurst <christoph@owncloud.com>
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||||
|
* @license AGPL-3.0
|
||||||
|
*
|
||||||
|
* This code is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3,
|
||||||
|
* as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace OCP\Session\Exceptions;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 9.1.0
|
||||||
|
*/
|
||||||
|
class SessionNotAvailableException extends Exception {
|
||||||
|
|
||||||
|
}
|
|
@ -100,6 +100,7 @@ interface ISession {
|
||||||
* Wrapper around session_id
|
* Wrapper around session_id
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
|
* @throws SessionNotAvailableException
|
||||||
* @since 9.1.0
|
* @since 9.1.0
|
||||||
*/
|
*/
|
||||||
public function getId();
|
public function getId();
|
||||||
|
|
|
@ -17,7 +17,7 @@ class Memory extends Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Exception
|
* @expectedException OCP\Session\Exceptions\SessionNotAvailableException
|
||||||
*/
|
*/
|
||||||
public function testThrowsExceptionOnGetId() {
|
public function testThrowsExceptionOnGetId() {
|
||||||
$this->instance->getId();
|
$this->instance->getId();
|
||||||
|
|
Loading…
Reference in New Issue