Skip to content

Commit 61f8e85

Browse files
committedJan 28, 2017
Only throw TokenMismatchException if in debug mode
Closes #118
1 parent 1deef47 commit 61f8e85

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed
 

‎src/Form.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,11 @@ public function validate()
173173
$this->shouldValidate = false;
174174

175175
if (csrf(R::postData(self::CSRF_FIELD)) !== true) {
176-
throw new TokenMismatchException('The CSRF token was invalid.');
176+
if (Config::get('debug') === true) {
177+
throw new TokenMismatchException('The CSRF token was invalid.');
178+
}
179+
180+
$this->fail();
177181
}
178182

179183
if (parent::validates()) {

‎tests/FormTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Uniform\Tests;
44

5+
use C as Config;
56
use Uniform\Form;
67
use Jevets\Kirby\Flash;
78
use Uniform\Guards\Guard;
@@ -16,6 +17,7 @@ class FormTest extends TestCase
1617
public function setUp()
1718
{
1819
parent::setUp();
20+
Config::set('debug', true);
1921
$this->form = new FormStub;
2022
}
2123

@@ -35,6 +37,19 @@ public function testValidateCsrfException()
3537
$this->form->validate();
3638
}
3739

40+
public function testValidateCsrfExceptionNoDebug()
41+
{
42+
Config::set('debug', false);
43+
44+
try {
45+
$this->form->validate();
46+
$this->assertFalse($this->form->success());
47+
$this->assertFalse(true);
48+
} catch (Exception $e) {
49+
$this->assertEquals('Redirected', $e->getMessage());
50+
}
51+
}
52+
3853
public function testValidateCsrfSuccess()
3954
{
4055
$_POST['csrf_token'] = csrf();

0 commit comments

Comments
 (0)
Please sign in to comment.