Skip to content

Commit 3062ceb

Browse files
fix(session): Log start errors
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
1 parent 04db454 commit 3062ceb

9 files changed

Lines changed: 17 additions & 22 deletions

File tree

cron.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
\OC::$server->getSession()->close();
5858

5959
// initialize a dummy memory session
60-
$session = new \OC\Session\Memory('');
60+
$session = new \OC\Session\Memory();
6161
$cryptoWrapper = \OC::$server->getSessionCryptoWrapper();
6262
$session = $cryptoWrapper->wrapSession($session);
6363
\OC::$server->setSession($session);

lib/base.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,10 @@ public static function initSession(): void {
443443

444444
try {
445445
// set the session name to the instance id - which is unique
446-
$session = new \OC\Session\Internal($sessionName);
446+
$session = new \OC\Session\Internal(
447+
Server::get(LoggerInterface::class),
448+
$sessionName
449+
);
447450

448451
$cryptoWrapper = Server::get(\OC\Session\CryptoWrapper::class);
449452
$session = $cryptoWrapper->wrapSession($session);

lib/private/Server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ public function __construct($webRoot, \OC\Config $config) {
512512

513513
$this->registerService(\OC\User\Session::class, function (Server $c) {
514514
$manager = $c->get(IUserManager::class);
515-
$session = new \OC\Session\Memory('');
515+
$session = new \OC\Session\Memory();
516516
$timeFactory = new TimeFactory();
517517
// Token providers might require a working database. This code
518518
// might however be called when Nextcloud is not yet setup.

lib/private/Session/Internal.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use OC\Authentication\Exceptions\InvalidTokenException;
3737
use OC\Authentication\Token\IProvider;
3838
use OCP\Session\Exceptions\SessionNotAvailableException;
39+
use Psr\Log\LoggerInterface;
3940

4041
/**
4142
* Class Internal
@@ -49,12 +50,15 @@ class Internal extends Session {
4950
* @param string $name
5051
* @throws \Exception
5152
*/
52-
public function __construct(string $name) {
53+
public function __construct(LoggerInterface $logger, string $name) {
5354
set_error_handler([$this, 'trapError']);
5455
$this->invoke('session_name', [$name]);
5556
try {
5657
$this->startSession();
5758
} catch (\Exception $e) {
59+
$logger->error('Could not start session: ' . $e->getMessage(), [
60+
'exception' => $e,
61+
]);
5862
setcookie($this->invoke('session_name'), '', -1, \OC::$WEBROOT ?: '/');
5963
}
6064
restore_error_handler();

lib/private/Session/Memory.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,7 @@
4040
* @package OC\Session
4141
*/
4242
class Memory extends Session {
43-
protected $data;
44-
45-
public function __construct(string $name) {
46-
//no need to use $name since all data is already scoped to this instance
47-
$this->data = [];
48-
}
43+
protected $data = [];
4944

5045
/**
5146
* @param string $key

lib/private/Session/Session.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@ abstract class Session implements \ArrayAccess, ISession {
3535
*/
3636
protected $sessionClosed = false;
3737

38-
/**
39-
* $name serves as a namespace for the session keys
40-
*
41-
* @param string $name
42-
*/
43-
abstract public function __construct(string $name);
44-
4538
/**
4639
* @param mixed $offset
4740
* @return bool

tests/lib/Session/CryptoSessionDataTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class CryptoSessionDataTest extends Session {
3434
protected function setUp(): void {
3535
parent::setUp();
3636

37-
$this->wrappedSession = new \OC\Session\Memory($this->getUniqueID());
37+
$this->wrappedSession = new \OC\Session\Memory();
3838
$this->crypto = $this->createMock(ICrypto::class);
3939
$this->crypto->expects($this->any())
4040
->method('encrypt')

tests/lib/Session/MemoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
class MemoryTest extends Session {
1313
protected function setUp(): void {
1414
parent::setUp();
15-
$this->instance = new \OC\Session\Memory($this->getUniqueID());
15+
$this->instance = new \OC\Session\Memory();
1616
}
1717

18-
18+
1919
public function testThrowsExceptionOnGetId() {
2020
$this->expectException(\OCP\Session\Exceptions\SessionNotAvailableException::class);
2121

tests/lib/User/SessionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ public function testActiveUserAfterSetSession() {
745745
return $users[$uid];
746746
});
747747

748-
$session = new Memory('');
748+
$session = new Memory();
749749
$session->set('user_id', 'foo');
750750
$userSession = $this->getMockBuilder(Session::class)
751751
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
@@ -758,7 +758,7 @@ public function testActiveUserAfterSetSession() {
758758

759759
$this->assertEquals($users['foo'], $userSession->getUser());
760760

761-
$session2 = new Memory('');
761+
$session2 = new Memory();
762762
$session2->set('user_id', 'bar');
763763
$userSession->setSession($session2);
764764
$this->assertEquals($users['bar'], $userSession->getUser());

0 commit comments

Comments
 (0)