Ejemplo n.º 1
0
    def test_clear_token(self, mock_keyring):

        mix = AADMixin()
        mix.cred_store = "store_name"
        mix.store_key = "client_id"
        mix.clear_cached_token()

        mock_keyring.delete_password.assert_called_with(
            "store_name", "client_id")
Ejemplo n.º 2
0
    def test_clear_token(self, mock_keyring):

        mix = AADMixin()
        mix.cred_store = "store_name"
        mix.store_key = "client_id"
        mix.clear_cached_token()

        mock_keyring.delete_password.assert_called_with(
            "store_name", "client_id")
Ejemplo n.º 3
0
    def test_store_token(self, mock_keyring):

        mix = AADMixin()
        mix.cred_store = "store_name"
        mix.store_key = "client_id"
        mix._default_token_cache({'token_type':'1', 'access_token':'2'})

        mock_keyring.set_password.assert_called_with(
            "store_name", "client_id",
            str({'token_type':'1', 'access_token':'2'}))
Ejemplo n.º 4
0
    def test_store_token(self, mock_keyring):

        mix = AADMixin()
        mix.cred_store = "store_name"
        mix.store_key = "client_id"
        mix._default_token_cache({'token_type':'1', 'access_token':'2'})

        mock_keyring.set_password.assert_called_with(
            "store_name", "client_id",
            str({'token_type':'1', 'access_token':'2'}))
Ejemplo n.º 5
0
    def test_store_token_boom(self, mock_keyring):

        mock_keyring.side_effect = Exception('Boom!')

        mix = AADMixin(None, None)
        mix.cred_store = "store_name"
        mix.store_key = "client_id"
        with self.assertLogs('msrestazure.azure_active_directory',
                             level="WARNING"):
            mix._default_token_cache({'token_type': '1', 'access_token': '2'})
Ejemplo n.º 6
0
    def test_store_token_boom(self, mock_keyring):

        def boom(*args, **kwargs):
            raise Exception("Boom!")
        mock_keyring.set_password = boom

        mix = AADMixin(None, None)
        mix.cred_store = "store_name"
        mix.store_key = "client_id"
        with self.assertLogs('msrestazure.azure_active_directory', level="WARNING"):
            mix._default_token_cache({'token_type':'1', 'access_token':'2'})
Ejemplo n.º 7
0
    def test_credentials_get_stored_auth(self, mock_keyring):

        mix = AADMixin()
        mix.cred_store = "store_name"
        mix.store_key = "client_id"
        mix.signed_session = mock.Mock()

        mock_keyring.get_password.return_value = None

        with self.assertRaises(ValueError):
            mix._retrieve_stored_token()

        mock_keyring.get_password.assert_called_with(
            "store_name", "client_id")

        mock_keyring.get_password.return_value = str(
            {'token_type':'1', 'access_token':'2'})

        mix._retrieve_stored_token()
        mock_keyring.get_password.assert_called_with("store_name", "client_id")
Ejemplo n.º 8
0
    def test_credentials_get_stored_auth(self, mock_keyring):

        mix = AADMixin()
        mix.cred_store = "store_name"
        mix.store_key = "client_id"
        mix.signed_session = mock.Mock()

        mock_keyring.get_password.return_value = None

        with self.assertRaises(ValueError):
            mix._retrieve_stored_token()

        mock_keyring.get_password.assert_called_with(
            "store_name", "client_id")

        mock_keyring.get_password.return_value = str(
            {'token_type':'1', 'access_token':'2'})

        mix._retrieve_stored_token()
        mock_keyring.get_password.assert_called_with("store_name", "client_id")