From e57cab44b98d1093eabb4220a0b1d0d2234f5141 Mon Sep 17 00:00:00 2001 From: Daniel Wolf <95075445+wolfdn@users.noreply.github.com> Date: Wed, 4 Oct 2023 13:28:14 +0200 Subject: [PATCH] Add unittest --- tests/security/test_base_security_manager.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/security/test_base_security_manager.py b/tests/security/test_base_security_manager.py index 736b0b88d6..9a5cd6cc0e 100644 --- a/tests/security/test_base_security_manager.py +++ b/tests/security/test_base_security_manager.py @@ -1,8 +1,10 @@ import datetime +import json import unittest from unittest.mock import MagicMock, patch from flask_appbuilder.security.manager import BaseSecurityManager +from flask_appbuilder.security.manager import JsonWebKey, jwt @patch.object(BaseSecurityManager, "update_user") @@ -67,3 +69,15 @@ def test_subsequent_unsuccessful_auth(self, mock1, mock2): self.assertEqual(user_mock.fail_login_count, 10) self.assertEqual(user_mock.last_login, None) self.assertTrue(bsm.update_user.called_once) + + def test_azure_jwt_validated(self, mock1, mock2): + example_jwt="ExampleAzureJWT" + + JsonWebKey.import_key_set = MagicMock() + JWTClaimsMock = MagicMock() + jwt.decode = MagicMock(return_value=JWTClaimsMock) + json.dumps = MagicMock(return_value=f"Decoded{example_jwt}") + + bsm = BaseSecurityManager() + bsm._decode_and_validate_azure_jwt(example_jwt) + JWTClaimsMock.validate.assert_called()