@@ -129,6 +129,7 @@ public function test_it_rejects_when_identity_has_vetted_token()
129
129
{
130
130
$ identity = new Identity ();
131
131
$ identity ->institution = new Institution ('Known institution ' );
132
+ $ identity ->possessedSelfAssertedToken = null ;
132
133
133
134
$ this ->identityService
134
135
->shouldReceive ('find ' )
@@ -155,10 +156,42 @@ public function test_it_rejects_when_identity_has_vetted_token()
155
156
$ this ->assertEquals ('Identity already has a vetted second factor ' , reset ($ messages ));
156
157
}
157
158
159
+ public function test_it_rejects_when_identity_had_prior_non_sat_token ()
160
+ {
161
+ $ identity = new Identity ();
162
+ $ identity ->institution = new Institution ('Known institution ' );
163
+ $ identity ->possessedSelfAssertedToken = false ;
164
+
165
+ $ this ->identityService
166
+ ->shouldReceive ('find ' )
167
+ ->once ()
168
+ ->andReturn ($ identity );
169
+
170
+ $ options = new InstitutionConfigurationOptions ();
171
+ $ options ->selfAssertedTokensOption = new SelfAssertedTokensOption (true );
172
+ $ this ->institutionConfigurationService
173
+ ->shouldReceive ('findInstitutionConfigurationOptionsFor ' )
174
+ ->once ()
175
+ ->andReturn ($ options );
176
+
177
+ $ identityId = new IdentityId ('known-user-id ' );
178
+ $ this ->secondFactorService
179
+ ->shouldReceive ('hasVettedByIdentity ' )
180
+ ->with ($ identityId )
181
+ ->andReturnFalse ();
182
+
183
+ $ decision = $ this ->service ->assertRegistrationOfSelfAssertedTokensIsAllowed ($ identityId );
184
+ $ messages = $ decision ->getErrorMessages ();
185
+
186
+ $ this ->assertEquals (403 , $ decision ->getCode ());
187
+ $ this ->assertEquals ('Identity never possessed a self-asserted token, but did/does possess one of the other types ' , reset ($ messages ));
188
+ }
189
+
158
190
public function test_it_allows_when_identity_meets_all_requirements ()
159
191
{
160
192
$ identity = new Identity ();
161
193
$ identity ->institution = new Institution ('Known institution ' );
194
+ $ identity ->possessedSelfAssertedToken = null ;
162
195
163
196
$ this ->identityService
164
197
->shouldReceive ('find ' )
@@ -185,5 +218,34 @@ public function test_it_allows_when_identity_meets_all_requirements()
185
218
$ this ->assertEmpty ($ messages );
186
219
}
187
220
221
+ public function test_it_allows_when_identity_with_prior_sat_meets_all_requirements ()
222
+ {
223
+ $ identity = new Identity ();
224
+ $ identity ->institution = new Institution ('Known institution ' );
225
+ $ identity ->possessedSelfAssertedToken = true ;
226
+
227
+ $ this ->identityService
228
+ ->shouldReceive ('find ' )
229
+ ->once ()
230
+ ->andReturn ($ identity );
188
231
232
+ $ options = new InstitutionConfigurationOptions ();
233
+ $ options ->selfAssertedTokensOption = new SelfAssertedTokensOption (true );
234
+ $ this ->institutionConfigurationService
235
+ ->shouldReceive ('findInstitutionConfigurationOptionsFor ' )
236
+ ->once ()
237
+ ->andReturn ($ options );
238
+
239
+ $ identityId = new IdentityId ('known-user-id ' );
240
+ $ this ->secondFactorService
241
+ ->shouldReceive ('hasVettedByIdentity ' )
242
+ ->with ($ identityId )
243
+ ->andReturnFalse ();
244
+
245
+ $ decision = $ this ->service ->assertRegistrationOfSelfAssertedTokensIsAllowed ($ identityId );
246
+ $ messages = $ decision ->getErrorMessages ();
247
+
248
+ $ this ->assertEquals (200 , $ decision ->getCode ());
249
+ $ this ->assertEmpty ($ messages );
250
+ }
189
251
}
0 commit comments