Skip to content

Commit

Permalink
Merge pull request #17 from mozmeao/add-builders-redirect
Browse files Browse the repository at this point in the history
Add support for redirecting all of builders/* paths to a separate builders.m.o domain
  • Loading branch information
stevejalim authored Nov 27, 2024
2 parents eeba261 + 5c32164 commit 1eedab4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
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"])

0 comments on commit 1eedab4

Please sign in to comment.