Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Adding ADAL wrapper to msrestazure #8

Merged
merged 9 commits into from
Nov 30, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
msrest>=0.4.4,<0.5.0
adal~=0.4.0
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,7 @@
'License :: OSI Approved :: MIT License',
'Topic :: Software Development'],
install_requires=[
"msrest>=0.4.4"],
"msrest~=0.4.4",
"adal~=0.4.0"
],
)
33 changes: 32 additions & 1 deletion test/unittest_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,22 @@

from requests_oauthlib import OAuth2Session
import oauthlib
import adal

from msrestazure import AzureConfiguration
from msrestazure import azure_active_directory
from msrestazure.azure_active_directory import (
AADMixin,
InteractiveCredentials,
ServicePrincipalCredentials,
UserPassCredentials
UserPassCredentials,
AdalAuthentication
)
from msrest.exceptions import (
TokenExpiredError,
AuthenticationError,
)
from requests import ConnectionError


class TestInteractiveCredentials(unittest.TestCase):
Expand Down Expand Up @@ -356,6 +359,34 @@ def test_user_pass_credentials(self):
client_id="client_id", username='my_username',
password='my_password', resource='https://management.core.chinacloudapi.cn/', verify=False)

def test_adal_authentication(self):
def success_auth():
return {
'tokenType': 'https',
'accessToken': 'cryptictoken'
}

credentials = AdalAuthentication(success_auth)
session = credentials.signed_session()
self.assertEquals(session.headers['Authorization'], 'https cryptictoken')

def error():
raise adal.AdalError("You hacker", {})
credentials = AdalAuthentication(error)
with self.assertRaises(AuthenticationError) as cm:
session = credentials.signed_session()

def expired():
raise adal.AdalError("Too late", {'error_description': "AADSTS70008: Expired"})
credentials = AdalAuthentication(expired)
with self.assertRaises(TokenExpiredError) as cm:
session = credentials.signed_session()

def connection_error():
raise ConnectionError("Plug the network")
credentials = AdalAuthentication(connection_error)
with self.assertRaises(AuthenticationError) as cm:
session = credentials.signed_session()

if __name__ == '__main__':
unittest.main()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a newline at the end of the file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done this one