Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

vigiboard / vigiboard / tests / functional / test_authentication.py @ d3c47597

History | View | Annotate | Download (3.65 KB)

1
# -*- coding: utf-8 -*-
2
"""
3
Integration tests for the :mod:`repoze.who`-powered authentication sub-system.
4

5
As vigiboard grows and the authentication method changes, only these tests
6
should be updated.
7

8
"""
9

    
10
from vigiboard.tests import TestController
11

    
12

    
13
class TestAuthentication(TestController):
14
    """
15
    Tests for the default authentication setup.
16
    
17
    By default in TurboGears 2, :mod:`repoze.who` is configured with the same
18
    plugins specified by repoze.what-quickstart (which are listed in
19
    http://code.gustavonarea.net/repoze.what-quickstart/#repoze.what.plugins.quickstart.setup_sql_auth).
20
    
21
    As the settings for those plugins change, or the plugins are replaced,
22
    these tests should be updated.
23
    
24
    """
25
    
26
    application_under_test = 'main'
27
    
28
    def test_forced_login(self):
29
        """
30
        Anonymous users must be redirected to the login form when authorization
31
        is denied.
32
        
33
        Next, upon successful login they should be redirected to the initially
34
        requested page.
35
        
36
        """
37
        # Requesting a protected area
38
        resp = self.app.get('/secc/', status=302)
39
        assert resp.location.startswith('http://localhost/login')
40
        # Getting the login form:
41
        resp = resp.follow(status=200)
42
        form = resp.form
43
        # Submitting the login form:
44
        form['login'] = u'manager'
45
        # XXX Use '42' as the password until remote password validation gets in.
46
        form['password'] = '42'
47
        post_login = form.submit(status=302)
48
        # Being redirected to the initially requested page:
49
        assert post_login.location.startswith('http://localhost/post_login')
50
        initial_page = post_login.follow(status=302)
51
        assert 'authtkt' in initial_page.request.cookies, \
52
               "Session cookie wasn't defined: %s" % initial_page.request.cookies
53
        assert initial_page.location.startswith('http://localhost/secc/'), \
54
               initial_page.location
55

    
56
    def test_voluntary_login(self):
57
        """Voluntary logins must work correctly"""
58
        # Going to the login form voluntarily:
59
        resp = self.app.get('/login', status=200)
60
        form = resp.form
61
        # Submitting the login form:
62
        form['login'] = u'manager'
63
        # XXX Use '42' as the password until remote password validation gets in.
64
        form['password'] = '42'
65
        post_login = form.submit(status=302)
66
        # Being redirected to the home page:
67
        assert post_login.location.startswith('http://localhost/post_login')
68
        home_page = post_login.follow(status=302)
69
        assert 'authtkt' in home_page.request.cookies, \
70
               'Session cookie was not defined: %s' % home_page.request.cookies
71
        assert home_page.location == 'http://localhost/'
72

    
73
    def test_logout(self):
74
        """Logouts must work correctly"""
75
        # Logging in voluntarily the quick way:
76
        # XXX Use '42' as the password until remote password validation gets in.
77
        resp = self.app.get('/login_handler?login=manager&password=42',
78
                            status=302)
79
        resp = resp.follow(status=302)
80
        assert 'authtkt' in resp.request.cookies, \
81
               'Session cookie was not defined: %s' % resp.request.cookies
82
        # Logging out:
83
        resp = self.app.get('/logout_handler', status=302)
84
        assert resp.location.startswith('http://localhost/post_logout')
85
        # Finally, redirected to the home page:
86
        home_page = resp.follow(status=302)
87
        assert home_page.request.cookies.get('authtkt') == '', \
88
               'Session cookie was not deleted: %s' % home_page.request.cookies
89
        assert home_page.location == 'http://localhost/', home_page.location