@@ -44,7 +44,7 @@ public function testGetNonExistingToken($namespace, $manager, $storage, $generat
44
44
45
45
$ this ->assertInstanceOf (CsrfToken::class, $ token );
46
46
$ this ->assertSame ('token_id ' , $ token ->getId ());
47
- $ this ->assertSame ('TOKEN ' , $ token ->getValue ());
47
+ $ this ->assertNotSame ('TOKEN ' , $ token ->getValue ());
48
48
}
49
49
50
50
/**
@@ -66,7 +66,34 @@ public function testUseExistingTokenIfAvailable($namespace, $manager, $storage)
66
66
67
67
$ this ->assertInstanceOf (CsrfToken::class, $ token );
68
68
$ this ->assertSame ('token_id ' , $ token ->getId ());
69
- $ this ->assertSame ('TOKEN ' , $ token ->getValue ());
69
+ $ this ->assertNotSame ('TOKEN ' , $ token ->getValue ());
70
+ }
71
+
72
+ /**
73
+ * @dataProvider getManagerGeneratorAndStorage
74
+ */
75
+ public function testRandomizeTheToken ($ namespace , $ manager , $ storage )
76
+ {
77
+ $ storage ->expects ($ this ->any ())
78
+ ->method ('hasToken ' )
79
+ ->with ($ namespace .'token_id ' )
80
+ ->willReturn (true );
81
+
82
+ $ storage ->expects ($ this ->any ())
83
+ ->method ('getToken' )
84
+ ->with ($ namespace .'token_id ' )
85
+ ->willReturn ('TOKEN ' );
86
+
87
+ $ values = [];
88
+ $ lengths = [];
89
+ for ($ i = 0 ; $ i < 10 ; ++$ i ) {
90
+ $ token = $ manager ->getToken ('token_id ' );
91
+ $ values [] = $ token ->getValue ();
92
+ $ lengths [] = \strlen ($ token ->getValue ());
93
+ }
94
+
95
+ $ this ->assertCount (10 , array_unique ($ values ));
96
+ $ this ->assertGreaterThan (2 , \count (array_unique ($ lengths )));
70
97
}
71
98
72
99
/**
@@ -89,13 +116,33 @@ public function testRefreshTokenAlwaysReturnsNewToken($namespace, $manager, $sto
89
116
90
117
$ this ->assertInstanceOf (CsrfToken::class, $ token );
91
118
$ this ->assertSame ('token_id ' , $ token ->getId ());
92
- $ this ->assertSame ('TOKEN ' , $ token ->getValue ());
119
+ $ this ->assertNotSame ('TOKEN ' , $ token ->getValue ());
93
120
}
94
121
95
122
/**
96
123
* @dataProvider getManagerGeneratorAndStorage
97
124
*/
98
125
public function testMatchingTokenIsValid ($ namespace , $ manager , $ storage )
126
+ {
127
+ $ storage ->expects ($ this ->exactly (2 ))
128
+ ->method ('hasToken ' )
129
+ ->with ($ namespace .'token_id ' )
130
+ ->willReturn (true );
131
+
132
+ $ storage ->expects ($ this ->exactly (2 ))
133
+ ->method ('getToken ' )
134
+ ->with ($ namespace .'token_id ' )
135
+ ->willReturn ('TOKEN ' );
136
+
137
+ $ token = $ manager ->getToken ('token_id ' );
138
+ $ this ->assertNotSame ('TOKEN ' , $ token ->getValue ());
139
+ $ this ->assertTrue ($ manager ->isTokenValid ($ token ));
140
+ }
141
+
142
+ /**
143
+ * @dataProvider getManagerGeneratorAndStorage
144
+ */
145
+ public function testMatchingTokenIsValidWithLegacyToken ($ namespace , $ manager , $ storage )
99
146
{
100
147
$ storage ->expects ($ this ->once ())
101
148
->method ('hasToken ' )
@@ -170,7 +217,6 @@ public function testNamespaced()
170
217
171
218
$ token = $ manager ->getToken ('foo ' );
172
219
$ this ->assertSame ('foo ' , $ token ->getId ());
173
- $ this ->assertSame ('random ' , $ token ->getValue ());
174
220
}
175
221
176
222
public function getManagerGeneratorAndStorage ()
0 commit comments