Changeset 10462


Ignore:
Timestamp:
7 Aug 2013, 09:11:59 (11 years ago)
Author:
uli
Message:

Add a kofa authenticator (sketch).

Location:
main/waeup.cas/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.cas/trunk/setup.py

    r10394 r10462  
    6868    [waeup.cas.authenticators]
    6969    dummy = waeup.cas.authenticators:DummyAuthenticator
     70    kofa1 = waeup.cas.authenticators:KofaAuthenticator
    7071    """,
    7172)
  • main/waeup.cas/trunk/waeup/cas/authenticators.py

    r10396 r10462  
    109109            reason = 'Invalid username or password.'
    110110        return result, reason
     111
     112
     113class KofaAuthenticator(Authenticator):
     114    """Authenticate against a running Kofa instance.
     115    """
     116
     117    name = 'kofa1'
     118
     119    def __init__(self, auth_services=None):
     120        self.services = auth_services
     121
     122    def check_credentials(self, username='', password=''):
     123        """Do the real check.
     124        """
     125        return False, 'Not implemented.'
  • main/waeup.cas/trunk/waeup/cas/tests/test_authenticators.py

    r10396 r10462  
     1import os
    12import unittest
     3from paste.deploy import loadapp
    24from waeup.cas.authenticators import (
    35    get_all_authenticators, get_authenticator, filter_auth_opts,
    4     Authenticator, DummyAuthenticator,
     6    Authenticator, DummyAuthenticator, KofaAuthenticator
    57    )
     8from waeup.cas.server import CASServer
    69
    710
     
    5457        result2 = auth.check_credentials('foo', 'bar')
    5558        assert result2 == (False, 'Invalid username or password.')
     59
     60
     61SERVICES = dict(
     62    inst1 = dict(auth_url = 'http://localhost:6666/app',
     63                 service_url = 'http://example.com/foo/bar')
     64    )
     65
     66
     67class KofaAuthenticatorTests(unittest.TestCase):
     68
     69    def test_create(self):
     70        # we can create KofaAuthenticator instances
     71        auth = KofaAuthenticator()
     72        assert isinstance(auth, KofaAuthenticator)
     73
     74    def test_options_defaults(self):
     75        # all options have sensible defaults
     76        auth = KofaAuthenticator()
     77        assert auth.services is None
     78
     79    def test_options(self):
     80        # we can pass options
     81        auth = KofaAuthenticator(auth_services=SERVICES)
     82        assert auth.services == SERVICES
     83
     84    def test_paste_deploy_options(self):
     85        # we can set CAS server-related options via paste.deploy config
     86        paste_conf = os.path.join(
     87            os.path.dirname(__file__), 'sample3.ini')
     88        app = loadapp('config:%s' % paste_conf)
     89        assert isinstance(app, CASServer)
     90        assert app.db_connection_string == 'sqlite:///:memory:'
     91        assert isinstance(app.auth, KofaAuthenticator)
     92
     93    def DIStest_check_credentials(self):
     94        # we get real responses when querying Kofa instances
     95        auth = KofaAuthenticator()
     96        result1 = auth.check_credentials('bird', 'bebop')
     97        assert result1 == (True, '')
     98        result2 = auth.check_credentials('foo', 'bar')
     99        assert result2 == (False, 'Invalid username or password.')
Note: See TracChangeset for help on using the changeset viewer.