Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
cbe98f3
Initial commit
abhidnya13 Feb 25, 2020
e64332f
Iteration 1
abhidnya13 Mar 5, 2020
2a7d5e3
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
abhidnya13 Mar 5, 2020
aed0e8d
Iteration 2 rectifying tests
abhidnya13 Mar 6, 2020
30f7d99
Iteration 3 modifying some more failing tests
abhidnya13 Mar 6, 2020
34e8e16
Iteration 4
abhidnya13 Mar 7, 2020
f60bbb5
Removing tests whose implementation was removed
abhidnya13 Mar 7, 2020
d54fb8b
Iteration 5
abhidnya13 Mar 7, 2020
be389d5
Replacing generic exception to specific Http error
abhidnya13 Mar 9, 2020
dcec4af
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
abhidnya13 Mar 16, 2020
e37f0c3
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
abhidnya13 Mar 16, 2020
b3a4e09
Refactor according to new interface
abhidnya13 Mar 20, 2020
96988f8
Changing one reference to new interface left in the previous one
abhidnya13 Mar 20, 2020
1d05615
Modified one more missed change
abhidnya13 Mar 20, 2020
ccafcf9
Few more changes and refactor
abhidnya13 Mar 20, 2020
2670e25
Adding raw response to response object
abhidnya13 Mar 20, 2020
cb70a37
Cleaning None values
abhidnya13 Mar 23, 2020
53520fd
PR review iteration
abhidnya13 Mar 26, 2020
293b081
Removing default http client
abhidnya13 Mar 30, 2020
fcac05e
cleaning up
abhidnya13 Mar 30, 2020
229ad26
Adding deleted single empty line back
abhidnya13 Mar 30, 2020
340210f
Updating filtering of non values from dictionary
abhidnya13 Mar 30, 2020
ca8a129
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
abhidnya13 Apr 7, 2020
d993950
Capturing editorial changes
abhidnya13 Apr 13, 2020
e5ebd28
Review changes 1
abhidnya13 Apr 16, 2020
8901269
Fixing broken test
abhidnya13 Apr 16, 2020
7774be8
Cleaning up
abhidnya13 Apr 16, 2020
42ca7a2
PR review changes part 1
abhidnya13 Apr 17, 2020
d38d38d
PR review changes part 2
abhidnya13 Apr 17, 2020
3226bc4
PR review changes part 3
abhidnya13 Apr 17, 2020
90afb94
Minor indent change
abhidnya13 Apr 17, 2020
a1ce0d1
PR review changes part 4
abhidnya13 Apr 20, 2020
ad245a7
Adding back accidentally deleted blank line
abhidnya13 Apr 20, 2020
34bb127
Removing extra indent
abhidnya13 Apr 20, 2020
a745949
Minor line add in authority.py
abhidnya13 Apr 20, 2020
b636baa
Making changes for backward compatibility
abhidnya13 Apr 20, 2020
d24d575
Some more editorial changes
abhidnya13 Apr 21, 2020
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
Prev Previous commit
Next Next commit
Adding raw response to response object
  • Loading branch information
abhidnya13 committed Mar 20, 2020
commit 2670e254511a58f6f6b104355a80a21672f4893c
14 changes: 8 additions & 6 deletions msal/oauth2cli/default_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,23 @@ def __init__(self, verify=True, proxies=None):
def post(self, url, params=None, data=None, headers=None, **kwargs):

response = self.session.post(url=url, params=params, headers=headers, data=data, **kwargs)
return Response(response)
return Response(response.status_code, response.text, response)

def get(self, url, params=None, headers=None, **kwargs):
response = self.session.get(url=url, params=params, headers=headers, **kwargs)
return Response(response)
return Response(response.status_code, response.text, response)


class Response(Response):

def __init__(self, response):
def __init__(self, status_code, text, response):
"""Constructor for DefaultResponseObject
response: Raw http response from requests
status, # type: int
text, # type: str response in string format
response, # type: Raw response from requests
"""
self.status_code = response.status_code
self.text = response.text
self.status_code = status_code
self.text = text
self.response = response

def raise_for_status(self):
Expand Down
14 changes: 7 additions & 7 deletions tests/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,29 @@ def test_cache_empty_will_be_returned_as_None(self):
def test_acquire_token_silent_will_suppress_error(self):
error_response = '{"error": "invalid_grant", "suberror": "xyz"}'
def tester(url, **kwargs):
return Response(400, error_response)
return Response(400, error_response, '')
self.assertEqual(None, self.app.acquire_token_silent(
self.scopes, self.account, post=tester))

def test_acquire_token_silent_with_error_will_return_error(self):
error_response = '{"error": "invalid_grant", "error_description": "xyz"}'
def tester(url, **kwargs):
return Response(400, error_response)
return Response(400, error_response, '')
self.assertEqual(json.loads(error_response), self.app.acquire_token_silent_with_error(
self.scopes, self.account, post=tester))

def test_atswe_will_map_some_suberror_to_classification_as_is(self):
error_response = '{"error": "invalid_grant", "suberror": "basic_action"}'
def tester(url, **kwargs):
return Response(400, error_response)
return Response(400, error_response, '')
result = self.app.acquire_token_silent_with_error(
self.scopes, self.account, post=tester)
self.assertEqual("basic_action", result.get("classification"))

def test_atswe_will_map_some_suberror_to_classification_to_empty_string(self):
error_response = '{"error": "invalid_grant", "suberror": "client_mismatch"}'
def tester(url, **kwargs):
return Response(400, error_response)
return Response(400, error_response, '')
result = self.app.acquire_token_silent_with_error(
self.scopes, self.account, post=tester)
self.assertEqual("", result.get("classification"))
Expand Down Expand Up @@ -133,7 +133,7 @@ def test_unknown_orphan_app_will_attempt_frt_and_not_remove_it(self):
error_response = '{"error": "invalid_grant","error_description": "Was issued to another client"}'
def tester(url, data=None, **kwargs):
self.assertEqual(self.frt, data.get("refresh_token"), "Should attempt the FRT")
return Response(400, error_response)
return Response(400, error_response, '')
app._acquire_token_silent_by_finding_rt_belongs_to_me_or_my_family(
self.authority, self.scopes, self.account, post=tester)
self.assertNotEqual([], app.token_cache.find(
Expand All @@ -154,7 +154,7 @@ def test_known_orphan_app_will_skip_frt_and_only_use_its_own_rt(self):
logger.debug("%s.cache = %s", self.id(), self.cache.serialize())
def tester(url, data=None, **kwargs):
self.assertEqual(rt, data.get("refresh_token"), "Should attempt the RT")
return Response(200, '{}')
return Response(200, '{}', '')
app._acquire_token_silent_by_finding_rt_belongs_to_me_or_my_family(
self.authority, self.scopes, self.account, post=tester)

Expand All @@ -164,7 +164,7 @@ def tester(url, data=None, **kwargs):
self.frt, data.get("refresh_token"), "Should attempt the FRT")
return Response(
200, json.dumps(TokenCacheTestCase.build_response(
uid=self.uid, utid=self.utid, foci="1", access_token="at")))
uid=self.uid, utid=self.utid, foci="1", access_token="at")), '')
app = ClientApplication(
"unknown_family_app", authority=self.authority_url, token_cache=self.cache)
at = app._acquire_token_silent_by_finding_rt_belongs_to_me_or_my_family(
Expand Down