mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
style: Run pre-commit
This commit is contained in:
parent
b47882b114
commit
9c6c13b78a
235 changed files with 7180 additions and 5628 deletions
|
@ -1,11 +1,9 @@
|
|||
import re
|
||||
import urllib.parse
|
||||
|
||||
from http import HTTPStatus
|
||||
|
||||
import lxml.etree
|
||||
import pytest
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from aurweb import db
|
||||
|
@ -28,21 +26,26 @@ def client() -> TestClient:
|
|||
@pytest.fixture
|
||||
def user() -> User:
|
||||
with db.begin():
|
||||
user = db.create(User, Username="test", Email="test@example.org",
|
||||
RealName="Test User", Passwd="testPassword",
|
||||
AccountTypeID=USER_ID)
|
||||
user = db.create(
|
||||
User,
|
||||
Username="test",
|
||||
Email="test@example.org",
|
||||
RealName="Test User",
|
||||
Passwd="testPassword",
|
||||
AccountTypeID=USER_ID,
|
||||
)
|
||||
yield user
|
||||
|
||||
|
||||
def test_index(client: TestClient):
|
||||
""" Test the index route at '/'. """
|
||||
"""Test the index route at '/'."""
|
||||
with client as req:
|
||||
response = req.get("/")
|
||||
assert response.status_code == int(HTTPStatus.OK)
|
||||
|
||||
|
||||
def test_index_security_headers(client: TestClient):
|
||||
""" Check for the existence of CSP, XCTO, XFO and RP security headers.
|
||||
"""Check for the existence of CSP, XCTO, XFO and RP security headers.
|
||||
|
||||
CSP: Content-Security-Policy
|
||||
XCTO: X-Content-Type-Options
|
||||
|
@ -60,7 +63,7 @@ def test_index_security_headers(client: TestClient):
|
|||
|
||||
|
||||
def test_favicon(client: TestClient):
|
||||
""" Test the favicon route at '/favicon.ico'. """
|
||||
"""Test the favicon route at '/favicon.ico'."""
|
||||
with client as request:
|
||||
response1 = request.get("/static/images/favicon.ico")
|
||||
response2 = request.get("/favicon.ico")
|
||||
|
@ -69,52 +72,38 @@ def test_favicon(client: TestClient):
|
|||
|
||||
|
||||
def test_language(client: TestClient):
|
||||
""" Test the language post route as a guest user. """
|
||||
post_data = {
|
||||
"set_lang": "de",
|
||||
"next": "/"
|
||||
}
|
||||
"""Test the language post route as a guest user."""
|
||||
post_data = {"set_lang": "de", "next": "/"}
|
||||
with client as req:
|
||||
response = req.post("/language", data=post_data)
|
||||
assert response.status_code == int(HTTPStatus.SEE_OTHER)
|
||||
|
||||
|
||||
def test_language_invalid_next(client: TestClient):
|
||||
""" Test an invalid next route at '/language'. """
|
||||
post_data = {
|
||||
"set_lang": "de",
|
||||
"next": "https://evil.net"
|
||||
}
|
||||
"""Test an invalid next route at '/language'."""
|
||||
post_data = {"set_lang": "de", "next": "https://evil.net"}
|
||||
with client as req:
|
||||
response = req.post("/language", data=post_data)
|
||||
assert response.status_code == int(HTTPStatus.BAD_REQUEST)
|
||||
|
||||
|
||||
def test_user_language(client: TestClient, user: User):
|
||||
""" Test the language post route as an authenticated user. """
|
||||
post_data = {
|
||||
"set_lang": "de",
|
||||
"next": "/"
|
||||
}
|
||||
"""Test the language post route as an authenticated user."""
|
||||
post_data = {"set_lang": "de", "next": "/"}
|
||||
|
||||
sid = user.login(Request(), "testPassword")
|
||||
assert sid is not None
|
||||
|
||||
with client as req:
|
||||
response = req.post("/language", data=post_data,
|
||||
cookies={"AURSID": sid})
|
||||
response = req.post("/language", data=post_data, cookies={"AURSID": sid})
|
||||
assert response.status_code == int(HTTPStatus.SEE_OTHER)
|
||||
assert user.LangPreference == "de"
|
||||
|
||||
|
||||
def test_language_query_params(client: TestClient):
|
||||
""" Test the language post route with query params. """
|
||||
"""Test the language post route with query params."""
|
||||
next = urllib.parse.quote_plus("/")
|
||||
post_data = {
|
||||
"set_lang": "de",
|
||||
"next": "/",
|
||||
"q": f"next={next}"
|
||||
}
|
||||
post_data = {"set_lang": "de", "next": "/", "q": f"next={next}"}
|
||||
q = post_data.get("q")
|
||||
with client as req:
|
||||
response = req.post("/language", data=post_data)
|
||||
|
@ -154,9 +143,13 @@ def test_nonce_csp(client: TestClient):
|
|||
|
||||
def test_id_redirect(client: TestClient):
|
||||
with client as request:
|
||||
response = request.get("/", params={
|
||||
"id": "test", # This param will be rewritten into Location.
|
||||
"key": "value", # Test that this param persists.
|
||||
"key2": "value2" # And this one.
|
||||
}, allow_redirects=False)
|
||||
response = request.get(
|
||||
"/",
|
||||
params={
|
||||
"id": "test", # This param will be rewritten into Location.
|
||||
"key": "value", # Test that this param persists.
|
||||
"key2": "value2", # And this one.
|
||||
},
|
||||
allow_redirects=False,
|
||||
)
|
||||
assert response.headers.get("location") == "/test?key=value&key2=value2"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue