-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix, google: don't include domain if hosted_domain has a single entry
- Loading branch information
1 parent
7937cd6
commit 05c5f9c
Showing
2 changed files
with
60 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -185,7 +185,12 @@ async def test_google( | |
assert auth_model == None | ||
|
||
|
||
async def test_hosted_domain(google_client): | ||
async def test_hosted_domain_single_entry(google_client): | ||
""" | ||
Tests that sign in is restricted to the listed domain and that the username | ||
represents the part before the `@domain.com` as expected when hosted_domain | ||
contains a single entry. | ||
""" | ||
c = Config() | ||
c.GoogleOAuthenticator.hosted_domain = ["In-Hosted-Domain.com"] | ||
c.GoogleOAuthenticator.allow_all = True | ||
|
@@ -195,6 +200,40 @@ async def test_hosted_domain(google_client): | |
handler = google_client.handler_for_user(handled_user_model) | ||
auth_model = await authenticator.get_authenticated_user(handler, None) | ||
assert auth_model | ||
assert auth_model["name"] == "user1" | ||
|
||
handled_user_model = user_model("[email protected]") | ||
handler = google_client.handler_for_user(handled_user_model) | ||
with raises(HTTPError) as exc: | ||
await authenticator.get_authenticated_user(handler, None) | ||
assert exc.value.status_code == 403 | ||
|
||
|
||
async def test_hosted_domain_multiple_entries(google_client): | ||
""" | ||
Tests that sign in is restricted to the listed domains and that the username | ||
represents the full email as expected when hosted_domain contains multiple | ||
entries. | ||
""" | ||
c = Config() | ||
c.GoogleOAuthenticator.hosted_domain = [ | ||
"In-Hosted-Domain1.com", | ||
"In-Hosted-Domain2.com", | ||
] | ||
c.GoogleOAuthenticator.allow_all = True | ||
authenticator = GoogleOAuthenticator(config=c) | ||
|
||
handled_user_model = user_model("[email protected]") | ||
handler = google_client.handler_for_user(handled_user_model) | ||
auth_model = await authenticator.get_authenticated_user(handler, None) | ||
assert auth_model | ||
assert auth_model["name"] == "[email protected]" | ||
|
||
handled_user_model = user_model("[email protected]") | ||
handler = google_client.handler_for_user(handled_user_model) | ||
auth_model = await authenticator.get_authenticated_user(handler, None) | ||
assert auth_model | ||
assert auth_model["name"] == "[email protected]" | ||
|
||
handled_user_model = user_model("[email protected]") | ||
handler = google_client.handler_for_user(handled_user_model) | ||
|