Skip to content

Commit

Permalink
Include an ENV check in use_fake_fxa that correctly maps to the conso…
Browse files Browse the repository at this point in the history
…lidated runtime environment variable ENV
  • Loading branch information
KevinMind committed Feb 11, 2025
1 parent 22fbf75 commit b1c777a
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 8 deletions.
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ x-env-mapping: &env
- HISTSIZE=50000
- HISTIGNORE=ls:exit:"cd .."
- HISTCONTROL=erasedups
- ENV=local
- CIRCLECI
- DATA_BACKUP_SKIP
- FXA_CLIENT_ID
- FXA_CLIENT_SECRET

x-olympia: &olympia
<<: *env
image: ${DOCKER_TAG:-}
Expand Down
4 changes: 4 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,7 @@ def insert_debug_toolbar_middleware(middlewares):
'static_url_prefix': 'bundle',
}
}

# Hardcode the environment to local to guarantee a clear distinction
# between local and non-local environments.
ENV = 'local'
2 changes: 2 additions & 0 deletions settings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,5 @@
'client_secret': '.',
},
}

ENV = 'test'
2 changes: 1 addition & 1 deletion src/olympia/amo/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def test_allow_mozilla_collections(self):


@pytest.mark.django_db
@override_settings(FXA_CONFIG={'default': {'client_id': '.'}})
@override_settings(FXA_CONFIG={'default': {'client_id': '.'}}, ENV='local')
def test_fake_fxa_authorization_correct_values_passed():
url = reverse('fake-fxa-authorization')
response = test.Client().get(url, {'state': 'foobar'})
Expand Down
4 changes: 2 additions & 2 deletions src/olympia/amo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1163,8 +1163,8 @@ def extract_colors_from_image(path):

def use_fake_fxa(config):
"""Return whether or not to use a fake FxA server for authentication.
Should always return False in production"""
return config.get('client_id') == '.'
Should always return False in local environments"""
return settings.ENV == 'local' and config.get('client_id') == '.'


class AMOJSONEncoder(JSONEncoder):
Expand Down
1 change: 0 additions & 1 deletion src/olympia/conf/dev/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
EMAIL_HOST_USER = EMAIL_URL['EMAIL_HOST_USER']
EMAIL_HOST_PASSWORD = EMAIL_URL['EMAIL_HOST_PASSWORD']

ENV = env('ENV')
RAISE_ON_SIGNAL_ERROR = True

API_THROTTLING = True
Expand Down
2 changes: 0 additions & 2 deletions src/olympia/conf/prod/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

SEND_REAL_EMAIL = True

ENV = env('ENV')

API_THROTTLING = True

DOMAIN = env('DOMAIN', default='addons.mozilla.org')
Expand Down
2 changes: 0 additions & 2 deletions src/olympia/conf/stage/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
EMAIL_HOST_USER = EMAIL_URL['EMAIL_HOST_USER']
EMAIL_HOST_PASSWORD = EMAIL_URL['EMAIL_HOST_PASSWORD']

ENV = env('ENV')

API_THROTTLING = True

DOMAIN = env('DOMAIN', default='addons.allizom.org')
Expand Down
6 changes: 6 additions & 0 deletions src/olympia/lib/settings_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1636,3 +1636,9 @@ def read_only_mode(env):
'manifest_path': STATIC_BUILD_MANIFEST_PATH,
}
}

# The environment in which the application is running.
# This is set by the environment variables in production environments.
# For local it is hard coded to "local" to guarantee a clear distinction
# between local and non-local environments.
ENV = env('ENV')

0 comments on commit b1c777a

Please sign in to comment.