You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2015/02/11 18:10:45 UTC
[1/2] allura git commit: [#7831] minor code improvements, including:
Repository: allura
Updated Branches:
refs/heads/master 70df2e8fe -> 6face2dfe
[#7831] minor code improvements, including:
* disable_auth_magic=False should do what you expect
* set extra_environ on the app instead of on each request in the test
* assert_equal for more helpful failure output
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/6face2df
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/6face2df
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/6face2df
Branch: refs/heads/master
Commit: 6face2dfee01a32bd1559f772a5b09c2d09c142b
Parents: 6bc50fe
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Wed Feb 11 17:01:23 2015 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Feb 11 17:10:21 2015 +0000
----------------------------------------------------------------------
Allura/allura/controllers/basetest_project_root.py | 8 ++++----
Allura/allura/tests/functional/test_auth.py | 12 ++++++------
2 files changed, 10 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/6face2df/Allura/allura/controllers/basetest_project_root.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/basetest_project_root.py b/Allura/allura/controllers/basetest_project_root.py
index 459a62f..f655437 100644
--- a/Allura/allura/controllers/basetest_project_root.py
+++ b/Allura/allura/controllers/basetest_project_root.py
@@ -25,6 +25,7 @@ from pylons import tmpl_context as c
from pylons import request
from webob import exc
from tg import expose
+from paste.deploy.converters import asbool
from allura.lib.base import WsgiDispatchController
from allura.lib.security import require, require_authenticated, require_access, has_access
@@ -118,7 +119,7 @@ class BasetestProjectRootController(WsgiDispatchController, ProjectController):
return app.root, remainder
def __call__(self, environ, start_response):
- """ Called from a turbo gears 'app' instance.
+ """ Called from a WebTest 'app' instance.
:param environ: Extra environment variables.
@@ -127,11 +128,10 @@ class BasetestProjectRootController(WsgiDispatchController, ProjectController):
c.app = None
c.project = M.Project.query.get(
shortname='test', neighborhood_id=self.p_nbhd._id)
- if 'disable_auth_magic' in environ:
- auth = plugin.AuthenticationProvider.get(request)
+ auth = plugin.AuthenticationProvider.get(request)
+ if asbool(environ.get('disable_auth_magic')):
c.user = auth.authenticate_request()
else:
- auth = plugin.AuthenticationProvider.get(request)
user = auth.by_username(environ.get('username', 'test-admin'))
if not user:
user = M.User.anonymous()
http://git-wip-us.apache.org/repos/asf/allura/blob/6face2df/Allura/allura/tests/functional/test_auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_auth.py b/Allura/allura/tests/functional/test_auth.py
index bfd3c72..b71ffcd 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -75,19 +75,19 @@ class TestAuth(TestController):
assert 'Invalid login' in str(r), r.showbrowser()
def test_logout(self):
- environ = {'disable_auth_magic': "True"}
- r = self.app.get('/auth/', extra_environ=environ)
+ self.app.extra_environ = {'disable_auth_magic': 'True'}
+ r = self.app.get('/auth/')
f = r.forms[0]
f['username'] = 'test-user'
f['password'] = 'foo'
- r = f.submit().follow(extra_environ=environ)
+ r = f.submit().follow()
logged_in_session = r.session['_id']
- assert r.html.nav('a')[-1].string == "Log Out"
+ assert_equal(r.html.nav('a')[-1].string, "Log Out")
- r = self.app.get('/auth/logout', extra_environ=environ).follow(extra_environ=environ)
+ r = self.app.get('/auth/logout').follow()
logged_out_session = r.session['_id']
assert logged_in_session is not logged_out_session
- assert r.html.nav('a')[-1].string == 'Log In'
+ assert_equal(r.html.nav('a')[-1].string, 'Log In')
def test_track_login(self):
user = M.User.by_username('test-user')
[2/2] allura git commit: [#7831] Fixed an issue that prevented users
from logging out
Posted by br...@apache.org.
[#7831] Fixed an issue that prevented users from logging out
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/6bc50feb
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/6bc50feb
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/6bc50feb
Branch: refs/heads/master
Commit: 6bc50feb600b2ba642c84354442e3028dce12dc8
Parents: 70df2e8
Author: Heith Seewald <hs...@slashdotmedia.com>
Authored: Tue Feb 10 15:40:54 2015 -0500
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Wed Feb 11 17:10:21 2015 +0000
----------------------------------------------------------------------
.../allura/controllers/basetest_project_root.py | 33 +++++++++++---------
Allura/allura/lib/plugin.py | 1 +
Allura/allura/tests/functional/test_auth.py | 17 ++++++++--
3 files changed, 35 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/6bc50feb/Allura/allura/controllers/basetest_project_root.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/basetest_project_root.py b/Allura/allura/controllers/basetest_project_root.py
index a2df7a2..459a62f 100644
--- a/Allura/allura/controllers/basetest_project_root.py
+++ b/Allura/allura/controllers/basetest_project_root.py
@@ -41,7 +41,6 @@ log = logging.getLogger(__name__)
class BasetestProjectRootController(WsgiDispatchController, ProjectController):
-
'''Root controller for testing -- it behaves just like a
ProjectController for test/ except that all tools are mounted,
on-demand, at the mount point that is the same as their entry point
@@ -119,23 +118,32 @@ class BasetestProjectRootController(WsgiDispatchController, ProjectController):
return app.root, remainder
def __call__(self, environ, start_response):
+ """ Called from a turbo gears 'app' instance.
+
+
+ :param environ: Extra environment variables.
+ Example: self.app.get('/auth/', extra_environ={'disable_auth_magic': "True"})
+ """
c.app = None
c.project = M.Project.query.get(
shortname='test', neighborhood_id=self.p_nbhd._id)
- auth = plugin.AuthenticationProvider.get(request)
- user = auth.by_username(environ.get('username', 'test-admin'))
- if not user:
- user = M.User.anonymous()
- environ['beaker.session']['username'] = user.username
- # save and persist, so that a creation time is set
- environ['beaker.session'].save()
- environ['beaker.session'].persist()
- c.user = auth.authenticate_request()
+ if 'disable_auth_magic' in environ:
+ auth = plugin.AuthenticationProvider.get(request)
+ c.user = auth.authenticate_request()
+ else:
+ auth = plugin.AuthenticationProvider.get(request)
+ user = auth.by_username(environ.get('username', 'test-admin'))
+ if not user:
+ user = M.User.anonymous()
+ environ['beaker.session']['username'] = user.username
+ # save and persist, so that a creation time is set
+ environ['beaker.session'].save()
+ environ['beaker.session'].persist()
+ c.user = auth.authenticate_request()
return WsgiDispatchController.__call__(self, environ, start_response)
class DispatchTest(object):
-
@expose()
def _lookup(self, *args):
if args:
@@ -145,7 +153,6 @@ class DispatchTest(object):
class NamedController(object):
-
def __init__(self, name):
self.name = name
@@ -159,7 +166,6 @@ class NamedController(object):
class SecurityTests(object):
-
@expose()
def _lookup(self, name, *args):
name = unquote(name)
@@ -169,7 +175,6 @@ class SecurityTests(object):
class SecurityTest(object):
-
def __init__(self):
from forgewiki import model as WM
c.app = c.project.app_instance('wiki')
http://git-wip-us.apache.org/repos/asf/allura/blob/6bc50feb/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index f3f90a8..a901ba9 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -176,6 +176,7 @@ class AuthenticationProvider(object):
def logout(self):
self.session.invalidate()
+ self.session.save()
response.delete_cookie('allura-loggedin')
def validate_password(self, user, password):
http://git-wip-us.apache.org/repos/asf/allura/blob/6bc50feb/Allura/allura/tests/functional/test_auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_auth.py b/Allura/allura/tests/functional/test_auth.py
index ce0e4e4..bfd3c72 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -74,6 +74,21 @@ class TestAuth(TestController):
username='test-usera', password='foo'))
assert 'Invalid login' in str(r), r.showbrowser()
+ def test_logout(self):
+ environ = {'disable_auth_magic': "True"}
+ r = self.app.get('/auth/', extra_environ=environ)
+ f = r.forms[0]
+ f['username'] = 'test-user'
+ f['password'] = 'foo'
+ r = f.submit().follow(extra_environ=environ)
+ logged_in_session = r.session['_id']
+ assert r.html.nav('a')[-1].string == "Log Out"
+
+ r = self.app.get('/auth/logout', extra_environ=environ).follow(extra_environ=environ)
+ logged_out_session = r.session['_id']
+ assert logged_in_session is not logged_out_session
+ assert r.html.nav('a')[-1].string == 'Log In'
+
def test_track_login(self):
user = M.User.by_username('test-user')
assert_equal(user.last_access['login_date'], None)
@@ -297,7 +312,6 @@ class TestAuth(TestController):
params=dict(a=email_address),
extra_environ=dict(username='test-user'))
-
user1 = M.User.query.get(username='test-user-1')
user1.claim_address(email_address)
email1 = M.EmailAddress.find(dict(email=email_address, claimed_by_user_id=user1._id)).first()
@@ -1503,7 +1517,6 @@ class TestDisableAccount(TestController):
class TestPasswordExpire(TestController):
-
def login(self, username='test-user', pwd='foo', query_string=''):
r = self.app.get('/auth/' + query_string, extra_environ={'username': '*anonymous'})
f = r.forms[0]