Skip to content

Commit 0729b79

Browse files
committed
Merge pull request #48 from cordmata/develop
Allow Forcing Service URL over HTTPS
2 parents 350cef3 + 53eb37b commit 0729b79

File tree

7 files changed

+29
-11
lines changed

7 files changed

+29
-11
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ env:
99
- DJANGO_VERSION=Django==1.5
1010
- DJANGO_VERSION=Django==1.6
1111
- DJANGO_VERSION=Django==1.7
12+
- DJANGO_VERSION=Django==1.8
1213

1314
# command to install dependencies
1415
install:

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ This is [K-State's fork](https://github.com/kstateome/django-cas) of [the or
1515
This project is registered on PyPi as django-cas-client. To install::
1616

1717
pip install django-cas-client==1.1.2
18-
19-
18+
19+
2020
### Add to URLs
2121

2222
Add the login and logout patterns to your main URLS conf.
@@ -34,9 +34,9 @@ Set your CAS server URL
3434
Add cas to middleware classes
3535

3636
'cas.middleware.CASMiddleware',
37-
3837

39-
### Add authentication backends
38+
39+
### Add authentication backends
4040

4141
AUTHENTICATION_BACKENDS = (
4242
'django.contrib.auth.backends.ModelBackend',
@@ -138,6 +138,9 @@ Then, add the ``gateway`` decorator to a view:
138138
To show a custom forbidden page, set ``CAS_CUSTOM_FORBIDDEN`` to a ``path.to.some_view``. Otherwise,
139139
a generic ``HttpResponseForbidden`` will be returned.
140140

141+
## Require SSL login
142+
143+
To force the service url to always target HTTPS, set ``CAS_FORCE_SSL_SERVICE_URL`` to ``True``.
141144

142145
## Proxy Tickets
143146

@@ -146,4 +149,4 @@ This fork also includes
146149

147150
You can opt out of the time delay sometimes caused by proxy ticket validation by setting:
148151

149-
CAS_PGT_FETCH_WAIT = False
152+
CAS_PGT_FETCH_WAIT = False

cas/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
'CAS_RESPONSE_CALLBACKS': None,
1919
'CAS_CUSTOM_FORBIDDEN': None,
2020
'CAS_PGT_FETCH_WAIT': True,
21+
'CAS_FORCE_SSL_SERVICE_URL': False,
2122
}
2223

2324
for key, value in _DEFAULTS.items():

cas/tests/test_views.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from django.test import TestCase, RequestFactory
2+
from django.test.utils import override_settings
23

34
from cas.views import _redirect_url, _login_url, _logout_url, _service_url
45

@@ -24,6 +25,10 @@ def setUp(self):
2425
def test_service_url(self):
2526
self.assertEqual(_service_url(self.request), 'http://signin.k-state.edu/')
2627

28+
@override_settings(CAS_FORCE_SSL_SERVICE_URL=True)
29+
def test_service_url_forced_ssl(self):
30+
self.assertEqual(_service_url(self.request), 'https://signin.k-state.edu/')
31+
2732
def test_redirect_url(self):
2833
self.assertEqual(_redirect_url(self.request), '/')
2934

@@ -38,4 +43,4 @@ def test_login_url(self):
3843
'http://signin.cas.com/login?service=http%3A%2F%2Flocalhost%3A8000%2Faccounts%2Flogin%2F')
3944

4045
def test_logout_url(self):
41-
self.assertEqual(_logout_url(self.request), 'http://signin.cas.com/logout')
46+
self.assertEqual(_logout_url(self.request), 'http://signin.cas.com/logout')

cas/views.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ def _service_url(request, redirect_to=None, gateway=False):
3535
3636
"""
3737

38-
protocol = ('http://', 'https://')[request.is_secure()]
38+
if settings.CAS_FORCE_SSL_SERVICE_URL:
39+
protocol = 'https://'
40+
else:
41+
protocol = ('http://', 'https://')[request.is_secure()]
3942
host = request.get_host()
4043
service = protocol + host + request.path
4144
if redirect_to:

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
factory_boy
1+
factory_boy

run_tests.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,13 @@
4747
except AttributeError:
4848
pass
4949

50-
from django.test.simple import DjangoTestSuiteRunner
51-
test_runner = DjangoTestSuiteRunner(verbosity=1)
50+
try:
51+
from django.test.simple import DjangoTestSuiteRunner
52+
test_runner = DjangoTestSuiteRunner(verbosity=1)
53+
except ImportError:
54+
from django.test.utils import get_runner
55+
TestRunner = get_runner(settings)
56+
test_runner = TestRunner()
5257
failures = test_runner.run_tests(['cas', ])
5358
if failures:
54-
sys.exit(failures)
59+
sys.exit(failures)

0 commit comments

Comments
 (0)