From a3180155fd55b04c84365d1e04b4e50a5335acf8 Mon Sep 17 00:00:00 2001 From: Jonas Obrist Date: Wed, 10 Aug 2011 11:59:24 +0200 Subject: [PATCH] Added a way to run tests and two dummy tests Added login-logic to sso_server --- .gitignore | 4 +++ LICENSE | 24 ++++++++++++++++ MANIFEST.in | 1 + runtests.py | 50 ++++++++++++++++++++++++++++++++++ setup.py | 31 +++++++++++++++++++++ simple_sso/__init__.py | 1 + simple_sso/models.py | 1 + simple_sso/sso_server/views.py | 5 ++-- simple_sso/tests.py | 9 ++++++ 9 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 LICENSE create mode 100644 MANIFEST.in create mode 100644 runtests.py create mode 100644 setup.py create mode 100644 simple_sso/models.py diff --git a/.gitignore b/.gitignore index b3421b0..73ef910 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ *.pyc .* +/build/ +/dist/ +*.egg-info +/*env*/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8440c10 --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +Copyright (c) 2011, Jonas Obrist +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Jonas Obrist nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL JONAS OBRIST BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..0c73842 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include README.rst LICENSE diff --git a/runtests.py b/runtests.py new file mode 100644 index 0000000..f6153c9 --- /dev/null +++ b/runtests.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +#!/usr/bin/env python +import os +import sys + +INSTALLED_APPS = [ + 'django.contrib.contenttypes', + 'django.contrib.auth', + 'django.contrib.sessions', + 'django.contrib.admin', + 'simple_sso.sso_server', + 'simple_sso', +] + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': ':memory:', + } +} + +def teardown(state): + from django.conf import settings + # Restore the old settings. + for key, value in state.items(): + setattr(settings, key, value) + +def run_tests(): + from django.conf import settings + settings.configure( + INSTALLED_APPS = INSTALLED_APPS, + ROOT_URLCONF = 'runtests', + DATABASES = DATABASES, + TEST_RUNNER = 'django.test.simple.DjangoTestSuiteRunner', + ) + + # Run the test suite, including the extra validation tests. + from django.test.utils import get_runner + TestRunner = get_runner(settings) + + test_runner = TestRunner(verbosity=1, interactive=False, failfast=False) + failures = test_runner.run_tests(['simple_sso']) + return failures + + +if __name__ == "__main__": + failures = run_tests() + if failures: + sys.exit(bool(failures)) + \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..6989016 --- /dev/null +++ b/setup.py @@ -0,0 +1,31 @@ +import os +from setuptools import setup +from simple_sso import __version__ as version + +README = os.path.join(os.path.dirname(__file__), 'README.rst') + +with open(README) as fobj: + long_description = fobj.read() + +setup(name="django-simple-sso", + version=version, + description="Simple SSO for Django", + long_description=long_description, + classifiers=[ + 'Development Status :: 4 - Beta', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: BSD License', + 'Topic :: Software Development', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.7', + ], + keywords='django sso', + author='Jonas Obrist', + author_email='jonas.obrist@divio.ch', + url='http://github.com/ojii/django-simple-sso', + license='BSD', + packages=['simple_sso', 'simple_sso.sso_client', 'simple_sso.sso_server'], + install_requires=['Django>=1.3', 'django-load'], + include_package_data=True, + zip_safe=False +) diff --git a/simple_sso/__init__.py b/simple_sso/__init__.py index e69de29..5e3048b 100644 --- a/simple_sso/__init__.py +++ b/simple_sso/__init__.py @@ -0,0 +1 @@ +__version__ = '0.1' \ No newline at end of file diff --git a/simple_sso/models.py b/simple_sso/models.py new file mode 100644 index 0000000..40a96af --- /dev/null +++ b/simple_sso/models.py @@ -0,0 +1 @@ +# -*- coding: utf-8 -*- diff --git a/simple_sso/sso_server/views.py b/simple_sso/sso_server/views.py index bc31eb3..0dabbcf 100644 --- a/simple_sso/sso_server/views.py +++ b/simple_sso/sso_server/views.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from django.core.urlresolvers import reverse from django.http import (HttpResponse, HttpResponseForbidden, HttpResponseBadRequest, HttpResponseRedirect) from simple_sso.signatures import build_signature @@ -37,8 +38,8 @@ def authorize(request): token.save() return HttpResponseRedirect('%s?%s' % (url, urllib.urlencode(params))) else: - # TODO: Promt login - pass + params = urllib.urlencode([('next', '%s?%s' % (request.path, urllib.urlencode(request.GET)))]) + return HttpResponseRedirect('%s?%s' % (reverse('django.contrib.auth.views.login'), params)) else: if form.invalid_signature: return HttpResponseForbidden() diff --git a/simple_sso/tests.py b/simple_sso/tests.py index 40a96af..97f597f 100644 --- a/simple_sso/tests.py +++ b/simple_sso/tests.py @@ -1 +1,10 @@ # -*- coding: utf-8 -*- +from django.test.testcases import TestCase + + +class SimpleSSOTests(TestCase): + def test_ok(self): + self.assertTrue(True) + + def test_fail(self): + self.assertTrue(False)