1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
GET {{host}}
HTTP 200
# Try to access my movies, we're not authenticated and redirected to
# the login page.
GET {{host}}/my-movies
HTTP 302
[Asserts]
header "Location" == "/login"
# First, display the login page to capture
# the CSRF token (see https://en.wikipedia.org/wiki/Cross-site_request_forgery)
GET {{host}}/login
HTTP 200
[Captures]
csrf_token: xpath "string(//input[@name='_csrf']/@value)"
# Log in user, using the captured CSRF token. After
# successful login, we should be redirected to the favorites page.
POST {{host}}/login
[Form]
_csrf: {{csrf_token}}
username: bob78
password: 12345678
HTTP 302
[Asserts]
header "Location" == "/my-movies"
# Follow redirection and open favorites:
GET {{host}}/my-movies
HTTP 200
[Asserts]
body contains "Bob"
# Logout
GET {{host}}/logout
HTTP 302
[Asserts]
header "Location" == "/"
# Test that user is not logged
GET {{host}}/my-movies
HTTP 302
[Asserts]
header "Location" == "/login"
# If we try to log with a bad password, we should be redirected
# to the login page with a warning message. Instead of follow redirection
# by hand, we're using location option to follow redirection and go the the
# final page.
# Capture the CSRF token
GET {{host}}/login
HTTP 200
[Captures]
csrf_token: xpath "string(//input[@name='_csrf']/@value)"
# Log in with bad password.
POST {{host}}/login
[Options]
location: true
[Form]
_csrf: {{csrf_token}}
username: bob78
password: bad-password
HTTP 200
[Asserts]
url == "{{host}}/login"
xpath "string(//div[contains(@class, 'text-error')])" == "Authentication failed, please check your username and password"
# Check that CSRF token is mandatory:
POST {{host}}/login
[Form]
username: bob78
password: 12345678
HTTP 403