Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MelissaAutumn committed May 8, 2024
1 parent 97bb00c commit 551c8e8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 24 deletions.
2 changes: 1 addition & 1 deletion backend/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def setup(self, subscriber_id=None, token=None):
pass

@staticmethod
def get_redirect_url(self, state, email):
def get_redirect_url(self, db, state, email):
return FXA_CLIENT_PATCH.get('authorization_url'), state

@staticmethod
Expand Down
65 changes: 42 additions & 23 deletions backend/test/unit/test_fxa_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,55 @@


class TestFxaClient:
def test_is_in_allow_list(self):
os.environ['FXA_ALLOW_LIST'] = ''
def test_is_in_allow_list(self, with_db):
with with_db() as db:
os.environ['FXA_ALLOW_LIST'] = ''

fxa_client = FxaClient(None, None, None)
fxa_client = FxaClient(None, None, None)

test_email = 'test@example.org'
test_email = 'cooltestguy@example.org'

assert fxa_client.is_in_allow_list(test_email)
assert fxa_client.is_in_allow_list(db, test_email)

# Domain is in allow list
os.environ['FXA_ALLOW_LIST'] = '@example.org'
assert fxa_client.is_in_allow_list(test_email)
# Domain is in allow list
os.environ['FXA_ALLOW_LIST'] = '@example.org'
assert fxa_client.is_in_allow_list(db, test_email)

# Email is in allow list
os.environ['FXA_ALLOW_LIST'] = test_email
assert fxa_client.is_in_allow_list(test_email)
# Email is in allow list
os.environ['FXA_ALLOW_LIST'] = test_email
assert fxa_client.is_in_allow_list(db, test_email)

# Domain is not in allow list
os.environ['FXA_ALLOW_LIST'] = '@example.com'
assert not fxa_client.is_in_allow_list(test_email)
# Domain is not in allow list
os.environ['FXA_ALLOW_LIST'] = '@example.com'
assert not fxa_client.is_in_allow_list(db, test_email)

# Domain is in allow list
os.environ['FXA_ALLOW_LIST'] = '@example.com,@example.org'
assert fxa_client.is_in_allow_list(test_email)
# Domain is in allow list
os.environ['FXA_ALLOW_LIST'] = '@example.com,@example.org'
assert fxa_client.is_in_allow_list(db, test_email)

# Email is not allow list
os.environ['FXA_ALLOW_LIST'] = '@example.com,[email protected]'
assert not fxa_client.is_in_allow_list(db, test_email)

# Email is not allow list
os.environ['FXA_ALLOW_LIST'] = '@example.com,[email protected]'
assert not fxa_client.is_in_allow_list(db, '[email protected]@bad.org')

def test_allow_list_allows_subscriber(self, with_db, make_basic_subscriber):
with with_db() as db:
os.environ['FXA_ALLOW_LIST'] = '@abadexample.org'

fxa_client = FxaClient(None, None, None)

test_email = '[email protected]'

# They're not a user, and they're not in the allow list
assert not fxa_client.is_in_allow_list(db, test_email)

make_basic_subscriber(email=test_email)

# They're not in the allow list, but they are a user!
assert fxa_client.is_in_allow_list(db, test_email)

# Email is not allow list
os.environ['FXA_ALLOW_LIST'] = '@example.com,[email protected]'
assert not fxa_client.is_in_allow_list(test_email)

# Email is not allow list
os.environ['FXA_ALLOW_LIST'] = '@example.com,[email protected]'
assert not fxa_client.is_in_allow_list('[email protected]@bad.org')

0 comments on commit 551c8e8

Please sign in to comment.