|
7 | 7 | from werkzeug.http import dump_cookie
|
8 | 8 |
|
9 | 9 | from eduid.common.config.base import EduidEnvironment, FrontendAction
|
10 |
| -from eduid.userdb.credentials import U2F, Webauthn |
| 10 | +from eduid.userdb.credentials import U2F, FidoCredential, Webauthn |
11 | 11 | from eduid.webapp.common.api.testing import EduidAPITestCase
|
12 | 12 | from eduid.webapp.common.session import EduidSession
|
13 | 13 | from eduid.webapp.common.session.namespaces import WebauthnRegistration, WebauthnState
|
|
96 | 96 | class SecurityWebauthnTests(EduidAPITestCase):
|
97 | 97 | app: SecurityApp
|
98 | 98 |
|
| 99 | + def setUp(self): |
| 100 | + super().setUp() |
| 101 | + # remove all FidoCredentials from the test user |
| 102 | + user = self.app.central_userdb.get_user_by_eppn(self.test_user_eppn) |
| 103 | + assert user is not None |
| 104 | + for credential in user.credentials: |
| 105 | + if isinstance(credential, FidoCredential): |
| 106 | + user.credentials.remove(credential.key) |
| 107 | + self.app.central_userdb.save(user) |
| 108 | + |
99 | 109 | def load_app(self, config: Mapping[str, Any]) -> SecurityApp:
|
100 | 110 | """
|
101 | 111 | Called from the parent class, so we can provide the appropriate flask
|
@@ -198,9 +208,16 @@ def _begin_register_key(
|
198 | 208 | :param csrf: to control the CSRF token to send
|
199 | 209 | :param check_session: whether to check the registration state in the session
|
200 | 210 | """
|
| 211 | + |
| 212 | + force_mfa = False |
| 213 | + if other is not None or existing_legacy_token: |
| 214 | + # Fake that user used the other security key to authenticate |
| 215 | + force_mfa = True |
| 216 | + |
201 | 217 | self.set_authn_action(
|
202 | 218 | eppn=self.test_user_eppn,
|
203 | 219 | frontend_action=FrontendAction.ADD_SECURITY_KEY_AUTHN,
|
| 220 | + force_mfa=force_mfa, |
204 | 221 | )
|
205 | 222 |
|
206 | 223 | if existing_legacy_token:
|
@@ -250,9 +267,15 @@ def _finish_register_key(
|
250 | 267 | """
|
251 | 268 | mock_request_user_sync.side_effect = self.request_user_sync
|
252 | 269 |
|
| 270 | + force_mfa = False |
| 271 | + if existing_legacy_token: |
| 272 | + # Fake that user used the other security key to authenticate |
| 273 | + force_mfa = True |
| 274 | + |
253 | 275 | self.set_authn_action(
|
254 | 276 | eppn=self.test_user_eppn,
|
255 | 277 | frontend_action=FrontendAction.ADD_SECURITY_KEY_AUTHN,
|
| 278 | + force_mfa=force_mfa, |
256 | 279 | )
|
257 | 280 |
|
258 | 281 | if existing_legacy_token:
|
@@ -639,6 +662,6 @@ def test_approved_security_keys(self):
|
639 | 662 | assert "entries" in payload
|
640 | 663 | assert len(payload["entries"]) > 0
|
641 | 664 |
|
642 |
| - # test no dubles |
| 665 | + # test no doubles |
643 | 666 | unique_lowecase_entries = list(set(e.lower() for e in payload["entries"]))
|
644 | 667 | assert len(unique_lowecase_entries) == len(payload["entries"])
|
0 commit comments