Skip to content

Commit

Permalink
Merge pull request #110 from mikemunger/handle_decrypt_exception
Browse files Browse the repository at this point in the history
handle DecryptException when valid_from field is a non-encrypted valu…
  • Loading branch information
freekmurze authored Aug 3, 2022
2 parents 4af3550 + 3783cf9 commit 8879f19
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/EncryptedTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Carbon\CarbonInterface;
use DateTimeInterface;
use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Support\Facades\Date;
use Spatie\Honeypot\Exceptions\InvalidTimestamp;

Expand All @@ -24,7 +25,11 @@ public function __construct(string $encryptedTime)
{
$this->encryptedTime = $encryptedTime;

$timestamp = app('encrypter')->decrypt($encryptedTime);
try {
$timestamp = app('encrypter')->decrypt($encryptedTime);
} catch (DecryptException $e) {
throw InvalidTimestamp::make($encryptedTime);
}

if (! $this->isValidTimeStamp($timestamp)) {
throw InvalidTimestamp::make($timestamp);
Expand Down
3 changes: 3 additions & 0 deletions tests/HoneypotBladeDirectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Carbon\CarbonImmutable;
use Illuminate\Support\DateFactory;
use Spatie\Honeypot\Tests\TestClasses\FakeEncrypter;
use Spatie\Snapshots\MatchesSnapshots;
use Spatie\TestTime\TestTime;

Expand All @@ -15,6 +16,8 @@ public function setUp(): void
{
parent::setUp();

$this->swap('encrypter', new FakeEncrypter());

config()->set('honeypot.randomize_name_field_name', false);
}

Expand Down
3 changes: 1 addition & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Illuminate\Support\Facades\View;
use Livewire\LivewireServiceProvider;
use Spatie\Honeypot\HoneypotServiceProvider;
use Spatie\Honeypot\Tests\TestClasses\FakeEncrypter;

abstract class TestCase extends \Orchestra\Testbench\TestCase
{
Expand All @@ -20,7 +19,7 @@ public function setUp(): void

View::addLocation(__DIR__.'/views');

$this->swap('encrypter', new FakeEncrypter());
config()->set('app.key', 'base64:05V7tNPZKeo4DB3PT/Xzgw6qAKxVTAjUWWZ9YrzpBc0=');
}

protected function getPackageProviders($app)
Expand Down

0 comments on commit 8879f19

Please sign in to comment.