Changeset 10413 for main/waeup.cas


Ignore:
Timestamp:
7 Jul 2013, 08:02:18 (11 years ago)
Author:
uli
Message:

Support warn parameter for login.

Location:
main/waeup.cas/trunk/waeup/cas
Files:
1 added
2 edited

Legend:

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

    r10412 r10413  
    133133
    134134
    135 def login_redirect_service(db, service, sso=True, create_ticket=True):
     135def login_redirect_service(db, service, sso=True, create_ticket=True,
     136                           warn=False):
    136137    """Return a response redirecting to a service via HTTP 303 See Other.
    137138    """
    138     # safely redirect to service given
    139139    if create_ticket:
    140140        st = create_service_ticket(service, sso)
     
    142142        service = '%s?ticket=%s' % (service, st.ticket)
    143143    html = get_template('login_service_redirect.html')
     144    if warn:
     145        html = get_template('login_service_confirm.html')
    144146    html = html.replace('SERVICE_URL', service)
    145147    resp = exc.HTTPSeeOther(location=service)
     148    if warn:
     149        resp = Response()
    146150    # try to forbid caching of any type
    147151    resp.cache_control = 'no-store'
     
    210214        service = req.POST.get('service', req.GET.get('service', None))
    211215        renew = req.POST.get('renew', req.GET.get('renew', None))
     216        warn = req.POST.get('warn', req.GET.get('warn', False))
    212217        gateway = req.POST.get('gateway', req.GET.get('gateway', None))
    213218        if renew is not None and gateway is not None:
     
    224229        if tgc and (renew is None):
    225230            if service:
    226                 return login_redirect_service(self.db, service, sso=True)
     231                return login_redirect_service(
     232                    self.db, service, sso=True, warn=warn)
    227233            else:
    228234                return login_success_no_service(
     
    238244                else:
    239245                    # safely redirect to service given
    240                     return login_redirect_service(self.db, service, sso=False)
     246                    return login_redirect_service(
     247                        self.db, service, sso=False, warn=warn)
    241248            else:
    242249                # login failed
  • main/waeup.cas/trunk/waeup/cas/tests/test_server.py

    r10412 r10413  
    200200        assert b'username' in resp.body
    201201        assert 'Set-Cookie' not in resp.headers
     202
     203    def test_login_warn(self):
     204        # 2.2.1 as a credential acceptor, with `warn` set we require confirm
     205        app = CASServer()
     206        tgc = create_tgc_value()
     207        app.db.add(tgc)
     208        value = str(tgc.value)
     209        params = 'warn=true&service=http%3A%2F%2Fwww.service.com'
     210        req = Request.blank('https://localhost/login?%s' % params)
     211        req.headers['Cookie'] = 'cas-tgc=%s' % value
     212        resp = app(req)
     213        # without warn, we would get a redirect
     214        assert resp.status == '200 OK'
     215        assert b'CAS login successful' in resp.body
    202216
    203217
Note: See TracChangeset for help on using the changeset viewer.