vigiboard / vigiboard / tests / functional / test_authentication.py @ cf3c2494
History | View | Annotate | Download (2.35 KB)
1 | 57f7cb3f | Gabriel DE PERTHUIS | # -*- 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 | b4adb15b | Francois POIROTTE |
|
17 | 57f7cb3f | Gabriel DE PERTHUIS | 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 | b4adb15b | Francois POIROTTE |
|
21 | 57f7cb3f | Gabriel DE PERTHUIS | As the settings for those plugins change, or the plugins are replaced,
|
22 | these tests should be updated.
|
||
23 | b4adb15b | Francois POIROTTE |
|
24 | 57f7cb3f | Gabriel DE PERTHUIS | """
|
25 | b4adb15b | Francois POIROTTE | |
26 | 57f7cb3f | Gabriel DE PERTHUIS | application_under_test = 'main'
|
27 | |||
28 | def test_voluntary_login(self): |
||
29 | """Voluntary logins must work correctly"""
|
||
30 | # Going to the login form voluntarily:
|
||
31 | resp = self.app.get('/login', status=200) |
||
32 | form = resp.form |
||
33 | # Submitting the login form:
|
||
34 | form['login'] = u'manager' |
||
35 | e2ae110e | Francois POIROTTE | form['password'] = u'managepass' |
36 | 57f7cb3f | Gabriel DE PERTHUIS | post_login = form.submit(status=302)
|
37 | # Being redirected to the home page:
|
||
38 | b4adb15b | Francois POIROTTE | assert post_login.location.startswith('/post_login') |
39 | 57f7cb3f | Gabriel DE PERTHUIS | home_page = post_login.follow(status=302)
|
40 | assert 'authtkt' in home_page.request.cookies, \ |
||
41 | 'Session cookie was not defined: %s' % home_page.request.cookies
|
||
42 | ecf7726f | Francois POIROTTE | assert home_page.location == 'http://localhost/' |
43 | 57f7cb3f | Gabriel DE PERTHUIS | |
44 | def test_logout(self): |
||
45 | """Logouts must work correctly"""
|
||
46 | # Logging in voluntarily the quick way:
|
||
47 | e2ae110e | Francois POIROTTE | resp = self.app.get('/login_handler?login=manager&password=managepass', |
48 | 57f7cb3f | Gabriel DE PERTHUIS | status=302)
|
49 | resp = resp.follow(status=302)
|
||
50 | assert 'authtkt' in resp.request.cookies, \ |
||
51 | 'Session cookie was not defined: %s' % resp.request.cookies
|
||
52 | # Logging out:
|
||
53 | resp = self.app.get('/logout_handler', status=302) |
||
54 | b4adb15b | Francois POIROTTE | assert resp.location.startswith('/post_logout') |
55 | 57f7cb3f | Gabriel DE PERTHUIS | # Finally, redirected to the home page:
|
56 | home_page = resp.follow(status=302)
|
||
57 | ecf7726f | Francois POIROTTE | assert home_page.request.cookies.get('authtkt') == '' \ |
58 | or home_page.request.cookies.get('authtkt') == 'INVALID', \ |
||
59 | 57f7cb3f | Gabriel DE PERTHUIS | 'Session cookie was not deleted: %s' % home_page.request.cookies
|
60 | ecf7726f | Francois POIROTTE | assert home_page.location == 'http://localhost/', home_page.location |