-
Notifications
You must be signed in to change notification settings - Fork 207
Allowing transport layer to be customized #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
cbe98f3
Initial commit
abhidnya13 e64332f
Iteration 1
abhidnya13 2a7d5e3
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
abhidnya13 aed0e8d
Iteration 2 rectifying tests
abhidnya13 30f7d99
Iteration 3 modifying some more failing tests
abhidnya13 34e8e16
Iteration 4
abhidnya13 f60bbb5
Removing tests whose implementation was removed
abhidnya13 d54fb8b
Iteration 5
abhidnya13 be389d5
Replacing generic exception to specific Http error
abhidnya13 dcec4af
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
abhidnya13 e37f0c3
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
abhidnya13 b3a4e09
Refactor according to new interface
abhidnya13 96988f8
Changing one reference to new interface left in the previous one
abhidnya13 1d05615
Modified one more missed change
abhidnya13 ccafcf9
Few more changes and refactor
abhidnya13 2670e25
Adding raw response to response object
abhidnya13 cb70a37
Cleaning None values
abhidnya13 53520fd
PR review iteration
abhidnya13 293b081
Removing default http client
abhidnya13 fcac05e
cleaning up
abhidnya13 229ad26
Adding deleted single empty line back
abhidnya13 340210f
Updating filtering of non values from dictionary
abhidnya13 ca8a129
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
abhidnya13 d993950
Capturing editorial changes
abhidnya13 e5ebd28
Review changes 1
abhidnya13 8901269
Fixing broken test
abhidnya13 7774be8
Cleaning up
abhidnya13 42ca7a2
PR review changes part 1
abhidnya13 d38d38d
PR review changes part 2
abhidnya13 3226bc4
PR review changes part 3
abhidnya13 90afb94
Minor indent change
abhidnya13 a1ce0d1
PR review changes part 4
abhidnya13 ad245a7
Adding back accidentally deleted blank line
abhidnya13 34bb127
Removing extra indent
abhidnya13 a745949
Minor line add in authority.py
abhidnya13 b636baa
Making changes for backward compatibility
abhidnya13 d24d575
Some more editorial changes
abhidnya13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Review changes 1
- Loading branch information
commit e5ebd2867a8e2a31703f218cd2bebb63ba4c986b
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import requests | ||
|
|
||
|
|
||
| class MinimalHttpClient: | ||
|
|
||
| def __init__(self, verify=True, proxies=None, timeout=None): | ||
| self.session = requests.Session() | ||
| self.session.verify = verify | ||
| self.session.proxies = proxies | ||
| self.timeout = timeout | ||
|
|
||
| def post(self, url, params=None, data=None, headers=None, **kwargs): | ||
| return self.session.post( | ||
rayluo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| url, params=params, data=data, headers=headers, | ||
| timeout=self.timeout) | ||
|
|
||
| def get(self, url, params=None, headers=None, **kwargs): | ||
| return self.session.get( | ||
rayluo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| url, params=params, headers=headers, timeout=self.timeout) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,14 +4,16 @@ | |
| from tests import unittest | ||
| import requests | ||
|
|
||
| from tests.http_client import MinimalHttpClient | ||
|
|
||
|
|
||
| @unittest.skipIf(os.getenv("TRAVIS_TAG"), "Skip network io during tagged release") | ||
| class TestAuthority(unittest.TestCase): | ||
|
|
||
| def test_wellknown_host_and_tenant(self): | ||
| # Assert all well known authority hosts are using their own "common" tenant | ||
| for host in WELL_KNOWN_AUTHORITY_HOSTS: | ||
| a = Authority('https://{}/common'.format(host), requests.Session()) | ||
| a = Authority('https://{}/common'.format(host), MinimalHttpClient()) | ||
| self.assertEqual( | ||
| a.authorization_endpoint, | ||
| 'https://%s/common/oauth2/v2.0/authorize' % host) | ||
|
|
@@ -24,14 +26,14 @@ def test_lessknown_host_will_return_a_set_of_v1_endpoints(self): | |
| # It is probably not a strict API contract. I simply mention it here. | ||
| less_known = 'login.windows.net' # less.known.host/ | ||
| v1_token_endpoint = 'https://{}/common/oauth2/token'.format(less_known) | ||
| a = Authority('https://{}/common'.format(less_known), requests.Session()) | ||
| a = Authority('https://{}/common'.format(less_known), MinimalHttpClient()) | ||
| self.assertEqual(a.token_endpoint, v1_token_endpoint) | ||
| self.assertNotIn('v2.0', a.token_endpoint) | ||
|
|
||
| def test_unknown_host_wont_pass_instance_discovery(self): | ||
| _assert = getattr(self, "assertRaisesRegex", self.assertRaisesRegexp) # Hack | ||
| with _assert(ValueError, "invalid_instance"): | ||
| Authority('https://example.com/tenant_doesnt_matter_in_this_case', requests.Session()) | ||
| Authority('https://example.com/tenant_doesnt_matter_in_this_case', MinimalHttpClient()) | ||
|
|
||
| def test_invalid_host_skipping_validation_can_be_turned_off(self): | ||
| try: | ||
|
|
@@ -73,3 +75,21 @@ def test_canonicalize_rejects_tenantless_host_with_trailing_slash(self): | |
| canonicalize("https://no.tenant.example.com/") | ||
|
|
||
|
|
||
| @unittest.skipIf(os.getenv("TRAVIS_TAG"), "Skip network io during tagged release") | ||
| class TestAuthorityInternalHelperUserRealmDiscovery(unittest.TestCase): | ||
| def test_memorize(self): | ||
| # We use a real authority so the constructor can finish tenant discovery | ||
| authority = "https://login.microsoftonline.com/common" | ||
| self.assertNotIn(authority, Authority._domains_without_user_realm_discovery) | ||
| a = Authority(authority, validate_authority=False) | ||
|
|
||
| # We now pretend this authority supports no User Realm Discovery | ||
| class MockResponse(object): | ||
| status_code = 404 | ||
| a.user_realm_discovery("[email protected]", response=MockResponse()) | ||
| self.assertIn( | ||
| "login.microsoftonline.com", | ||
| Authority._domains_without_user_realm_discovery, | ||
| "user_realm_discovery() should memorize domains not supporting URD") | ||
| a.user_realm_discovery("[email protected]", | ||
| response="This would cause exception if memorization did not work") | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.