1
|
|
|
""" |
2
|
|
|
:Copyright: 2006-2020 Jochen Kupperschmidt |
3
|
|
|
:License: Modified BSD, see LICENSE for details. |
4
|
|
|
""" |
5
|
|
|
|
6
|
|
|
import pytest |
7
|
|
|
|
8
|
|
|
from byceps.services.authentication.password import service as password_service |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
@pytest.fixture |
12
|
|
|
def client(site_app, site): |
13
|
|
|
return site_app.test_client() |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
def test_login_form(client): |
17
|
|
|
response = client.get('/authentication/login') |
18
|
|
|
|
19
|
|
|
assert response.status_code == 200 |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
def test_login_succeeds(client, make_user): |
23
|
|
|
screen_name = 'LoginTester' |
24
|
|
|
password = 'correct horse battery staple' |
25
|
|
|
|
26
|
|
|
user = make_user(screen_name) |
27
|
|
|
password_service.create_password_hash(user.id, password) |
28
|
|
|
|
29
|
|
|
assert not list(client.cookie_jar) |
30
|
|
|
|
31
|
|
|
form_data = { |
32
|
|
|
'screen_name': screen_name, |
33
|
|
|
'password': password, |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
response = client.post('/authentication/login', data=form_data) |
37
|
|
|
assert response.status_code == 204 |
38
|
|
|
|
39
|
|
|
cookies = list(client.cookie_jar) |
40
|
|
|
assert len(cookies) == 1 |
41
|
|
|
|
42
|
|
|
cookie = cookies[0] |
43
|
|
|
assert cookie.domain == '.www.acmecon.test' |
44
|
|
|
assert cookie.name == 'session' |
45
|
|
|
assert cookie.secure |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
def test_login_fails(client): |
49
|
|
|
form_data = { |
50
|
|
|
'screen_name': 'TotallyUnknownUser', |
51
|
|
|
'password': 'TotallyWrongPassword', |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
response = client.post('/authentication/login', data=form_data) |
55
|
|
|
assert response.status_code == 403 |
56
|
|
|
|