Ignore:
Timestamp:
8 Jul 2013, 08:35:22 (11 years ago)
Author:
uli
Message:

Support /validate (CAS 1.0).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.cas/trunk/waeup/cas/tests/test_server.py

    r10415 r10416  
    1313    create_tgc_value, check_login_ticket, set_session_cookie,
    1414    check_session_cookie, get_template, delete_session_cookie,
     15    check_service_ticket,
    1516    )
    1617
     
    9596        # we can access a validation page
    9697        app = CASServer()
    97         req = Request.blank('http://localhost/validate')
    98         resp = app(req)
    99         assert resp.status == '501 Not Implemented'
     98        req = Request.blank('http://localhost/validate?service=foo&ticket=bar')
     99        resp = app(req)
     100        assert resp.status == '200 OK'
    100101
    101102    def test_logout(self):
     
    254255        assert b'like you to' in resp.body
    255256        assert b'http://www.logout.com' in resp.body
     257
     258    def test_validate_invalid(self):
     259        # 2.4.2 validation failures is indicated by a given format
     260        app = CASServer()
     261        params = 'ticket=foo&service=bar'
     262        req = Request.blank('https://localhost/validate?%s' % params)
     263        resp = app(req)
     264        assert resp.body == b'no\n\n'
     265
     266    def test_validate_valid(self):
     267        # 2.4 validation success is indicated by a given format
     268        app = CASServer()
     269        sticket = create_service_ticket(
     270            'someuser', 'http://service.com/', sso=False)
     271        app.db.add(sticket)
     272        params = 'ticket=%s&service=%s' % (
     273            sticket.ticket, sticket.service)
     274        req = Request.blank('https://localhost/validate?%s' % params)
     275        resp = app(req)
     276        assert resp.body == b'yes\nsomeuser\n'
     277
     278    def test_validate_renew_invalid(self):
     279        # 2.4.1 with `renew` we accept only non-sso issued tickets
     280        app = CASServer()
     281        sticket = create_service_ticket(
     282            'someuser', 'http://service.com/', sso=True)
     283        app.db.add(sticket)
     284        params = 'ticket=%s&service=%s&renew=true' % (
     285            sticket.ticket, sticket.service)
     286        req = Request.blank('https://localhost/validate?%s' % params)
     287        resp = app(req)
     288        assert resp.body == b'no\n\n'
     289
     290    def test_validate_renew_valid(self):
     291        # 2.4.1 with `renew` we accept only non-sso issued tickets
     292        app = CASServer()
     293        sticket = create_service_ticket(
     294            'someuser', 'http://service.com/', sso=False)
     295        app.db.add(sticket)
     296        params = 'ticket=%s&service=%s&renew=true' % (
     297            sticket.ticket, sticket.service)
     298        req = Request.blank('https://localhost/validate?%s' % params)
     299        resp = app(req)
     300        assert resp.body == b'yes\nsomeuser\n'
    256301
    257302
     
    480525            TicketGrantingCookie.value == value)
    481526        assert len(list(q)) == 0
     527
     528    def test_check_service_ticket(self):
     529        db = DB('sqlite:///')
     530        st = ServiceTicket(
     531            'ST-123456', 'someuser', 'http://myservice.com', True)
     532        db.add(st)
     533        assert check_service_ticket(db, None, 'foo') is None
     534        assert check_service_ticket(db, 'foo', None) is None
     535        assert check_service_ticket(db, 'ST-123456', 'foo') is None
     536        assert check_service_ticket(db, 'foo', 'http://myservice.com') is None
     537        result = check_service_ticket(db, 'ST-123456', 'http://myservice.com')
     538        assert isinstance(result, ServiceTicket)
     539        assert result.user == 'someuser'
     540        assert check_service_ticket(
     541            db,  'ST-123456', 'http://myservice.com', True) is None
     542        assert check_service_ticket(
     543            db,  'ST-123456', 'http://myservice.com', False) is not None
Note: See TracChangeset for help on using the changeset viewer.