Skip to content

Commit

Permalink
Add unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfdn committed Oct 4, 2023
1 parent 0f8af76 commit e57cab4
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/security/test_base_security_manager.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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()

0 comments on commit e57cab4

Please sign in to comment.