From 551c8e8f7f94b3edcdcd0ffa275d6489eb18e2e8 Mon Sep 17 00:00:00 2001 From: Melissa Autumn Date: Wed, 8 May 2024 15:47:20 -0700 Subject: [PATCH] Fix tests --- backend/test/conftest.py | 2 +- backend/test/unit/test_fxa_client.py | 65 ++++++++++++++++++---------- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/backend/test/conftest.py b/backend/test/conftest.py index 61405d2af..78e63d45f 100644 --- a/backend/test/conftest.py +++ b/backend/test/conftest.py @@ -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 diff --git a/backend/test/unit/test_fxa_client.py b/backend/test/unit/test_fxa_client.py index 14792cbf2..704d2b405 100644 --- a/backend/test/unit/test_fxa_client.py +++ b/backend/test/unit/test_fxa_client.py @@ -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,not-test@example.org' + assert not fxa_client.is_in_allow_list(db, test_email) + + # Email is not allow list + os.environ['FXA_ALLOW_LIST'] = '@example.com,not-test@example.org' + assert not fxa_client.is_in_allow_list(db, 'hello@example.com@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 = 'new-test@example.org' + + # 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,not-test@example.org' - assert not fxa_client.is_in_allow_list(test_email) - # Email is not allow list - os.environ['FXA_ALLOW_LIST'] = '@example.com,not-test@example.org' - assert not fxa_client.is_in_allow_list('hello@example.com@bad.org')