Merge lp:~sil/django-openid-auth/test-external-redirect into lp:~django-openid-auth/django-openid-auth/trunk

Proposed by Stuart Langridge
Status: Merged
Approved by: Elliot Murphy
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~sil/django-openid-auth/test-external-redirect
Merge into: lp:~django-openid-auth/django-openid-auth/trunk
Diff against target: 40 lines (+24/-0)
1 file modified
django_openid_auth/tests/test_views.py (+24/-0)
To merge this branch: bzr merge lp:~sil/django-openid-auth/test-external-redirect
Reviewer Review Type Date Requested Status
Elliot Murphy (community) Approve
Review via email: mp+17434@code.launchpad.net

Commit message

Add a test for the sanitise_redirect_url function

To post a comment you must log in.
Revision history for this message
Stuart Langridge (sil) wrote :

Add a test for the sanitise_redirect_url function that was made more complex in lp:~sil/django-openid-auth/allow-specified-external-redirect-domains.

Revision history for this message
Elliot Murphy (statik) wrote :

thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'django_openid_auth/tests/test_views.py'
2--- django_openid_auth/tests/test_views.py 2010-01-06 06:39:49 +0000
3+++ django_openid_auth/tests/test_views.py 2010-01-15 00:24:14 +0000
4@@ -43,6 +43,7 @@
5
6 from django_openid_auth import teams
7 from django_openid_auth.models import UserOpenID
8+from django_openid_auth.views import sanitise_redirect_url
9
10
11 ET = importElementTree()
12@@ -362,5 +363,28 @@
13 self.assertEqual(group2 in user.groups.all(), False)
14 self.assertTrue(group3 not in user.groups.all())
15
16+class HelperFunctionsTest(TestCase):
17+ def test_sanitise_redirect_url(self):
18+ settings.ALLOWED_EXTERNAL_OPENID_REDIRECT_DOMAINS = [
19+ "example.com", "example.org"]
20+ # list of URLs and whether they should be passed or not
21+ urls = [
22+ ("http://example.com", True),
23+ ("http://example.org/", True),
24+ ("http://example.org/foo/bar", True),
25+ ("http://example.org/foo/bar?baz=quux", True),
26+ ("http://example.org:9999/foo/bar?baz=quux", True),
27+ ("http://www.example.org/", False),
28+ ("http://example.net/foo/bar?baz=quux", False),
29+ ("/somewhere/local", True),
30+ ("/somewhere/local?url=http://fail.com/bar", True),
31+ ]
32+ for url, returns_self in urls:
33+ sanitised = sanitise_redirect_url(url)
34+ if returns_self:
35+ self.assertEqual(url, sanitised)
36+ else:
37+ self.assertEqual(settings.LOGIN_REDIRECT_URL, sanitised)
38+
39 def suite():
40 return unittest.TestLoader().loadTestsFromName(__name__)

Subscribers

People subscribed via source and target branches