vigiboard / vigiboard / tests / functional / test_authentication.py @ c94dc931
History | View | Annotate | Download (2.75 KB)
1 | 57f7cb3f | Gabriel DE PERTHUIS | # -*- coding: utf-8 -*-
|
---|---|---|---|
2 | c94dc931 | Francois POIROTTE | # Copyright (C) 2006-2020 CS-SI
|
3 | b373a5de | Aurelien BOMPARD | # License: GNU GPL v2 <http://www.gnu.org/licenses/gpl-2.0.html>
|
4 | |||
5 | 57f7cb3f | Gabriel DE PERTHUIS | """
|
6 | Integration tests for the :mod:`repoze.who`-powered authentication sub-system.
|
||
7 |
|
||
8 | As vigiboard grows and the authentication method changes, only these tests
|
||
9 | should be updated.
|
||
10 |
|
||
11 | """
|
||
12 | |||
13 | from vigiboard.tests import TestController |
||
14 | |||
15 | |||
16 | class TestAuthentication(TestController): |
||
17 | """
|
||
18 | Tests for the default authentication setup.
|
||
19 | b4adb15b | Francois POIROTTE |
|
20 | 57f7cb3f | Gabriel DE PERTHUIS | By default in TurboGears 2, :mod:`repoze.who` is configured with the same
|
21 | plugins specified by repoze.what-quickstart (which are listed in
|
||
22 | http://code.gustavonarea.net/repoze.what-quickstart/#repoze.what.plugins.quickstart.setup_sql_auth).
|
||
23 | b4adb15b | Francois POIROTTE |
|
24 | 57f7cb3f | Gabriel DE PERTHUIS | As the settings for those plugins change, or the plugins are replaced,
|
25 | these tests should be updated.
|
||
26 | b4adb15b | Francois POIROTTE |
|
27 | 57f7cb3f | Gabriel DE PERTHUIS | """
|
28 | b4adb15b | Francois POIROTTE | |
29 | 57f7cb3f | Gabriel DE PERTHUIS | application_under_test = 'main'
|
30 | |||
31 | def test_voluntary_login(self): |
||
32 | """Voluntary logins must work correctly"""
|
||
33 | # Going to the login form voluntarily:
|
||
34 | resp = self.app.get('/login', status=200) |
||
35 | form = resp.form |
||
36 | # Submitting the login form:
|
||
37 | form['login'] = u'manager' |
||
38 | 7587a4de | Aurelien BOMPARD | form['password'] = u'iddad' |
39 | 57f7cb3f | Gabriel DE PERTHUIS | post_login = form.submit(status=302)
|
40 | # Being redirected to the home page:
|
||
41 | bc8c7a50 | Francois POIROTTE | assert post_login.location.startswith('/post_login') or \ |
42 | post_login.location.startswith('http://localhost/post_login'), \
|
||
43 | "Result: %s" % post_login.location
|
||
44 | 57f7cb3f | Gabriel DE PERTHUIS | home_page = post_login.follow(status=302)
|
45 | assert 'authtkt' in home_page.request.cookies, \ |
||
46 | 'Session cookie was not defined: %s' % home_page.request.cookies
|
||
47 | ecf7726f | Francois POIROTTE | assert home_page.location == 'http://localhost/' |
48 | 57f7cb3f | Gabriel DE PERTHUIS | |
49 | def test_logout(self): |
||
50 | """Logouts must work correctly"""
|
||
51 | # Logging in voluntarily the quick way:
|
||
52 | 7587a4de | Aurelien BOMPARD | resp = self.app.get('/login_handler?login=manager&password=iddad', |
53 | 57f7cb3f | Gabriel DE PERTHUIS | status=302)
|
54 | resp = resp.follow(status=302)
|
||
55 | assert 'authtkt' in resp.request.cookies, \ |
||
56 | 'Session cookie was not defined: %s' % resp.request.cookies
|
||
57 | # Logging out:
|
||
58 | 88c74e19 | Francois POIROTTE | resp = self.app.get('/logout_handler', status=302, |
59 | extra_environ={'REMOTE_ADDR': '127.0.0.1'}) |
||
60 | bc8c7a50 | Francois POIROTTE | assert resp.location.startswith('/post_logout') or \ |
61 | resp.location.startswith('http://localhost/post_logout'), \
|
||
62 | "Result: %s" % resp.location
|
||
63 | 57f7cb3f | Gabriel DE PERTHUIS | # Finally, redirected to the home page:
|
64 | home_page = resp.follow(status=302)
|
||
65 | ecf7726f | Francois POIROTTE | assert home_page.request.cookies.get('authtkt') == '' \ |
66 | or home_page.request.cookies.get('authtkt') == 'INVALID', \ |
||
67 | 57f7cb3f | Gabriel DE PERTHUIS | 'Session cookie was not deleted: %s' % home_page.request.cookies
|
68 | ecf7726f | Francois POIROTTE | assert home_page.location == 'http://localhost/', home_page.location |