mirror of
https://github.com/wallabag/docker
synced 2025-12-13 17:56:31 +00:00
test_login: add login with csrf token and check if it was successful
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import re
|
||||
import requests
|
||||
|
||||
|
||||
@@ -15,12 +16,26 @@ def test_login_page():
|
||||
|
||||
|
||||
def test_login():
|
||||
with requests.Session() as s:
|
||||
csrf = ''
|
||||
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)
|
||||
if csrf_match:
|
||||
csrf = csrf_match.group(1)
|
||||
else:
|
||||
print("csrf not matched")
|
||||
|
||||
data = {
|
||||
'_username': 'wallabag',
|
||||
'_password': 'wallabag'
|
||||
}
|
||||
data = {
|
||||
'_username': 'wallabag',
|
||||
'_password': 'wallabag',
|
||||
'_csrf_token' : csrf
|
||||
}
|
||||
|
||||
r = s.post(URL + '/login_check', data=data)
|
||||
print(r.text)
|
||||
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
|
||||
assert '/archive/list' in r.text
|
||||
assert '/all/list' in r.text
|
||||
|
||||
Reference in New Issue
Block a user