Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
3d1100c
Upgrade to php 8.4
Sep 8, 2025
bbaae01
Upgrade phpdi
Sep 8, 2025
338629f
Upgrade container interface methods
Sep 8, 2025
55e922c
Replace `\Zend\Diactoros` imports with `\Laminas\Diactoros`
Sep 8, 2025
c7790dc
Replace Blast Facades with own implementation
Sep 8, 2025
c3d8ceb
Fix facade tests
Sep 8, 2025
98b9d28
Replace `Logger::[level]` calls with `Level::[level]`
Oct 1, 2025
4d43027
Update mindplay/middleman ->dispatch to ->handle
Oct 1, 2025
106232f
Remove support for callable route destinations (removed in Rareloop r…
Oct 1, 2025
37224e1
Resolve `trigger_error` deprecations
Oct 1, 2025
dbc3874
Bump mmeyer2k/dcrypt
Oct 1, 2025
cc2aa78
Bump bugfix release of mikey179/vfsstream - fixes test failure
Oct 1, 2025
5f0c4c6
Rework encryption
Oct 1, 2025
9f30468
Re-support php >= 8.1
Oct 6, 2025
300e934
Refactor Facade -> AbstractFacade
Oct 6, 2025
ea77350
Switch to Spatie/ignition
Oct 6, 2025
9cf7e13
Upgrade phpunit config
Oct 6, 2025
7bbeb1b
Remove php84 syntax from Application
Oct 7, 2025
27a4e6d
Implement SAPIEmitter and resolve old symfony error usage
Oct 7, 2025
e0d6f55
Roll collections version back to 10 to support PHP 8.1
Oct 8, 2025
9fabb30
Ensure illuminate/encryption is also on v10
Oct 8, 2025
9181ded
Revert Rector changes
Oct 9, 2025
492a904
Formatting tweaks
Oct 9, 2025
4222a32
Update EncryptionServiceProvider
Oct 9, 2025
d69d636
Fix bug
Oct 9, 2025
366d39f
Fix PHP errors
Oct 9, 2025
2af859c
Fix namespaces
Oct 9, 2025
0b1e036
WIP refactor encrypter and tests
Oct 9, 2025
42a3199
Fix encryption and session storage
Oct 13, 2025
c4fb85b
Revert encryption changes
Oct 13, 2025
bba9526
Remove unused exceptions
Oct 13, 2025
b8b2311
Revert encryption-key change
Oct 13, 2025
b043f1f
Update composer file to use pinned versions
Oct 13, 2025
521bf22
Tweak CI file
Oct 13, 2025
7863e62
Use php-actions/composer@v6
Oct 13, 2025
efbb11f
Test removing repositories
Oct 13, 2025
3614c0e
Test
Oct 13, 2025
96088c8
Test
Oct 13, 2025
1058e8c
Add repository back in
Oct 14, 2025
0b6e032
Bring forked dcrypt library into core
Oct 14, 2025
fd519af
Update dependencies
Oct 14, 2025
11e6cc7
Fix PHPCS issue
Oct 14, 2025
f961127
Make session storage a bit more resilliant
Oct 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Session/EncryptedStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@ protected function prepareForStorage($data)

protected function prepareForUnserialize($data)
{
if ($data === '') {
return '';
}

try {
return $this->encrypter->decrypt($data);
} catch (Exception $e) {
$this->exceptionHandler->report($e);
$this->exceptionHandler?->report($e);
Comment thread
adamtomat marked this conversation as resolved.
return '';
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/Session/FileSessionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@

class FileSessionHandler implements SessionHandlerInterface
{
public function __construct(protected $path, protected $prefix = 'lumberjack_session_')
protected $path;
protected $prefix;

public function __construct($path, $prefix = 'lumberjack_session_')
{
$this->path = $path;
$this->prefix = $prefix;
}

#[\ReturnTypeWillChange]
Expand Down
4 changes: 3 additions & 1 deletion src/Session/SessionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Rareloop\Lumberjack\Application;
use Rareloop\Lumberjack\Config;
use Rareloop\Lumberjack\Contracts\Encrypter as EncrypterContract;
use Rareloop\Lumberjack\Exceptions\HandlerInterface;
use Rareloop\Lumberjack\Manager;

class SessionManager extends Manager
Expand Down Expand Up @@ -54,8 +55,9 @@ protected function buildSession($handler)

if ($this->config->get('session.encrypt')) {
$encrypter = $this->app->get(EncrypterContract::class);
$exceptionHandler = $this->app->get(HandlerInterface::class);

return new EncryptedStore($this->name, $handler, $encrypter, $sessionId);
return new EncryptedStore($this->name, $handler, $encrypter, $sessionId, $exceptionHandler);
}

return new Store($this->name, $handler, $sessionId);
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Exceptions/HandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,6 @@ class HandlerWithBlacklist extends Handler
];
}

class BlacklistedException extends \Exception
class BlacklistedException extends \Exception
{
}
44 changes: 36 additions & 8 deletions tests/Unit/Session/EncryptedStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,14 @@ public function data_is_decrypted_before_it_is_loaded()

/**
* @test
* @dataProvider unexpectedSessionData
*/
public function unexpected_session_data_is_handled_gracefully($previousSessionValue)
public function unexpected_session_data_is_handled_gracefully()
{
$encryptionKey = 'encryption-key';

// Use a mock handler to fake a previously stored state
$handler = Mockery::mock(NullSessionHandler::class . '[read]');
$handler->shouldReceive('read')->andReturn($previousSessionValue);
$handler->shouldReceive('read')->andReturn(@serialize(['foo' => 'bar']));

$errorHandler = Mockery::mock(HandlerInterface::class);
$errorHandler->shouldReceive('report')->once();
Expand All @@ -73,11 +72,40 @@ public function unexpected_session_data_is_handled_gracefully($previousSessionVa
$this->assertSame(null, $store->get('foo'));
}

public function unexpectedSessionData()
/**
* @test
*/
public function gracefully_handle_case_with_no_exception_handler()
{
return [
[@serialize(['foo' => 'bar'])],
[''],
];
$encryptionKey = 'encryption-key';

// Use a mock handler to fake a previously stored state
$handler = Mockery::mock(NullSessionHandler::class . '[read]');
$handler->shouldReceive('read')->andReturn(@serialize(['foo' => 'bar']));

$store = new EncryptedStore('session-name', $handler, new Encrypter($encryptionKey), 'session-id');
$store->start();

$this->assertSame(null, $store->get('foo'));
}

/**
* @test
*/
public function empty_session_data_is_ignored()
{
$encryptionKey = 'encryption-key';

// Use a mock handler to fake a previously stored state
$handler = Mockery::mock(NullSessionHandler::class . '[read]');
$handler->shouldReceive('read')->andReturn('');

$errorHandler = Mockery::mock(HandlerInterface::class);
$errorHandler->shouldNotHaveReceived('report');

$store = new EncryptedStore('session-name', $handler, new Encrypter($encryptionKey), 'session-id', $errorHandler);
$store->start();

$this->assertSame(null, $store->get('foo'));
}
}
27 changes: 20 additions & 7 deletions tests/Unit/Session/SessionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
namespace Rareloop\Lumberjack\Test;

use Mockery;
use ReflectionClass;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\TestCase;
use Rareloop\Lumberjack\Application;
use Rareloop\Lumberjack\Config;
use Rareloop\Lumberjack\Contracts\Encrypter as EncrypterContract;
use Rareloop\Lumberjack\Encrypter;
use Rareloop\Lumberjack\Application;
use Rareloop\Lumberjack\Session\Store;
use Rareloop\Lumberjack\Exceptions\Handler;
use Rareloop\Lumberjack\Session\EncryptedStore;
use Rareloop\Lumberjack\Session\FileSessionHandler;
use Rareloop\Lumberjack\Session\SessionManager;
use Rareloop\Lumberjack\Session\Store;
use Rareloop\Lumberjack\Session\FileSessionHandler;
use Rareloop\Lumberjack\Exceptions\HandlerInterface;
use Rareloop\Lumberjack\Test\Unit\Session\NullSessionHandler;
use org\bovigo\vfs\vfsStream;
use Rareloop\Lumberjack\Contracts\Encrypter as EncrypterContract;

class SessionManagerTest extends TestCase
{
Expand Down Expand Up @@ -93,12 +96,22 @@ public function can_create_an_unencrypted_store()
/** @test */
public function can_create_an_encrypted_store()
{
$app = $app = $this->appWithSessionDriverConfig('file', 'lumberjack', $encrypted = true);
$app = $this->appWithSessionDriverConfig('file', 'lumberjack', $encrypted = true);
$app->bind(EncrypterContract::class, new Encrypter('encryption-key'));

$handler = Mockery::mock(Handler::class);
$app->bind(HandlerInterface::class, $handler);

$manager = new SessionManager($app);

$this->assertInstanceOf(EncryptedStore::class, $manager->driver());
$driver = $manager->driver();
$this->assertInstanceOf(EncryptedStore::class, $driver);

$reflection = new ReflectionClass($driver);
$property = $reflection->getProperty('exceptionHandler');
$property->setAccessible(true);

$this->assertInstanceOf(HandlerInterface::class, $property->getValue($driver));
}
}

Expand Down