@@ -24,16 +24,16 @@ final class Argon2SplitTokenTest extends TestCase
24
24
private const FULL_TOKEN = '1zUeXUvr4LKymANBB_bLEqiP5GPr-Pha_OR6OOnV1o8Vy_rWhDoxKNIt ' ;
25
25
private const SELECTOR = '1zUeXUvr4LKymANBB_bLEqiP5GPr-Pha ' ;
26
26
27
- private static $ randValue ;
27
+ private static HiddenString $ randValue ;
28
28
29
29
#[BeforeClass]
30
- public static function createRandomBytes ()
30
+ public static function createRandomBytes (): void
31
31
{
32
- self ::$ randValue = new HiddenString (hex2bin ('d7351e5d4bebe0b2b298034107f6cb12a88fe463ebf8f85afce47a38e9d5d68f15cbfad6843a3128d22d ' ), false , true );
32
+ self ::$ randValue = new HiddenString (( string ) hex2bin ('d7351e5d4bebe0b2b298034107f6cb12a88fe463ebf8f85afce47a38e9d5d68f15cbfad6843a3128d22d ' ), false , true );
33
33
}
34
34
35
35
#[Test]
36
- public function it_validates_the_correct_length_less ()
36
+ public function it_validates_the_correct_length_less (): void
37
37
{
38
38
$ this ->expectException (\RuntimeException::class);
39
39
$ this ->expectExceptionMessage ('Invalid token-data provided, expected exactly 42 bytes. ' );
@@ -42,7 +42,7 @@ public function it_validates_the_correct_length_less()
42
42
}
43
43
44
44
#[Test]
45
- public function it_validates_the_correct_length_more ()
45
+ public function it_validates_the_correct_length_more (): void
46
46
{
47
47
$ this ->expectException (\RuntimeException::class);
48
48
$ this ->expectExceptionMessage ('Invalid token-data provided, expected exactly 42 bytes. ' );
@@ -51,7 +51,7 @@ public function it_validates_the_correct_length_more()
51
51
}
52
52
53
53
#[Test]
54
- public function it_validates_the_correct_length_from_string_less ()
54
+ public function it_validates_the_correct_length_from_string_less (): void
55
55
{
56
56
$ this ->expectException (\RuntimeException::class);
57
57
$ this ->expectExceptionMessage ('Invalid token provided. ' );
@@ -60,7 +60,7 @@ public function it_validates_the_correct_length_from_string_less()
60
60
}
61
61
62
62
#[Test]
63
- public function it_validates_the_correct_length_from_string_more ()
63
+ public function it_validates_the_correct_length_from_string_more (): void
64
64
{
65
65
$ this ->expectException (\RuntimeException::class);
66
66
$ this ->expectExceptionMessage ('Invalid token provided. ' );
@@ -69,7 +69,7 @@ public function it_validates_the_correct_length_from_string_more()
69
69
}
70
70
71
71
#[Test]
72
- public function it_creates_a_split_token_without_id ()
72
+ public function it_creates_a_split_token_without_id (): void
73
73
{
74
74
$ splitToken = SplitToken::create (self ::$ randValue );
75
75
@@ -78,7 +78,7 @@ public function it_creates_a_split_token_without_id()
78
78
}
79
79
80
80
#[Test]
81
- public function it_creates_a_split_token_with_id ()
81
+ public function it_creates_a_split_token_with_id (): void
82
82
{
83
83
$ splitToken = SplitToken::create ($ fullToken = self ::$ randValue );
84
84
@@ -87,7 +87,7 @@ public function it_creates_a_split_token_with_id()
87
87
}
88
88
89
89
#[Test]
90
- public function it_compares_two_split_tokens ()
90
+ public function it_compares_two_split_tokens (): void
91
91
{
92
92
$ splitToken1 = SplitToken::create (self ::$ randValue );
93
93
@@ -97,43 +97,46 @@ public function it_compares_two_split_tokens()
97
97
}
98
98
99
99
#[Test]
100
- public function it_creates_a_split_token_with_custom_config ()
100
+ public function it_creates_a_split_token_with_custom_config (): void
101
101
{
102
102
$ splitToken = SplitToken::create (self ::$ randValue , [
103
103
'memory_cost ' => 512 ,
104
104
'time_cost ' => 1 ,
105
105
'threads ' => 1 ,
106
106
]);
107
107
108
- self ::assertMatchesRegularExpression ('/^\$argon2[id]+\$v=19\$m=512,t=1,p=1/ ' , $ splitToken ->toValueHolder ()->verifierHash ());
108
+ self ::assertNotNull ($ hash = $ splitToken ->toValueHolder ()->verifierHash ());
109
+ self ::assertMatchesRegularExpression ('/^\$argon2id+\$v=19\$m=512,t=1,p=1/ ' , $ hash );
109
110
}
110
111
111
112
#[Test]
112
- public function it_produces_a_split_token_value_holder ()
113
+ public function it_produces_a_split_token_value_holder (): void
113
114
{
114
115
$ splitToken = SplitToken::create (self ::$ randValue );
115
116
116
117
$ value = $ splitToken ->toValueHolder ();
117
118
118
119
self ::assertEquals ($ splitToken ->selector (), $ value ->selector ());
119
- self ::assertStringStartsWith ('$argon2i ' , $ value ->verifierHash ());
120
+ self ::assertNotNull ($ hash = $ splitToken ->toValueHolder ()->verifierHash ());
121
+ self ::assertStringStartsWith ('$argon2id ' , $ hash );
120
122
self ::assertEquals ([], $ value ->metadata ());
121
123
self ::assertFalse ($ value ->isExpired ());
122
124
self ::assertFalse ($ value ->isExpired (new \DateTimeImmutable ('-5 minutes ' )));
123
125
}
124
126
125
127
#[Test]
126
- public function it_produces_a_split_token_value_holder_with_metadata ()
128
+ public function it_produces_a_split_token_value_holder_with_metadata (): void
127
129
{
128
130
$ splitToken = SplitToken::create (self ::$ randValue );
129
131
$ value = $ splitToken ->toValueHolder (['he ' => 'now ' ]);
130
132
131
- self ::assertStringStartsWith ('$argon2i ' , $ value ->verifierHash ());
133
+ self ::assertNotNull ($ hash = $ splitToken ->toValueHolder ()->verifierHash ());
134
+ self ::assertStringStartsWith ('$argon2id ' , $ hash );
132
135
self ::assertEquals (['he ' => 'now ' ], $ value ->metadata ());
133
136
}
134
137
135
138
#[Test]
136
- public function it_produces_a_split_token_value_holder_with_expiration ()
139
+ public function it_produces_a_split_token_value_holder_with_expiration (): void
137
140
{
138
141
$ date = new \DateTimeImmutable ('+5 minutes ' );
139
142
$ splitToken = SplitToken::create ($ fullToken = self ::$ randValue )->expireAt ($ date );
@@ -146,7 +149,7 @@ public function it_produces_a_split_token_value_holder_with_expiration()
146
149
}
147
150
148
151
#[Test]
149
- public function it_reconstructs_from_string ()
152
+ public function it_reconstructs_from_string (): void
150
153
{
151
154
$ splitTokenReconstituted = SplitToken::fromString (self ::FULL_TOKEN );
152
155
@@ -155,7 +158,7 @@ public function it_reconstructs_from_string()
155
158
}
156
159
157
160
#[Test]
158
- public function it_fails_when_creating_holder_with_string_constructed ()
161
+ public function it_fails_when_creating_holder_with_string_constructed (): void
159
162
{
160
163
$ this ->expectException (\RuntimeException::class);
161
164
$ this ->expectExceptionMessage ('toValueHolder() does not work with a SplitToken object when created with fromString(). ' );
@@ -164,7 +167,7 @@ public function it_fails_when_creating_holder_with_string_constructed()
164
167
}
165
168
166
169
#[Test]
167
- public function it_verifies_split_token ()
170
+ public function it_verifies_split_token (): void
168
171
{
169
172
// Stored.
170
173
$ splitTokenHolder = SplitToken::create (self ::$ randValue )->toValueHolder ();
@@ -176,15 +179,15 @@ public function it_verifies_split_token()
176
179
}
177
180
178
181
#[Test]
179
- public function it_verifies_split_token_from_string_and_no_current_token_set ()
182
+ public function it_verifies_split_token_from_string_and_no_current_token_set (): void
180
183
{
181
184
$ fromString = SplitToken::fromString (self ::FULL_TOKEN );
182
185
183
186
self ::assertFalse ($ fromString ->matches (null ));
184
187
}
185
188
186
189
#[Test]
187
- public function it_verifies_split_token_from_string_selector ()
190
+ public function it_verifies_split_token_from_string_selector (): void
188
191
{
189
192
// Stored.
190
193
$ splitTokenHolder = SplitToken::create (self ::$ randValue )->toValueHolder ();
@@ -197,7 +200,7 @@ public function it_verifies_split_token_from_string_selector()
197
200
}
198
201
199
202
#[Test]
200
- public function it_verifies_split_token_from_string_with_expiration ()
203
+ public function it_verifies_split_token_from_string_with_expiration (): void
201
204
{
202
205
// Stored.
203
206
$ splitTokenHolder = SplitToken::create (self ::$ randValue )
0 commit comments