From abbd16db400a84e858a04cbdafabd3448460242b Mon Sep 17 00:00:00 2001 From: Greg Kempe Date: Tue, 7 Dec 2021 16:39:44 +0200 Subject: [PATCH] Handle django 2.2.25 --- indigo_app/tests/test_authed_urls.py | 82 +++++++++++++++------------- 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/indigo_app/tests/test_authed_urls.py b/indigo_app/tests/test_authed_urls.py index 147c786b17..e796291231 100644 --- a/indigo_app/tests/test_authed_urls.py +++ b/indigo_app/tests/test_authed_urls.py @@ -1,3 +1,6 @@ +import re + +import django from django.urls import get_resolver from django.test import testcases @@ -5,45 +8,50 @@ class AuthedUrlsTest(testcases.TestCase): - non_authed_urls = """ -robots\.txt$ -help$ -terms$ -$ - -accounts/social/connections/$ -accounts/social/signup/$ -accounts/social/login/error/$ -accounts/social/login/cancelled/$ -accounts/password/reset/key/done/$ -accounts/password/reset/key/(?P[0-9A-Za-z]+)-(?P.+)/$ -accounts/password/reset/done/$ -accounts/password/reset/$ -accounts/confirm-email/(?P[-:\w]+)/$ -accounts/confirm\-email/$ -accounts/email/$ -accounts/inactive/$ -accounts/password/set/$ -accounts/password/change/$ -accounts/logout/$ -accounts/login/$ -accounts/signup/$ - -resolver/(?P.+)$ -resolver/((?P[\w,.-]+)/)?resolve(?P/.*)$ - -api/$ -api/documents/(?P[0-9]+)/analysis/mark\-up\-italics$ -api/documents/(?P[0-9]+)/analysis/link\-references$ -api/documents/(?P[0-9]+)/analysis/link\-terms$ -api/documents/(?P[0-9]+)/static/(?P.+)$ -api/documents/(?P[0-9]+)/render/coverpage$ -api/documents/(?P[0-9]+)/parse$ -api/documents/(?P[0-9]+)/diff$ -api/documents/(?P[0-9]+)/media/(?P.*)$ -api/publications/(?P[a-z]{2})(-(?P[^/]+))?/find$ + non_authed_urls = r""" +robots\.txt\Z +help\Z +terms\Z +\Z + +accounts/social/connections/\Z +accounts/social/signup/\Z +accounts/social/login/error/\Z +accounts/social/login/cancelled/\Z +accounts/password/reset/key/done/\Z +accounts/password/reset/key/(?P[0-9A-Za-z]+)-(?P.+)/\Z +accounts/password/reset/done/\Z +accounts/password/reset/\Z +accounts/confirm-email/(?P[-:\w]+)/\Z +accounts/confirm\-email/\Z +accounts/email/\Z +accounts/inactive/\Z +accounts/password/set/\Z +accounts/password/change/\Z +accounts/logout/\Z +accounts/login/\Z +accounts/signup/\Z + +resolver/(?P.+)\Z +resolver/((?P[\w,.-]+)/)?resolve(?P/.*)\Z + +api/\Z +api/documents/(?P[0-9]+)/analysis/mark\-up\-italics\Z +api/documents/(?P[0-9]+)/analysis/link\-references\Z +api/documents/(?P[0-9]+)/analysis/link\-terms\Z +api/documents/(?P[0-9]+)/static/(?P.+)\Z +api/documents/(?P[0-9]+)/render/coverpage\Z +api/documents/(?P[0-9]+)/parse\Z +api/documents/(?P[0-9]+)/diff\Z +api/documents/(?P[0-9]+)/media/(?P.*)\Z +api/publications/(?P[a-z]{2})(-(?P[^/]+))?/find\Z """.split() + def setUp(self): + # version 2.2.25 changed the regexes for URLs, so account for the old format + if django.VERSION < (2, 2, 25): + self.non_authed_urls = [re.sub(r'\\Z$', '$', x) for x in self.non_authed_urls] + def test_urls_have_auth(self): """ This test checks that all URLs, except those explicitly whitelisted, inherit from the AbstractAuthedIndigoView class, which requires authentication.