Repository: mdn/kuma

Issue:
We can remove django-waffle now
Since https://github.com/mdn/kuma/pull/7932 landed I don't think we're ever using it anywhere for anything. 


Discussion:

Resolving patch:
diff --git a/kuma/core/middleware.py b/kuma/core/middleware.py
deleted file mode 100644
--- a/kuma/core/middleware.py
+++ /dev/null
@@ -1,66 +0,0 @@
-from django.conf import settings
-from django.contrib.sessions.middleware import SessionMiddleware
-from waffle.middleware import WaffleMiddleware
-
-
-class MiddlewareBase(object):
-    def __init__(self, get_response):
-        self.get_response = get_response
-
-
-class SetRemoteAddrFromForwardedFor(MiddlewareBase):
-    """
-    Middleware that sets REMOTE_ADDR based on HTTP_X_FORWARDED_FOR, if the
-    latter is set. This is useful if you're sitting behind a reverse proxy that
-    causes each request's REMOTE_ADDR to be set to 127.0.0.1.
-    """
-
-    def __call__(self, request):
-        try:
-            forwarded_for = request.META["HTTP_X_FORWARDED_FOR"]
-        except KeyError:
-            pass
-        else:
-            # HTTP_X_FORWARDED_FOR can be a comma-separated list of IPs.
-            # The client's IP will be the first one.
-            forwarded_for = forwarded_for.split(",")[0].strip()
-            request.META["REMOTE_ADDR"] = forwarded_for
-
-        return self.get_response(request)
-
-
-class ForceAnonymousSessionMiddleware(SessionMiddleware):
-    def process_request(self, request):
-        """
-        Always create an anonymous session.
-        """
-        request.session = self.SessionStore(None)
-
-    def process_response(self, request, response):
-        """
-        Override the base-class method to ensure we do nothing.
-        """
-        return response
-
-
-class WaffleWithCookieDomainMiddleware(WaffleMiddleware):
-    """
-    The waffle.middleware.WaffleMiddleware class does not yet provide a way
-    way to configure the domain of the cookies it adds to the response. This
-    class is a simple wrapper around the waffle.middleware.WaffleMiddleware
-    class, and it simply sets the domain of all cookies added to the response
-    by waffle.middleware.WaffleMiddleware. The domain is set to the value
-    configured in settings.WAFFLE_COOKIE_DOMAIN.
-    """
-
-    def process_response(self, request, response):
-        keys_before = frozenset(response.cookies.keys())
-        try:
-            response = super(WaffleWithCookieDomainMiddleware, self).process_response(
-                request, response
-            )
-        finally:
-            keys_after = frozenset(response.cookies.keys())
-            for key in keys_after - keys_before:
-                response.cookies[key]["domain"] = settings.WAFFLE_COOKIE_DOMAIN
-        return response
diff --git a/kuma/settings/common.py b/kuma/settings/common.py
--- a/kuma/settings/common.py
+++ b/kuma/settings/common.py
@@ -261,45 +261,6 @@ def _get_locales():
 ]
 
 
