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

Add support for redirecting all of builders/* paths to a separate builders.m.o domain #17

Merged
merged 1 commit into from
Nov 27, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions birdbox/birdbox/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.conf import settings
from django.contrib import admin
from django.http import HttpResponse, HttpResponseForbidden
from django.urls import include, path
from django.urls import include, path, re_path
from django.utils.module_loading import import_string
from django.views.defaults import permission_denied

Expand All @@ -18,7 +18,7 @@
from wagtail.documents import urls as wagtaildocs_urls
from watchman import views as watchman_views

from common.views import csrf_failure, rate_limited
from common.views import csrf_failure, rate_limited, redirect_view
from microsite import urls as microsite_urls

handler500 = "common.views.server_error_view"
Expand All @@ -39,6 +39,7 @@ def handler403(request, exception=None):
path("documents/", include(wagtaildocs_urls)),
path("healthz/", watchman_views.ping, name="watchman.ping"),
path("readiness/", watchman_views.status, name="watchman.status"),
re_path("^builders/", redirect_view, {"dest": "https://builders.mozilla.org"}),
path("", include(microsite_urls)),
path(
"robots.txt",
Expand Down
29 changes: 29 additions & 0 deletions birdbox/common/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,32 @@ def test_robots_txt(client, engage_robots, expected_content):
@pytest.mark.django_db
def test_csrf_view_is_custom_one():
assert settings.CSRF_FAILURE_VIEW == "common.views.csrf_failure"


@pytest.mark.django_db
@pytest.mark.parametrize(
"path",
(
"/builders/",
"/builders/some/deeper/path/",
),
)
def test_builders_redirect(path, client):
resp = client.get(path, follow=False)
assert resp.headers["location"] == "https://builders.mozilla.org"


@pytest.mark.django_db
def test_builders_redirect_does_not_affect_anyting_else(client, minimal_site_with_blog):
from microsite.models import BlogPage

bp1, bp2_featured, bp3 = BlogPage.objects.live().all()

resp = client.get(bp1.url, follow=False)
assert resp.status_code == 200

resp = client.get(bp2_featured.url, follow=False)
assert resp.status_code == 200

resp = client.get(bp3.url, follow=False)
assert resp.status_code == 200
5 changes: 5 additions & 0 deletions birdbox/common/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

from django.http import HttpResponsePermanentRedirect
from django.shortcuts import render
from django.views.decorators.cache import never_cache

Expand All @@ -26,3 +27,7 @@ def rate_limited(request, exception):
response = render(request, "429.html", status=429)
response["Retry-After"] = "60"
return response


def redirect_view(request, **kwargs):
return HttpResponsePermanentRedirect(kwargs["dest"])