diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index 129d9d4a19..01ee90cde8 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -952,7 +952,7 @@ def create_random_account_with_name_and_password(create_account_function): # for load testing we want to create lots of accounts # with controlled username and password -if settings.AUTOMATIC_AUTH_FOR_LOAD_TESTING: +if settings.MITX_FEATURES.get('AUTOMATIC_AUTH_FOR_LOAD_TESTING'): create_account = create_random_account_with_name_and_password(create_account) @ensure_csrf_cookie diff --git a/lms/djangoapps/branding/views.py b/lms/djangoapps/branding/views.py index f30eec1554..2abf50022e 100644 --- a/lms/djangoapps/branding/views.py +++ b/lms/djangoapps/branding/views.py @@ -53,7 +53,7 @@ def courses(request): def auto_auth(request): """ - Automatically logs the anonymous user in with a generated random credentials + Automatically logs the user in with a generated random credentials This view is only accessible when settings.AUTOMATIC_AUTH_FOR_LOAD_TESTING is true. """ @@ -62,7 +62,7 @@ def auto_auth(request): from django.contrib.auth import login, authenticate from random import randint - # generate random user ceredentials from a small name space + # generate random user ceredentials from a small name space (determined by settings) name_base = 'USER_' pass_base = 'PASS_' @@ -71,14 +71,14 @@ def auto_auth(request): username = name_base + str(number) password = pass_base + str(number) - # if they already are a user, log in + # if they already are a user, log in try: user = User.objects.get(username=username) user = authenticate(username=username, password=password) login(request, user) + # else create and activate account info except: - # create and activate account info student.views.create_account(request, username, password) request.user.is_active = True request.user.save() diff --git a/lms/envs/aws.py b/lms/envs/aws.py index 79178e27a3..ae9dc86687 100644 --- a/lms/envs/aws.py +++ b/lms/envs/aws.py @@ -178,6 +178,8 @@ for name, value in ENV_TOKENS.get("CODE_JAIL", {}).items(): COURSES_WITH_UNSAFE_CODE = ENV_TOKENS.get("COURSES_WITH_UNSAFE_CODE", []) +# automatic log in for load testing +MITX_FEATURES['AUTOMATIC_AUTH_FOR_LOAD_TESTING'] = ENV_TOKENS.get('AUTOMATIC_AUTH_FOR_LOAD_TESTING') ############################## SECURE AUTH ITEMS ############### # Secret things: passwords, access keys, etc. diff --git a/lms/envs/common.py b/lms/envs/common.py index 57604ba1ff..f8f7aec156 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -37,8 +37,8 @@ PLATFORM_NAME = "edX" COURSEWARE_ENABLED = True ENABLE_JASMINE = False -AUTOMATIC_AUTH_FOR_LOAD_TESTING = True -MAX_AUTO_AUTH_USERS = 2 +# only relevant if MITX_FEATURES['AUTOMATIC_AUTH_FOR_LOAD_TESTING'] = True +MAX_AUTO_AUTH_USERS = 20 GENERATE_RANDOM_USER_CREDENTIALS = False PERFSTATS = False @@ -150,6 +150,9 @@ MITX_FEATURES = { # Allow use of the hint managment instructor view. 'ENABLE_HINTER_INSTRUCTOR_VIEW': False, + + # for load testing + 'AUTOMATIC_AUTH_FOR_LOAD_TESTING': False, } # Used for A/B testing @@ -233,7 +236,7 @@ TEMPLATE_CONTEXT_PROCESSORS = ( ) # add csrf support unless disabled for load testing -if not AUTOMATIC_AUTH_FOR_LOAD_TESTING: +if not MITX_FEATURES.get('AUTOMATIC_AUTH_FOR_LOAD_TESTING'): TEMPLATE_CONTEXT_PROCESSORS += ('django.core.context_processors.csrf',) # necessary for csrf protection STUDENT_FILEUPLOAD_MAX_SIZE = 4 * 1000 * 1000 # 4 MB @@ -491,7 +494,7 @@ MIDDLEWARE_CLASSES = ( ) # add in csrf middleware unless disabled for load testing -if not AUTOMATIC_AUTH_FOR_LOAD_TESTING: +if not MITX_FEATURES.get('AUTOMATIC_AUTH_FOR_LOAD_TESTING'): MIDDLEWARE_CLASSES = MIDDLEWARE_CLASSES + ('django.middleware.csrf.CsrfViewMiddleware',) ############################### Pipeline ####################################### diff --git a/lms/urls.py b/lms/urls.py index 899586562e..1c77530e6b 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -440,7 +440,7 @@ if settings.DEBUG: urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) # enable automatic login -if settings.AUTOMATIC_AUTH_FOR_LOAD_TESTING: +if settings.MITX_FEATURES.get('AUTOMATIC_AUTH_FOR_LOAD_TESTING'): urlpatterns += ( url(r'^auto_auth$', 'branding.views.auto_auth'), )