Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addons: return 404 when the project does not exist in the DB #11302

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions readthedocs/proxito/tests/test_hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
SINGLE_VERSION_WITHOUT_TRANSLATIONS,
)
from readthedocs.projects.models import AddonsConfig, Domain, Project
from readthedocs.proxito.views.hosting import ClientError


@override_settings(
Expand Down Expand Up @@ -666,6 +667,25 @@ def test_custom_domain_url(self):
== "https://docs.example.com/en/latest/"
)

def test_non_existent_project(self):
r = self.client.get(
reverse("proxito_readthedocs_docs_addons"),
{
"api-version": "1.0.0",
"client-version": "0.6.0",
"project-slug": "non-existent-project",
"version-slug": "latest",
},
secure=True,
headers={
"host": "project.dev.readthedocs.io",
},
)
assert r.status_code == 404
assert r.json() == {
"error": ClientError.PROJECT_NOT_FOUND,
}

def test_number_of_queries_project_version_slug(self):
# The number of queries should not increase too much, even if we change
# some of the responses from the API. This test will help us to
Expand Down
6 changes: 6 additions & 0 deletions readthedocs/proxito/views/hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ClientError(Exception):
"The version specified in 'api-version' is currently not supported"
)
VERSION_INVALID = "The version specifified in 'api-version' is invalid"
PROJECT_NOT_FOUND = "There is no project with the 'project-slug' requested"


class BaseReadTheDocsConfigJson(CDNCacheTagsMixin, APIView):
Expand Down Expand Up @@ -189,6 +190,11 @@ def get(self, request, format=None):
)

project, version, build, filename = self._resolve_resources()
if not project:
return JsonResponse(
{"error": ClientError.PROJECT_NOT_FOUND},
status=404,
)

data = AddonsResponse().get(
addons_version,
Expand Down