Ignore:
Timestamp:
4 Jul 2013, 12:52:19 (11 years ago)
Author:
uli
Message:

Handle failed login (with tests).

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

Legend:

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

    r10394 r10397  
    138138        service = req.POST.get('service', req.GET.get('service', None))
    139139        service_field = ''
     140        msg = ''
    140141        username = req.POST.get('username', None)
    141142        password = req.POST.get('password', None)
     
    143144        if username and password and valid_lt:
    144145            # act as credentials acceptor
    145             cred_ok = self.auth.check_credentials(username, password)
     146            cred_ok, reason = self.auth.check_credentials(username, password)
    146147            if cred_ok:
    147148                if service is None:
     
    165166                    resp.text = html
    166167                    return resp
     168            else:
     169                # login failed
     170                msg = '<i>Login failed</i><br />Reason: %s' % reason
    167171        if service is not None:
    168172            service_field = (
     
    175179        html = html.replace('LT_VALUE', lt.ticket)
    176180        html = html.replace('SERVICE_FIELD_VALUE', service_field)
     181        html = html.replace('MSG_TEXT', msg)
    177182        return Response(html)
    178183
  • main/waeup.cas/trunk/waeup/cas/templates/login.html

    r10394 r10397  
    44  </head>
    55  <body>
     6    <div id="msg">
     7      MSG_TEXT
     8    </div>
    69    Please enter your credentials to authenticate:
    710    <form method="post">
  • main/waeup.cas/trunk/waeup/cas/tests/test_server.py

    r10394 r10397  
    184184        assert b'ticket=ST-' in resp.body
    185185
     186    def test_login_cred_acceptor_failed(self):
     187        # 2.2.4: failed login yields a message
     188        lt = create_login_ticket()
     189        self.raw_app.db.add(lt)
     190        lt_string = lt.ticket
     191        resp = self.app.post('/login', dict(
     192            username='bird', password='cat', lt=lt_string))
     193        assert resp.status == '200 OK'
     194        assert b'failed' in resp.body
     195
    186196
    187197class CASServerHelperTests(unittest.TestCase):
Note: See TracChangeset for help on using the changeset viewer.