Skip to content
Snippets Groups Projects
Verified Commit 057685f3 authored by Mario Oenning's avatar Mario Oenning
Browse files

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: default avatarmoson <moson@archlinux.org>
parent 319c565c
No related branches found
Tags v6.0.27
1 merge request!793Fix package info for 404 errors & blacklisting pkgbase names
......@@ -212,7 +212,7 @@ async def http_exception_handler(request: Request, exc: HTTPException) -> Respon
if exc.status_code == http.HTTPStatus.NOT_FOUND:
tokens = request.url.path.split("/")
matches = re.match("^([a-z0-9][a-z0-9.+_-]*?)(\\.git)?$", tokens[1])
if matches:
if matches and len(tokens) == 2:
try:
pkgbase = get_pkg_or_base(matches.group(1))
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
def test_404(client: TestClient):
def test_404(client: TestClient, user):
"""Test HTTPException with status_code == 404 without a valid pkgbase."""
with client as request:
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.
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):
"""Test HTTPException with status_code == 503 (Service Unavailable)."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment