-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move invite code check to start of login flow, and add tests (#514)
- Loading branch information
1 parent
6d15127
commit 9391f0a
Showing
3 changed files
with
85 additions
and
5 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
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 |
---|---|---|
|
@@ -98,6 +98,74 @@ def test_fxa_login(self, with_client): | |
assert 'url' in data | ||
assert data.get('url') == FXA_CLIENT_PATCH.get('authorization_url') | ||
|
||
def test_fxa_with_allowlist_and_without_invite(self, with_client, with_l10n): | ||
os.environ['AUTH_SCHEME'] = 'fxa' | ||
os.environ['FXA_ALLOW_LIST'] = '@example.org' | ||
|
||
email = '[email protected]' | ||
response = with_client.get( | ||
'/fxa_login', | ||
params={ | ||
'email': email, | ||
}, | ||
) | ||
assert response.status_code == 403, response.text | ||
data = response.json() | ||
assert data.get('detail') == l10n('not-in-allow-list') | ||
|
||
def test_fxa_with_allowlist_and_with_bad_invite_code(self, with_client, with_l10n): | ||
os.environ['AUTH_SCHEME'] = 'fxa' | ||
os.environ['FXA_ALLOW_LIST'] = '@example.org' | ||
|
||
email = '[email protected]' | ||
response = with_client.get( | ||
'/fxa_login', | ||
params={ | ||
'email': email, | ||
'invite_code': 'absolute nonsense!' | ||
}, | ||
) | ||
assert response.status_code == 404, response.text | ||
data = response.json() | ||
assert data.get('detail') == l10n('invite-code-not-valid') | ||
|
||
def test_fxa_with_allowlist_and_with_used_invite_code(self, with_client, with_l10n, make_invite, make_pro_subscriber): | ||
os.environ['AUTH_SCHEME'] = 'fxa' | ||
os.environ['FXA_ALLOW_LIST'] = '@example.org' | ||
|
||
other_guy = make_pro_subscriber() | ||
invite = make_invite(subscriber_id=other_guy.id) | ||
|
||
email = '[email protected]' | ||
response = with_client.get( | ||
'/fxa_login', | ||
params={ | ||
'email': email, | ||
'invite_code': invite.code | ||
}, | ||
) | ||
assert response.status_code == 403, response.text | ||
data = response.json() | ||
assert data.get('detail') == l10n('invite-code-not-valid') | ||
|
||
def test_fxa_with_allowlist_and_with_invite(self, with_client, with_l10n, make_invite): | ||
os.environ['AUTH_SCHEME'] = 'fxa' | ||
os.environ['FXA_ALLOW_LIST'] = '@example.org' | ||
|
||
invite = make_invite() | ||
email = '[email protected]' | ||
response = with_client.get( | ||
'/fxa_login', | ||
params={ | ||
'email': email, | ||
'invite_code': invite.code, | ||
}, | ||
) | ||
assert response.status_code == 200, response.text | ||
data = response.json() | ||
assert 'url' in data | ||
assert data.get('url') == FXA_CLIENT_PATCH.get('authorization_url') | ||
|
||
def test_fxa_callback_with_invite(self, with_db, with_client, monkeypatch, make_invite): | ||
"""Test that our callback function correctly handles the session states, and creates a new subscriber""" | ||
os.environ['AUTH_SCHEME'] = 'fxa' | ||
|