implement SCL3 httpd redirects in Django#4220
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4220 +/- ##
==========================================
+ Coverage 86.31% 86.31% +<.01%
==========================================
Files 147 148 +1
Lines 9103 9105 +2
Branches 1222 1222
==========================================
+ Hits 7857 7859 +2
Misses 1005 1005
Partials 241 241
Continue to review full report at Codecov.
|
jwhitlock
left a comment
There was a problem hiding this comment.
I think we need the base_url fixture, so that you can verify that the new Kuma code matches the behavior of production. The [url12] test of /media/uploads/demos/foobar looks to be a real bug.
As for the foo//bar tests. 😕 Maybe spend 15 minutes trying to fix localhost, and then comment out those tests for now or mark them as XFAIL if that's possible. We may need WebOps to sync an Apache config change from prod to staging.
tests/redirects/test_redirects.py
Outdated
| @pytest.mark.nondestructive | ||
| @pytest.mark.parametrize('url', REDIRECT_URLS) | ||
| def test_redirects(url): | ||
| url['base_url'] = "https://developer.mozilla.org" |
There was a problem hiding this comment.
This should match bedrock, using the base_url py.test fixture:
def test_redirects(url, base_url):
url['base_url'] = base_url
You can then test it against staging:
py.test tests/redirects -vv --base-url https://developer.allizom.org --pdb
or the local Docker:
py.test tests/redirects -vv --base-url http://localhost:8000 --pdb
The --pdb drops you into the Python debugger, where you can print out the expected and actual values ("q" and Enter to quit). If we were on py.test 3.x, the assets may be more useful (see PR #4210), but w/ py.test 2.x, you have to do your own test debugging.
|
|
||
| url_test("/media/uploads/demos/foobar123", | ||
| "/docs/Web/Demos_of_open_web_technologies/", | ||
| status_code=requests.codes.found), |
There was a problem hiding this comment.
This fails against --base-url=http://localhost:8000. It expects a 302 Found, but gets a 301 Moved Permanently.
tests/redirects/map_301.py
Outdated
| "/docs/Web/Demos_of_open_web_technologies/", | ||
| status_code=requests.codes.found), | ||
|
|
||
| url_test("/foo//bar", "/foo_bar"), |
There was a problem hiding this comment.
This fails against --base_url=localhost:8000, getting http://localhost:8000/foo//foo_bar.
It also fails against --base_url=https://developer.allizom.org, getting https://en-US/foo/bar. I think the staging server's Apache config is wrong.
I also question the purpose of this pattern, but I guess it was a problem at some point (see bug 779501)
tests/redirects/map_301.py
Outdated
| status_code=requests.codes.found), | ||
|
|
||
| url_test("/foo//bar", "/foo_bar"), | ||
| url_test("/foo//bar//baz", "/foo_bar_baz"), |
There was a problem hiding this comment.
This fails against --base-url=http://localhost:8000, getting http://localhost:8000/bar_baz
It also fails against --base-url=https://developer.allizom.org, getting https://developer.allizom.org/f/en-US/foo/bar/baz.
WEIRD.
|
There's some missing stuff:
but, I'm happy with what is here so far. It's up to @metadave if he wants to keep working in this PR, or merge and add further refinements in a future PR. |
|
@jwhitlock I pushed some fixes to get all the tests to pass on which correspond to the following rewrites: I'd prefer to submit * the .htaccess redirects in a separate PR. I'll wait for Travis to turn green and merge. |
|
Nice work @metadave. I'll diff the staging and production configuration, and see why there is a difference for those URL patterns. |
|
I've looked at the staging and production Apache configuration, and the two given rewrite rules are missing from staging. I've opened infra bug 1365774 to request syncing the two configurations. |
|
The configurations have been synced, and the tests now pass against staging: |
previously: #4215
This PR uses @pmac's https://github.com/pmac/django-redirect-urls lib to implement SCL3 Apache httpd redirects in Python/Django. The complex rewrites retain original mod_rewrite rules as comments, while the remaining are uncommented simple static redirects. Test layout is similar to the Bedrock redirect tests.
The only rewrite rule that isn't implemented in this PR is as follows:
which redirects requests to
developer.mozilla.com/*-->developer.mozilla.org/*Tracked in this infra issue