mirror of
https://github.com/wallabag/docker
synced 2025-12-19 04:31:51 +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 re
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
@@ -5,7 +6,7 @@ import requests
|
|||||||
URL = 'http://127.0.0.1:80'
|
URL = 'http://127.0.0.1:80'
|
||||||
|
|
||||||
|
|
||||||
def test_login_page():
|
def test_accessing_login_page():
|
||||||
r = requests.get(URL, allow_redirects=True)
|
r = requests.get(URL, allow_redirects=True)
|
||||||
|
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
@@ -15,16 +16,22 @@ def test_login_page():
|
|||||||
assert 'Username' in r.text
|
assert 'Username' in r.text
|
||||||
|
|
||||||
|
|
||||||
def test_login():
|
def test_logging_in():
|
||||||
csrf = ''
|
|
||||||
client = requests.session()
|
client = requests.session()
|
||||||
r = client.get(URL, allow_redirects=True)
|
r = client.get(URL, allow_redirects=True)
|
||||||
jar = r.cookies
|
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:
|
if csrf_match:
|
||||||
csrf = csrf_match.group(1)
|
csrf = csrf_match.group(1)
|
||||||
else:
|
else:
|
||||||
print("csrf not matched")
|
# if there is no csrf token the test will fail
|
||||||
|
pytest.fail('csrf not matched')
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'_username': 'wallabag',
|
'_username': 'wallabag',
|
||||||
@@ -33,7 +40,6 @@ def test_login():
|
|||||||
}
|
}
|
||||||
|
|
||||||
r = client.post(URL + '/login_check', cookies=jar, data=data)
|
r = client.post(URL + '/login_check', cookies=jar, data=data)
|
||||||
print(r.text)
|
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert '/unread/list' in r.text
|
assert '/unread/list' in r.text
|
||||||
assert '/starred/list' in r.text
|
assert '/starred/list' in r.text
|
||||||
|
|||||||
Reference in New Issue
Block a user