31
31
WebAuthnDevice ,
32
32
WebAuthnDeviceType ,
33
33
)
34
- from authentik .stages .authenticator_webauthn .stage import SESSION_KEY_WEBAUTHN_CHALLENGE
34
+ from authentik .stages .authenticator_webauthn .stage import PLAN_CONTEXT_WEBAUTHN_CHALLENGE
35
35
from authentik .stages .authenticator_webauthn .tasks import webauthn_mds_import
36
36
from authentik .stages .identification .models import IdentificationStage , UserFields
37
37
from authentik .stages .user_login .models import UserLoginStage
@@ -103,7 +103,11 @@ def test_device_challenge_webauthn(self):
103
103
device_classes = [DeviceClasses .WEBAUTHN ],
104
104
webauthn_user_verification = UserVerification .PREFERRED ,
105
105
)
106
- challenge = get_challenge_for_device (request , stage , webauthn_device )
106
+ plan = FlowPlan ("" )
107
+ stage_view = AuthenticatorValidateStageView (
108
+ FlowExecutorView (flow = None , current_stage = stage , plan = plan ), request = request
109
+ )
110
+ challenge = get_challenge_for_device (stage_view , stage , webauthn_device )
107
111
del challenge ["challenge" ]
108
112
self .assertEqual (
109
113
challenge ,
@@ -122,7 +126,9 @@ def test_device_challenge_webauthn(self):
122
126
123
127
with self .assertRaises (ValidationError ):
124
128
validate_challenge_webauthn (
125
- {}, StageView (FlowExecutorView (current_stage = stage ), request = request ), self .user
129
+ {},
130
+ StageView (FlowExecutorView (current_stage = stage , plan = plan ), request = request ),
131
+ self .user ,
126
132
)
127
133
128
134
def test_device_challenge_webauthn_restricted (self ):
@@ -193,22 +199,35 @@ def test_raw_get_challenge(self):
193
199
sign_count = 0 ,
194
200
rp_id = generate_id (),
195
201
)
196
- challenge = get_challenge_for_device (request , stage , webauthn_device )
197
- webauthn_challenge = request .session [SESSION_KEY_WEBAUTHN_CHALLENGE ]
202
+ plan = FlowPlan ("" )
203
+ plan .context [PLAN_CONTEXT_WEBAUTHN_CHALLENGE ] = base64url_to_bytes (
204
+ "g98I51mQvZXo5lxLfhrD2zfolhZbLRyCgqkkYap1jwSaJ13BguoJWCF9_Lg3AgO4Wh-Bqa556JE20oKsYbl6RA"
205
+ )
206
+ stage_view = AuthenticatorValidateStageView (
207
+ FlowExecutorView (flow = None , current_stage = stage , plan = plan ), request = request
208
+ )
209
+ challenge = get_challenge_for_device (stage_view , stage , webauthn_device )
198
210
self .assertEqual (
199
- challenge ,
200
- {
201
- "allowCredentials" : [
202
- {
203
- "id" : "QKZ97ASJAOIDyipAs6mKUxDUZgDrWrbAsUb5leL7-oU" ,
204
- "type" : "public-key" ,
205
- }
206
- ],
207
- "challenge" : bytes_to_base64url (webauthn_challenge ),
208
- "rpId" : "testserver" ,
209
- "timeout" : 60000 ,
210
- "userVerification" : "preferred" ,
211
- },
211
+ challenge ["allowCredentials" ],
212
+ [
213
+ {
214
+ "id" : "QKZ97ASJAOIDyipAs6mKUxDUZgDrWrbAsUb5leL7-oU" ,
215
+ "type" : "public-key" ,
216
+ }
217
+ ],
218
+ )
219
+ self .assertIsNotNone (challenge ["challenge" ])
220
+ self .assertEqual (
221
+ challenge ["rpId" ],
222
+ "testserver" ,
223
+ )
224
+ self .assertEqual (
225
+ challenge ["timeout" ],
226
+ 60000 ,
227
+ )
228
+ self .assertEqual (
229
+ challenge ["userVerification" ],
230
+ "preferred" ,
212
231
)
213
232
214
233
def test_get_challenge_userless (self ):
@@ -228,18 +247,16 @@ def test_get_challenge_userless(self):
228
247
sign_count = 0 ,
229
248
rp_id = generate_id (),
230
249
)
231
- challenge = get_webauthn_challenge_without_user (request , stage )
232
- webauthn_challenge = request .session [SESSION_KEY_WEBAUTHN_CHALLENGE ]
233
- self .assertEqual (
234
- challenge ,
235
- {
236
- "allowCredentials" : [],
237
- "challenge" : bytes_to_base64url (webauthn_challenge ),
238
- "rpId" : "testserver" ,
239
- "timeout" : 60000 ,
240
- "userVerification" : "preferred" ,
241
- },
242
- )
250
+ plan = FlowPlan ("" )
251
+ stage_view = AuthenticatorValidateStageView (
252
+ FlowExecutorView (flow = None , current_stage = stage , plan = plan ), request = request
253
+ )
254
+ challenge = get_webauthn_challenge_without_user (stage_view , stage )
255
+ self .assertEqual (challenge ["allowCredentials" ], [])
256
+ self .assertIsNotNone (challenge ["challenge" ])
257
+ self .assertEqual (challenge ["rpId" ], "testserver" )
258
+ self .assertEqual (challenge ["timeout" ], 60000 )
259
+ self .assertEqual (challenge ["userVerification" ], "preferred" )
243
260
244
261
def test_validate_challenge_unrestricted (self ):
245
262
"""Test webauthn authentication (unrestricted webauthn device)"""
@@ -275,10 +292,10 @@ def test_validate_challenge_unrestricted(self):
275
292
"last_used" : None ,
276
293
}
277
294
]
278
- session [SESSION_KEY_PLAN ] = plan
279
- session [SESSION_KEY_WEBAUTHN_CHALLENGE ] = base64url_to_bytes (
295
+ plan .context [PLAN_CONTEXT_WEBAUTHN_CHALLENGE ] = base64url_to_bytes (
280
296
"aCC6ak_DP45xMH1qyxzUM5iC2xc4QthQb09v7m4qDBmY8FvWvhxFzSuFlDYQmclrh5fWS5q0TPxgJGF4vimcFQ"
281
297
)
298
+ session [SESSION_KEY_PLAN ] = plan
282
299
session .save ()
283
300
284
301
response = self .client .post (
@@ -352,10 +369,10 @@ def test_validate_challenge_restricted(self):
352
369
"last_used" : None ,
353
370
}
354
371
]
355
- session [SESSION_KEY_PLAN ] = plan
356
- session [SESSION_KEY_WEBAUTHN_CHALLENGE ] = base64url_to_bytes (
372
+ plan .context [PLAN_CONTEXT_WEBAUTHN_CHALLENGE ] = base64url_to_bytes (
357
373
"aCC6ak_DP45xMH1qyxzUM5iC2xc4QthQb09v7m4qDBmY8FvWvhxFzSuFlDYQmclrh5fWS5q0TPxgJGF4vimcFQ"
358
374
)
375
+ session [SESSION_KEY_PLAN ] = plan
359
376
session .save ()
360
377
361
378
response = self .client .post (
@@ -433,10 +450,10 @@ def test_validate_challenge_userless(self):
433
450
"last_used" : None ,
434
451
}
435
452
]
436
- session [SESSION_KEY_PLAN ] = plan
437
- session [SESSION_KEY_WEBAUTHN_CHALLENGE ] = base64url_to_bytes (
453
+ plan .context [PLAN_CONTEXT_WEBAUTHN_CHALLENGE ] = base64url_to_bytes (
438
454
"g98I51mQvZXo5lxLfhrD2zfolhZbLRyCgqkkYap1jwSaJ13BguoJWCF9_Lg3AgO4Wh-Bqa556JE20oKsYbl6RA"
439
455
)
456
+ session [SESSION_KEY_PLAN ] = plan
440
457
session .save ()
441
458
442
459
response = self .client .post (
@@ -496,17 +513,14 @@ def test_validate_challenge_invalid(self):
496
513
not_configured_action = NotConfiguredAction .CONFIGURE ,
497
514
device_classes = [DeviceClasses .WEBAUTHN ],
498
515
)
499
- stage_view = AuthenticatorValidateStageView (
500
- FlowExecutorView (flow = flow , current_stage = stage ), request = request
501
- )
502
- request = get_request ("/" )
503
- request .session [SESSION_KEY_WEBAUTHN_CHALLENGE ] = base64url_to_bytes (
516
+ plan = FlowPlan (flow .pk .hex )
517
+ plan .context [PLAN_CONTEXT_WEBAUTHN_CHALLENGE ] = base64url_to_bytes (
504
518
"g98I51mQvZXo5lxLfhrD2zfolhZbLRyCgqkkYap1jwSaJ13BguoJWCF9_Lg3AgO4Wh-Bqa556JE20oKsYbl6RA"
505
519
)
506
- request . session . save ( )
520
+ request = get_request ( "/" )
507
521
508
522
stage_view = AuthenticatorValidateStageView (
509
- FlowExecutorView (flow = flow , current_stage = stage ), request = request
523
+ FlowExecutorView (flow = flow , current_stage = stage , plan = plan ), request = request
510
524
)
511
525
request .META ["SERVER_NAME" ] = "localhost"
512
526
request .META ["SERVER_PORT" ] = "9000"
0 commit comments