def test_07_login_mode(self): # a realm: cornelius@r1: PW: test def check_webui_user_userstore(user_obj, password, options=None, superuser_realms=None, check_otp=False): self.assertEqual(check_otp, False) def check_webui_user_privacyidea(user_obj, password, options=None, superuser_realms=None, check_otp=False): self.assertEqual(check_otp, True) user_obj = User("cornelius", "r1") g = FakeFlaskG() P = PolicyClass() g.policy_object = P options = {"g": g} # No policy, the function is called with check_otp=False login_mode(check_webui_user_userstore, user_obj, "", options=options, superuser_realms="", check_otp=False) set_policy(name="pol2", scope=SCOPE.WEBUI, action="%s=%s" % (ACTION.LOGINMODE, LOGINMODE.PRIVACYIDEA)) g = FakeFlaskG() P = PolicyClass() g.policy_object = P options = {"g": g} # Policy is set, the function is called with check_otp=True login_mode(check_webui_user_privacyidea, user_obj, "", options=options, superuser_realms="", check_otp=False)
def test_07_login_mode(self): # a realm: cornelius@r1: PW: test def check_webui_user_userstore(user_obj, password, options=None, superuser_realms=None, check_otp=False): self.assertEqual(check_otp, False) def check_webui_user_privacyidea(user_obj, password, options=None, superuser_realms=None, check_otp=False): self.assertEqual(check_otp, True) user_obj = User("cornelius", "r1") g = FakeFlaskG() P = PolicyClass() g.policy_object = P g.audit_object = FakeAudit() options = {"g": g} # No policy, the function is called with check_otp=False login_mode(check_webui_user_userstore, user_obj, "", options=options, superuser_realms="", check_otp=False) set_policy(name="pol2", scope=SCOPE.WEBUI, action="{0!s}={1!s}".format(ACTION.LOGINMODE, LOGINMODE.PRIVACYIDEA)) g = FakeFlaskG() P = PolicyClass() g.policy_object = P g.audit_object = FakeAudit() options = {"g": g} # Policy is set, the function is called with check_otp=True login_mode(check_webui_user_privacyidea, user_obj, "", options=options, superuser_realms="", check_otp=False) # Set policy, so that the user is not allowed to login at all set_policy(name="pol2", scope=SCOPE.WEBUI, action="{0!s}={1!s}".format(ACTION.LOGINMODE, LOGINMODE.DISABLE)) g = FakeFlaskG() P = PolicyClass() g.policy_object = P g.audit_object = FakeAudit() options = {"g": g} # Policy is set. Trying to login raises a policy error self.assertRaises(PolicyError, login_mode, check_webui_user_privacyidea, user_obj, "", options=options, superuser_realms="", check_otp=False) delete_policy("pol2")
def test_07_login_mode(self): # a realm: cornelius@r1: PW: test def check_webui_user_userstore(user_obj, password, options=None, superuser_realms=None, check_otp=False): self.assertEqual(check_otp, False) def check_webui_user_privacyidea(user_obj, password, options=None, superuser_realms=None, check_otp=False): self.assertEqual(check_otp, True) user_obj = User("cornelius", "r1") g = FakeFlaskG() P = PolicyClass() g.policy_object = P g.audit_object = FakeAudit() options = {"g": g} # No policy, the function is called with check_otp=False login_mode(check_webui_user_userstore, user_obj, "", options=options, superuser_realms="", check_otp=False) set_policy(name="pol2", scope=SCOPE.WEBUI, action="{0!s}={1!s}".format(ACTION.LOGINMODE, LOGINMODE.PRIVACYIDEA)) g = FakeFlaskG() P = PolicyClass() g.policy_object = P g.audit_object = FakeAudit() options = {"g": g} # Policy is set, the function is called with check_otp=True login_mode(check_webui_user_privacyidea, user_obj, "", options=options, superuser_realms="", check_otp=False) # Set policy, so that the user is not allowed to login at all set_policy(name="pol2", scope=SCOPE.WEBUI, action="{0!s}={1!s}".format(ACTION.LOGINMODE, LOGINMODE.DISABLE)) g = FakeFlaskG() P = PolicyClass() g.policy_object = P g.audit_object = FakeAudit() options = {"g": g} # Policy is set. Trying to login raises a policy error self.assertRaises(PolicyError, login_mode, check_webui_user_privacyidea, user_obj, "", options=options, superuser_realms="", check_otp=False) delete_policy("pol2")