-# # TODO: Figure out why changing the order of apps (for example, moving taggit
-# # higher in the list) breaks tests.
-# INSTALLED_APPS = (
-#     # django
-#     "django.contrib.auth",
-#     "django.contrib.contenttypes",
-#     "django.contrib.sessions",
-#     "django.contrib.sites",
-#     "django.contrib.admin",
-#     "django.contrib.messages",
-#     "django.contrib.staticfiles",
-#     # MDN
-#     "kuma.core.apps.CoreConfig",
-#     "kuma.landing",
-#     "kuma.search.apps.SearchConfig",
-#     "kuma.users.apps.UserConfig",
-#     "kuma.wiki.apps.WikiConfig",
-#     "kuma.api.apps.APIConfig",
-#     "kuma.attachments.apps.AttachmentsConfig",
-#     "allauth",
-#     "allauth.account",
-#     "allauth.socialaccount",
-#     "kuma.users.providers.github",
-#     "kuma.users.providers.google",
-#     "kuma.plus.apps.PlusConfig",
-#     # util
-#     "django_jinja",
-#     "puente",
-#     "waffle",
-#     "kuma.authkeys",
-#     "taggit",
-#     "django_extensions",
-#     "statici18n",
-#     "rest_framework",
-#     "rest_framework.authtoken",
-#     "django_mysql",
-# )
-
-
 TEMPLATES = [
     {
         "BACKEND": "django.template.backends.django.DjangoTemplates",
@@ -322,12 +283,6 @@ def _get_locales():
 SESSION_COOKIE_HTTPONLY = True
 SESSION_COOKIE_AGE = config("SESSION_COOKIE_AGE", default=60 * 60 * 24 * 365, cast=int)
 
-# WAFFLE_SECURE = config("WAFFLE_COOKIE_SECURE", default=True, cast=bool)
-# # This is a setting unique to Kuma which specifies the domain
-# # that will be used for all of the waffle cookies. It is used by
-# # kuma.core.middleware.WaffleWithCookieDomainMiddleware.
-# WAFFLE_COOKIE_DOMAIN = DOMAIN
-
 # bug 856061
 ALLOWED_HOSTS = config(
     "ALLOWED_HOSTS",


Test patch:
diff --git a/kuma/core/tests/test_middleware.py b/kuma/core/tests/test_middleware.py
deleted file mode 100644
--- a/kuma/core/tests/test_middleware.py
+++ /dev/null
@@ -1,56 +0,0 @@
-from unittest.mock import MagicMock
-
-import pytest
-from django.http import HttpResponse
-from django.test import RequestFactory
-
-from ..middleware import (
-    ForceAnonymousSessionMiddleware,
-    SetRemoteAddrFromForwardedFor,
-    WaffleWithCookieDomainMiddleware,
-)
-
-
-@pytest.mark.parametrize(
-    "forwarded_for,remote_addr",
-    (("1.1.1.1", "1.1.1.1"), ("2.2.2.2", "2.2.2.2"), ("3.3.3.3, 4.4.4.4", "3.3.3.3")),
-)
-def test_set_remote_addr_from_forwarded_for(rf, forwarded_for, remote_addr):
-    """SetRemoteAddrFromForwardedFor parses the X-Forwarded-For Header."""
-    rf = RequestFactory()
-    middleware = SetRemoteAddrFromForwardedFor(lambda req: None)
-    request = rf.get("/", HTTP_X_FORWARDED_FOR=forwarded_for)
-    middleware(request)
-    assert request.META["REMOTE_ADDR"] == remote_addr
-
-
-def test_force_anonymous_session_middleware(rf, settings):
-    request = rf.get("/foo")
-    request.COOKIES[settings.SESSION_COOKIE_NAME] = "totallyfake"
-
-    mock_response = MagicMock()
-    middleware = ForceAnonymousSessionMiddleware(lambda req: mock_response)
-    response = middleware(request)
-
-    assert request.session
-    assert request.session.session_key is None
-    assert not response.method_calls
-
-
-def test_waffle_cookie_domain_middleware(rf, settings):
-    settings.WAFFLE_COOKIE = "dwf_%s"
-    settings.WAFFLE_COOKIE_DOMAIN = "mdn.dev"
-    resp = HttpResponse()
-    resp.set_cookie("some_key", "some_value", domain=None)
-    resp.set_cookie("another_key", "another_value", domain="another.domain")
-    middleware = WaffleWithCookieDomainMiddleware(lambda req: resp)
-    request = rf.get("/foo")
-    request.waffles = {
-        "contrib_beta": (True, False),
-        "developer_needs": (True, False),
-    }
-    response = middleware(request)
-    assert response.cookies["some_key"]["domain"] == ""
-    assert response.cookies["another_key"]["domain"] == "another.domain"
-    assert response.cookies["dwf_contrib_beta"]["domain"] == "mdn.dev"
-    assert response.cookies["dwf_developer_needs"]["domain"] == "mdn.dev"