Support development FxA config on dev (#3540)

This commit is contained in:
Mark Striemer 2016-09-20 17:08:09 -05:00 коммит произвёл GitHub
Родитель 59ce67cdd5
Коммит 1ee3c80093
7 изменённых файлов: 46 добавлений и 11 удалений

Просмотреть файл

@ -112,6 +112,10 @@ FXA_CONFIG = {
},
}
FXA_CONFIG['amo'] = FXA_CONFIG['internal']
FXA_CONFIG['local'] = FXA_CONFIG['internal']
DEFAULT_FXA_CONFIG_NAME = 'default'
INTERNAL_FXA_CONFIG_NAME = 'internal'
ALLOWED_FXA_CONFIGS = ['default', 'amo', 'local']
# CSP report endpoint which returns a 204 from addons-nginx in local dev.
CSP_REPORT_URI = '/csp-report'

Просмотреть файл

@ -173,7 +173,8 @@ class TestLoginView(BaseAuthenticationView):
def test_correct_config_is_used(self):
assert views.LoginView.DEFAULT_FXA_CONFIG_NAME == 'default'
assert views.LoginView.ALLOWED_FXA_CONFIGS == ['default', 'amo']
assert views.LoginView.ALLOWED_FXA_CONFIGS == (
['default', 'amo', 'local'])
def test_cors_addons_frontend(self):
response = self.options(self.url, origin='https://addons-frontend')
@ -198,7 +199,8 @@ class TestLoginStartView(TestCase):
def test_default_config_is_used(self):
assert views.LoginStartView.DEFAULT_FXA_CONFIG_NAME == 'default'
assert views.LoginStartView.ALLOWED_FXA_CONFIGS == ['default', 'amo']
assert views.LoginStartView.ALLOWED_FXA_CONFIGS == (
['default', 'amo', 'local'])
class TestLoginUser(TestCase):

Просмотреть файл

@ -184,7 +184,8 @@ def with_user(format, config=None):
@write
def inner(self, request):
if config is None:
fxa_config = settings.FXA_CONFIG['default']
fxa_config = (
settings.FXA_CONFIG[settings.DEFAULT_FXA_CONFIG_NAME])
else:
fxa_config = config
@ -267,10 +268,18 @@ def add_api_token_to_response(response, user, set_cookie=True):
class FxAConfigMixin(object):
def get_config_name(self, request):
return request.GET.get('config', self.DEFAULT_FXA_CONFIG_NAME)
def get_allowed_configs(self):
return getattr(
self, 'ALLOWED_FXA_CONFIGS', [self.DEFAULT_FXA_CONFIG_NAME])
def get_fxa_config(self, request):
config_name = request.GET.get('config')
if config_name in getattr(self, 'ALLOWED_FXA_CONFIGS', []):
config_name = self.get_config_name(request)
if config_name in self.get_allowed_configs():
return settings.FXA_CONFIG[config_name]
log.info('Using default FxA config instead of {}'.format(config_name))
return settings.FXA_CONFIG[self.DEFAULT_FXA_CONFIG_NAME]
@ -287,8 +296,8 @@ class LoginStartBaseView(FxAConfigMixin, APIView):
class LoginStartView(LoginStartBaseView):
DEFAULT_FXA_CONFIG_NAME = 'default'
ALLOWED_FXA_CONFIGS = ['default', 'amo']
DEFAULT_FXA_CONFIG_NAME = settings.DEFAULT_FXA_CONFIG_NAME
ALLOWED_FXA_CONFIGS = settings.ALLOWED_FXA_CONFIGS
class LoginBaseView(FxAConfigMixin, APIView):
@ -313,8 +322,8 @@ class LoginBaseView(FxAConfigMixin, APIView):
class LoginView(LoginBaseView):
DEFAULT_FXA_CONFIG_NAME = 'default'
ALLOWED_FXA_CONFIGS = ['default', 'amo']
DEFAULT_FXA_CONFIG_NAME = settings.DEFAULT_FXA_CONFIG_NAME
ALLOWED_FXA_CONFIGS = settings.ALLOWED_FXA_CONFIGS
class RegisterView(APIView):

Просмотреть файл

@ -261,7 +261,19 @@ FXA_CONFIG = {
'redirect_url': 'https://amo.dev.mozaws.net/fxa-authenticate',
'scope': 'profile',
},
'local': {
'client_id': env('DEVELOPMENT_FXA_CLIENT_ID'),
'client_secret': env('DEVELOPMENT_FXA_CLIENT_SECRET'),
'content_host': 'https://stable.dev.lcip.org',
'oauth_host': 'https://oauth-stable.dev.lcip.org/v1',
'profile_host': 'https://stable.dev.lcip.org/profile/v1',
'redirect_url': 'http://localhost:3000/fxa-authenticate',
'scope': 'profile',
},
}
DEFAULT_FXA_CONFIG_NAME = 'default'
INTERNAL_FXA_CONFIG_NAME = 'internal'
ALLOWED_FXA_CONFIGS = ['default', 'amo', 'local']
INTERNAL_DOMAINS = [
'addons-admin.dev.mozaws.net',

Просмотреть файл

@ -217,6 +217,9 @@ FXA_CONFIG = {
},
}
FXA_CONFIG['amo'] = FXA_CONFIG['default']
DEFAULT_FXA_CONFIG_NAME = 'default'
INTERNAL_FXA_CONFIG_NAME = 'internal'
ALLOWED_FXA_CONFIGS = ['default', 'amo']
INTERNAL_DOMAINS = ['addons-admin.prod.mozaws.net']
for regex, overrides in CORS_ENDPOINT_OVERRIDES:

Просмотреть файл

@ -249,6 +249,9 @@ FXA_CONFIG = {
},
}
FXA_CONFIG['amo'] = FXA_CONFIG['default']
DEFAULT_FXA_CONFIG_NAME = 'default'
INTERNAL_FXA_CONFIG_NAME = 'internal'
ALLOWED_FXA_CONFIGS = ['default', 'amo']
INTERNAL_DOMAINS = ['addons-admin.stage.mozaws.net']
for regex, overrides in CORS_ENDPOINT_OVERRIDES:

Просмотреть файл

@ -1,5 +1,7 @@
import logging
from django.conf import settings
from olympia.accounts.views import LoginBaseView, LoginStartBaseView
from olympia.addons.views import AddonSearchView
from olympia.api.authentication import JSONWebTokenAuthentication
@ -27,8 +29,8 @@ class InternalAddonSearchView(AddonSearchView):
class LoginStartView(LoginStartBaseView):
DEFAULT_FXA_CONFIG_NAME = 'internal'
DEFAULT_FXA_CONFIG_NAME = settings.INTERNAL_FXA_CONFIG_NAME
class LoginView(LoginBaseView):
DEFAULT_FXA_CONFIG_NAME = 'internal'
DEFAULT_FXA_CONFIG_NAME = settings.INTERNAL_FXA_CONFIG_NAME