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

Add a kofa authenticator (sketch).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.