mirror of
https://github.com/wallabag/docker
synced 2025-12-13 09:46:27 +00:00
tests: some pep8 and real failing if csrf dont match
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import pytest
|
||||
import re
|
||||
import requests
|
||||
|
||||
@@ -5,7 +6,7 @@ import requests
|
||||
URL = 'http://127.0.0.1:80'
|
||||
|
||||
|
||||
def test_login_page():
|
||||
def test_accessing_login_page():
|
||||
r = requests.get(URL, allow_redirects=True)
|
||||
|
||||
assert r.status_code == 200
|
||||
@@ -15,25 +16,30 @@ def test_login_page():
|
||||
assert 'Username' in r.text
|
||||
|
||||
|
||||
def test_login():
|
||||
csrf = ''
|
||||
def test_logging_in():
|
||||
client = requests.session()
|
||||
r = client.get(URL, allow_redirects=True)
|
||||
jar = r.cookies
|
||||
csrf_match = re.search('<input type="hidden" name="_csrf_token" value="(.*)" />', r.text)
|
||||
|
||||
# get csrf token
|
||||
csrf_match = re.search(
|
||||
'<input type="hidden" name="_csrf_token" value="(.*)" />',
|
||||
r.text
|
||||
)
|
||||
|
||||
if csrf_match:
|
||||
csrf = csrf_match.group(1)
|
||||
else:
|
||||
print("csrf not matched")
|
||||
# if there is no csrf token the test will fail
|
||||
pytest.fail('csrf not matched')
|
||||
|
||||
data = {
|
||||
'_username': 'wallabag',
|
||||
'_password': 'wallabag',
|
||||
'_csrf_token' : csrf
|
||||
'_csrf_token': csrf
|
||||
}
|
||||
|
||||
r = client.post(URL + '/login_check', cookies=jar, data=data)
|
||||
print(r.text)
|
||||
assert r.status_code == 200
|
||||
assert '/unread/list' in r.text
|
||||
assert '/starred/list' in r.text
|
||||
|
||||
Reference in New Issue
Block a user