Skip to content

Commit

Permalink
FastForm should now forward also url GET parameters when redirecting
Browse files Browse the repository at this point in the history
  • Loading branch information
amol- committed Jan 14, 2014
1 parent c1a626f commit c8d073d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
9 changes: 8 additions & 1 deletion tests/test_fastform.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,17 @@ def test_challenge_redirect_to_form(self):
assert isinstance(ans, HTTPFound)
assert ans.location == '/SOMEWHERE/login?came_from=%2FSOMEWHERE%2Fprivate'

def test_challenge_redirect_to_form_with_args(self):
env = build_env('/private', qs='A=1&B=2', SCRIPT_NAME='/SOMEWHERE')
ans = self.fform.challenge(env, '401 Unauthorized', [('app', '1')], [('forget', '1')])

assert isinstance(ans, HTTPFound)
assert ans.location == '/SOMEWHERE/login?came_from=%2FSOMEWHERE%2Fprivate%3FA%3D1%26B%3D2', ans.location

def test_remember_forget(self):
env = build_env('/private', SCRIPT_NAME='/SOMEWHERE')
assert self.fform.remember(env, {}) == 'REMEMBER'
assert self.fform.forget(env, {}) == 'FORGET'

def test_repr(self):
assert repr(self.fform).startswith('<FastFormPlugin:/login_handler')
assert repr(self.fform).startswith('<FastFormPlugin:/login_handler')
12 changes: 4 additions & 8 deletions tg/configuration/auth/fastform.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
from tg.controllers.util import _build_url

try:
from urlparse import urlparse, urlunparse
from urlparse import urlparse, urlunparse, parse_qs
except ImportError: #pragma: no cover
from urllib.parse import urlparse, urlunparse
from urllib.parse import urlparse, urlunparse, parse_qs

try:
from urllib import urlencode
except ImportError: #pragma: no cover
from urllib.parse import urlencode

try:
from urlparse import parse_qs
except ImportError:#pragma: no cover
from cgi import parse_qs

from webob import Request
from webob.exc import HTTPFound, HTTPUnauthorized
from zope.interface import implementer
Expand Down Expand Up @@ -125,7 +120,8 @@ def challenge(self, environ, status, app_headers, forget_headers):
destination = _build_url(environ, self.post_logout_url, params=params)

else:
params = {'came_from': _build_url(environ, path_info)}
came_from_params = parse_qs(environ.get('QUERY_STRING', ''))
params = {'came_from': _build_url(environ, path_info, came_from_params)}
destination = _build_url(environ, self.login_form_url, params=params)

return HTTPFound(location=destination, headers=headers)
Expand Down

0 comments on commit c8d073d

Please sign in to comment.