Skip to content

Commit 97e11b9

Browse files
committed
fix tests that didn't take high security authn in to account
1 parent 32d79b2 commit 97e11b9

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/eduid/webapp/security/tests/test_webauthn.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from werkzeug.http import dump_cookie
88

99
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
1111
from eduid.webapp.common.api.testing import EduidAPITestCase
1212
from eduid.webapp.common.session import EduidSession
1313
from eduid.webapp.common.session.namespaces import WebauthnRegistration, WebauthnState
@@ -96,6 +96,16 @@
9696
class SecurityWebauthnTests(EduidAPITestCase):
9797
app: SecurityApp
9898

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+
99109
def load_app(self, config: Mapping[str, Any]) -> SecurityApp:
100110
"""
101111
Called from the parent class, so we can provide the appropriate flask
@@ -198,9 +208,16 @@ def _begin_register_key(
198208
:param csrf: to control the CSRF token to send
199209
:param check_session: whether to check the registration state in the session
200210
"""
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+
201217
self.set_authn_action(
202218
eppn=self.test_user_eppn,
203219
frontend_action=FrontendAction.ADD_SECURITY_KEY_AUTHN,
220+
force_mfa=force_mfa,
204221
)
205222

206223
if existing_legacy_token:
@@ -250,9 +267,15 @@ def _finish_register_key(
250267
"""
251268
mock_request_user_sync.side_effect = self.request_user_sync
252269

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+
253275
self.set_authn_action(
254276
eppn=self.test_user_eppn,
255277
frontend_action=FrontendAction.ADD_SECURITY_KEY_AUTHN,
278+
force_mfa=force_mfa,
256279
)
257280

258281
if existing_legacy_token:
@@ -639,6 +662,6 @@ def test_approved_security_keys(self):
639662
assert "entries" in payload
640663
assert len(payload["entries"]) > 0
641664

642-
# test no dubles
665+
# test no doubles
643666
unique_lowecase_entries = list(set(e.lower() for e in payload["entries"]))
644667
assert len(unique_lowecase_entries) == len(payload["entries"])

0 commit comments

Comments
 (0)