mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix: Fix package info for 404 errors
We try to find packages when a user enters a URL like /somepkg or accidentally opens /somepkg.git in the browser. However, it currently also does this for URL's like /pkgbase/doesnotexist and falsely interprets "pkgbase" part as a package or pkgbase name. This in combination with a pkgbase that is named "pkgbase" generates some misleading 404 message for URL's like /pkgbase/doesnotexist. That being said, we should probably add pkgbase to the blacklist check as well (we do this for pkgname already) and add things like "pkgbase" to the blacklist -> Will be picked up in another commit. Signed-off-by: moson <moson@archlinux.org>
This commit is contained in:
parent
319c565cb9
commit
057685f304
2 changed files with 16 additions and 2 deletions
|
@ -212,7 +212,7 @@ async def http_exception_handler(request: Request, exc: HTTPException) -> Respon
|
||||||
if exc.status_code == http.HTTPStatus.NOT_FOUND:
|
if exc.status_code == http.HTTPStatus.NOT_FOUND:
|
||||||
tokens = request.url.path.split("/")
|
tokens = request.url.path.split("/")
|
||||||
matches = re.match("^([a-z0-9][a-z0-9.+_-]*?)(\\.git)?$", tokens[1])
|
matches = re.match("^([a-z0-9][a-z0-9.+_-]*?)(\\.git)?$", tokens[1])
|
||||||
if matches:
|
if matches and len(tokens) == 2:
|
||||||
try:
|
try:
|
||||||
pkgbase = get_pkg_or_base(matches.group(1))
|
pkgbase = get_pkg_or_base(matches.group(1))
|
||||||
context = pkgbaseutil.make_context(request, pkgbase)
|
context = pkgbaseutil.make_context(request, pkgbase)
|
||||||
|
|
|
@ -199,7 +199,7 @@ def test_404_with_valid_pkgbase(client: TestClient, pkgbase: PackageBase):
|
||||||
assert "To clone the Git repository" in body
|
assert "To clone the Git repository" in body
|
||||||
|
|
||||||
|
|
||||||
def test_404(client: TestClient):
|
def test_404(client: TestClient, user):
|
||||||
"""Test HTTPException with status_code == 404 without a valid pkgbase."""
|
"""Test HTTPException with status_code == 404 without a valid pkgbase."""
|
||||||
with client as request:
|
with client as request:
|
||||||
response = request.get("/nonexistentroute")
|
response = request.get("/nonexistentroute")
|
||||||
|
@ -210,6 +210,20 @@ def test_404(client: TestClient):
|
||||||
# No `pkgbase` is provided here; we don't see the extra info.
|
# No `pkgbase` is provided here; we don't see the extra info.
|
||||||
assert "To clone the Git repository" not in body
|
assert "To clone the Git repository" not in body
|
||||||
|
|
||||||
|
# Create a pkgbase named "pkgbase"
|
||||||
|
# Should NOT return extra info for "pkgbase"
|
||||||
|
with db.begin():
|
||||||
|
db.create(PackageBase, Name="pkgbase", Maintainer=user)
|
||||||
|
|
||||||
|
with client as request:
|
||||||
|
response = request.get("/pkgbase/doesnotexist")
|
||||||
|
assert response.status_code == int(HTTPStatus.NOT_FOUND)
|
||||||
|
|
||||||
|
body = response.text
|
||||||
|
assert "404 - Page Not Found" in body
|
||||||
|
# No `pkgbase` is provided here; we don't see the extra info.
|
||||||
|
assert "To clone the Git repository" not in body
|
||||||
|
|
||||||
|
|
||||||
def test_503(client: TestClient):
|
def test_503(client: TestClient):
|
||||||
"""Test HTTPException with status_code == 503 (Service Unavailable)."""
|
"""Test HTTPException with status_code == 503 (Service Unavailable)."""
|
||||||
|
|
Loading…
Add table
Reference in a new issue