From: Rodney Ewing Date: Fri, 17 May 2013 17:20:46 +0000 (-0700) Subject: added tests for no_auth feature X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=dfd3f561af07e5108317992f6ae836858e3cd0bf;p=mediagoblin.git added tests for no_auth feature --- diff --git a/mediagoblin/tests/auth_configs/__init__.py b/mediagoblin/tests/auth_configs/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/mediagoblin/tests/auth_configs/basic_auth_appconfig.ini b/mediagoblin/tests/auth_configs/basic_auth_appconfig.ini new file mode 100644 index 00000000..b15ae1fb --- /dev/null +++ b/mediagoblin/tests/auth_configs/basic_auth_appconfig.ini @@ -0,0 +1,28 @@ +[mediagoblin] +direct_remote_path = /test_static/ +email_sender_address = "notice@mediagoblin.example.org" +email_debug_mode = true +no_auth = false + +# TODO: Switch to using an in-memory database +sql_engine = "sqlite:///%(here)s/test_user_dev/mediagoblin.db" + +# Celery shouldn't be set up by the application as it's setup via +# mediagoblin.init.celery.from_celery +celery_setup_elsewhere = true + +[storage:publicstore] +base_dir = %(here)s/test_user_dev/media/public +base_url = /mgoblin_media/ + +[storage:queuestore] +base_dir = %(here)s/test_user_dev/media/queue + +[celery] +CELERY_ALWAYS_EAGER = true +CELERY_RESULT_DBURI = "sqlite:///%(here)s/test_user_dev/celery.db" +BROKER_HOST = "sqlite:///%(here)s/test_user_dev/kombu.db" + +[plugins] +[[mediagoblin.plugins.basic_auth]] + diff --git a/mediagoblin/tests/auth_configs/no_auth_false_no_auth_plugin_appconfig.ini b/mediagoblin/tests/auth_configs/no_auth_false_no_auth_plugin_appconfig.ini new file mode 100644 index 00000000..719ff260 --- /dev/null +++ b/mediagoblin/tests/auth_configs/no_auth_false_no_auth_plugin_appconfig.ini @@ -0,0 +1,27 @@ +[mediagoblin] +direct_remote_path = /test_static/ +email_sender_address = "notice@mediagoblin.example.org" +email_debug_mode = true +no_auth = false + +# TODO: Switch to using an in-memory database +sql_engine = "sqlite:///%(here)s/test_user_dev/mediagoblin.db" + +# Celery shouldn't be set up by the application as it's setup via +# mediagoblin.init.celery.from_celery +celery_setup_elsewhere = true + +[storage:publicstore] +base_dir = %(here)s/test_user_dev/media/public +base_url = /mgoblin_media/ + +[storage:queuestore] +base_dir = %(here)s/test_user_dev/media/queue + +[celery] +CELERY_ALWAYS_EAGER = true +CELERY_RESULT_DBURI = "sqlite:///%(here)s/test_user_dev/celery.db" +BROKER_HOST = "sqlite:///%(here)s/test_user_dev/kombu.db" + +[plugins] + diff --git a/mediagoblin/tests/auth_configs/no_auth_true_no_auth_plugin_appconfig.ini b/mediagoblin/tests/auth_configs/no_auth_true_no_auth_plugin_appconfig.ini new file mode 100644 index 00000000..6c0d5241 --- /dev/null +++ b/mediagoblin/tests/auth_configs/no_auth_true_no_auth_plugin_appconfig.ini @@ -0,0 +1,27 @@ +[mediagoblin] +direct_remote_path = /test_static/ +email_sender_address = "notice@mediagoblin.example.org" +email_debug_mode = true +no_auth = true + +# TODO: Switch to using an in-memory database +sql_engine = "sqlite:///%(here)s/test_user_dev/mediagoblin.db" + +# Celery shouldn't be set up by the application as it's setup via +# mediagoblin.init.celery.from_celery +celery_setup_elsewhere = true + +[storage:publicstore] +base_dir = %(here)s/test_user_dev/media/public +base_url = /mgoblin_media/ + +[storage:queuestore] +base_dir = %(here)s/test_user_dev/media/queue + +[celery] +CELERY_ALWAYS_EAGER = true +CELERY_RESULT_DBURI = "sqlite:///%(here)s/test_user_dev/celery.db" +BROKER_HOST = "sqlite:///%(here)s/test_user_dev/kombu.db" + +[plugins] + diff --git a/mediagoblin/tests/test_auth.py b/mediagoblin/tests/test_auth.py index a9165340..c67d523f 100644 --- a/mediagoblin/tests/test_auth.py +++ b/mediagoblin/tests/test_auth.py @@ -13,13 +13,16 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . - +import pkg_resources +import pytest import urlparse from mediagoblin import mg_globals from mediagoblin.db.models import User -from mediagoblin.tests.tools import fixture_add_user +from mediagoblin.tests.tools import get_app, fixture_add_user from mediagoblin.tools import template, mail +from mediagoblin.auth.tools import AuthError +from mediagoblin import auth def test_register_views(test_app): @@ -273,3 +276,52 @@ def test_authentication_views(test_app): 'password': 'toast', 'next' : '/u/chris/'}) assert urlparse.urlsplit(response.location)[2] == '/u/chris/' + + +# App with no_auth=false and no auth plugin enabled +def no_auth_false_no_auth_plugin_app(request): + return get_app( + request, + mgoblin_config=pkg_resources.resource_filename( + 'mediagoblin.tests.auth_configs', + 'no_auth_false_no_auth_plugin_appconfig.ini')) + + +def test_no_auth_false_no_auth_plugin_raises(request): + with pytest.raises(AuthError): + no_auth_false_no_auth_plugin_app(request) + + +@pytest.fixture() +def no_auth_true_no_auth_plugin_app(request): + return get_app( + request, + mgoblin_config=pkg_resources.resource_filename( + 'mediagoblin.tests.auth_configs', + 'no_auth_true_no_auth_plugin_appconfig.ini')) + + +def test_no_auth_true_no_auth_plugin_app(no_auth_true_no_auth_plugin_app): + # app.auth should = false + assert mg_globals.app.auth is False + + # Try to visit register page + template.clear_test_template_context() + response = no_auth_true_no_auth_plugin_app.get('/auth/register/') + response.follow() + + # Correct redirect? + assert urlparse.urlsplit(response.location)[2] == '/' + assert 'mediagoblin/root.html' in template.TEMPLATE_TEST_CONTEXT + + # Try to vist login page + template.clear_test_template_context() + response = no_auth_true_no_auth_plugin_app.get('/auth/login/') + response.follow() + + # Correct redirect? + assert urlparse.urlsplit(response.location)[2] == '/' + assert 'mediagoblin/root.html' in template.TEMPLATE_TEST_CONTEXT + + ## Test check_login should return False + assert auth.check_login('test', 'simple') is False diff --git a/mediagoblin/tests/test_basic_auth.py b/mediagoblin/tests/test_basic_auth.py index 20098ab7..a985c315 100644 --- a/mediagoblin/tests/test_basic_auth.py +++ b/mediagoblin/tests/test_basic_auth.py @@ -72,15 +72,15 @@ def context_modified_app(request): return get_app( request, mgoblin_config=pkg_resources.resource_filename( - 'mediagoblin.tests', 'basic_auth_appconfig.ini')) + 'mediagoblin.tests.auth_configs', 'basic_auth_appconfig.ini')) def test_fp_view(context_modified_app): ### Oops, forgot the password - # ------------------- ## Register a user fixture_add_user(active_user=True) + # ------------------- template.clear_test_template_context() response = context_modified_app.post( '/auth/forgot_password/',