def test_add_tou_action(self): self.actions.remove_action_by_id(self.test_action.action_id) from eduid_idp.tou_action import add_actions mock_ticket = make_login_ticket(req_class_ref=SWAMID_AL2, context=self.idp_app.context, key='mock-session') add_actions(self.idp_app.context, self.test_user, mock_ticket) self.assertEqual( len(self.actions.get_actions(self.test_user.eppn, 'mock-session')), 1)
def test_add_mfa_action_no_key_required_mfa(self): self.actions.remove_action_by_id(self.test_action.action_id) from eduid_idp.mfa_action import add_actions mock_ticket = make_login_ticket( req_class_ref=CONTEXTCLASSREFS['REFEDS_MFA'], context=self.idp_app.context, key='mock-session') add_actions(self.idp_app.context, self.test_user, mock_ticket) self.assertEqual( len(self.actions.get_actions(self.test_user.eppn, 'mock-session')), 1)
def test_add_tou_action_already_action_other_version(self): self.idp_app.context.actions_db.add_action( self.test_user.eppn, action_type='tou', preference=100, params={'version': 'mock-version-2'}) self.actions.remove_action_by_id(self.test_action.action_id) from eduid_idp.tou_action import add_actions mock_ticket = make_login_ticket(req_class_ref=SWAMID_AL2, context=self.idp_app.context, key='mock-session') add_actions(self.idp_app.context, self.test_user, mock_ticket) self.assertEqual( len(self.actions.get_actions(self.test_user.eppn, 'mock-session')), 2)
def test_add_tou_action_already_accepted_other_version(self): event_id = bson.ObjectId() self.test_user.tou.add( ToUEvent.from_dict( dict( version='mock-version-2', created_by='test_tou_plugin', created_ts=datetime.utcnow(), event_id=event_id, ))) self.actions.remove_action_by_id(self.test_action.action_id) from eduid_idp.tou_action import add_actions mock_ticket = make_login_ticket(req_class_ref=SWAMID_AL2, context=self.idp_app.context, key='mock-session') add_actions(self.idp_app.context, self.test_user, mock_ticket) self.assertEqual( len(self.actions.get_actions(self.test_user.eppn, 'mock-session')), 1)
def _test_add_2nd_mfa_action(self, success=True, authn_context=True, cred_key=None, actions=0): self.actions.remove_action_by_id(self.test_action.action_id) webauthn = Webauthn.from_dict( dict( keyhandle='test_key_handle', credential_data='test_credential_data', app_id='https://dev.eduid.se/u2f-app-id.json', attest_obj='test_attest_obj', description='test_description', )) self.test_user.credentials.add(webauthn) self.amdb.save(self.user, check_sync=False) cred = self.test_user.credentials.filter(Webauthn).to_list()[0] if cred_key is None: cred_key = cred.key completed_action = self.actions.add_action(self.test_user.eppn, action_type='mfa', preference=100, params={}, session='mock-session') completed_action.result = { 'cred_key': cred_key, 'issuer': 'dummy-issuer', 'success': success, 'authn_context': authn_context, } self.actions.update_action(completed_action) from eduid_idp.mfa_action import add_actions mock_ticket = make_login_ticket(req_class_ref=SWAMID_AL2, context=self.idp_app.context, key='mock-session') add_actions(self.idp_app.context, self.test_user, mock_ticket) self.assertEqual( len(self.actions.get_actions(self.test_user.eppn, 'mock-session')), actions) return mock_ticket
def test_add_mfa_action_new_key(self): self.actions.remove_action_by_id(self.test_action.action_id) webauthn = Webauthn.from_dict( dict( keyhandle='test_key_handle', credential_data='test_credential_data', app_id='https://dev.eduid.se/u2f-app-id.json', attest_obj='test_attest_obj', description='test_description', )) self.test_user.credentials.add(webauthn) self.amdb.save(self.user, check_sync=False) from eduid_idp.mfa_action import add_actions mock_ticket = make_login_ticket(req_class_ref=SWAMID_AL2, context=self.idp_app.context, key='mock-session') add_actions(self.idp_app.context, self.test_user, mock_ticket) self.assertEqual( len(self.actions.get_actions(self.test_user.eppn, 'mock-session')), 1)
def test_add_mfa_action_old_key(self): self.actions.remove_action_by_id(self.test_action.action_id) u2f = U2F.from_dict( dict( version='U2F_V2', app_id='https://dev.eduid.se/u2f-app-id.json', keyhandle='test_key_handle', public_key='test_public_key', attest_cert='test_attest_cert', description='test_description', )) self.test_user.credentials.add(u2f) self.amdb.save(self.user, check_sync=False) from eduid_idp.mfa_action import add_actions mock_ticket = make_login_ticket(req_class_ref=SWAMID_AL2, context=self.idp_app.context, key='mock-session') add_actions(self.idp_app.context, self.test_user, mock_ticket) self.assertEqual( len(self.actions.get_actions(self.test_user.eppn, 'mock-session')), 1)