File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -78,8 +78,8 @@ public function generateNewToken():string {
78
78
public function processAndVerify ($ postData ):void {
79
79
// Expect the token to be present on ALL post requests.
80
80
if (!is_array ($ postData )
81
- && method_exists ($ postData, " toArray " )) {
82
- $ postData = $ postData ->toArray ( );
81
+ && is_callable ($ postData-> toArray )) {
82
+ $ postData = call_user_func ( $ postData ->toArray );
83
83
}
84
84
85
85
if (!empty ($ postData )) {
Original file line number Diff line number Diff line change 3
3
4
4
use Gt \Csrf \Exception \CsrfException ;
5
5
use PHPUnit \Framework \TestCase ;
6
+ use stdClass ;
6
7
7
8
class TokenStoreTest extends TestCase {
8
9
const ONE_FORM
@@ -95,6 +96,34 @@ public function testValidToken() {
95
96
self ::assertNull ($ exception );
96
97
}
97
98
99
+ public function testValidTokenObj () {
100
+ $ tokenStore = new ArrayTokenStore ();
101
+ $ token = $ tokenStore ->generateNewToken ();
102
+ $ tokenStore ->saveToken ($ token );
103
+
104
+ $ post = new StdClass ();
105
+ $ post ->toArray = function () use ($ post ) {
106
+ $ array = [];
107
+
108
+ foreach ($ post as $ key => $ value ) {
109
+ $ array [$ key ] = $ value ;
110
+ }
111
+
112
+ return $ array ;
113
+ };
114
+ $ post ->doink = "binky " ;
115
+ $ post ->{HTMLDocumentProtector::$ TOKEN_NAME } = $ token ;
116
+
117
+ $ exception = null ;
118
+
119
+ try {
120
+ $ tokenStore ->processAndVerify ($ post );
121
+ }
122
+ catch (CsrfException $ exception ) {}
123
+
124
+ self ::assertNull ($ exception );
125
+ }
126
+
98
127
// check that repeated calls to the token generator result in unique tokens
99
128
public function testCodesAreUnique () {
100
129
$ sut = new ArrayTokenStore ();
You can’t perform that action at this time.
0 commit comments