Page MenuHomePhabricator
Paste P32345

Test $wgCdnMatchParameterOrder on mwdebug host.
ActivePublic

Authored by ori on Aug 10 2022, 4:29 PM.
Tags
None
Referenced Files
F35419999: Test $wgCdnMatchParameterOrder on mwdebug host.
Aug 10 2022, 4:29 PM
Subscribers
None
#!/usr/bin/env python3
"""
Test $wgCdnMatchParameterOrder on mwdebug host.
Update `wikis` below to match $wgCdnMatchParameterOrder config.
"""
import requests
import socket
from urllib3.util import connection
_orig_create_connection = connection.create_connection
def patched_create_connection(address, *args, **kwargs):
"""Resolve .*.wikipedia.org to local machine."""
host, port = address
if host.endswith('wikipedia.org'):
host = socket.gethostname()
return _orig_create_connection((host, port), *args, **kwargs)
connection.create_connection = patched_create_connection
wikis = [
# hostname, $wgCdnMatchParameterOrder
('test.wikipedia.org', True),
('en.wikipedia.org', True),
]
titles = ("Moon", "Statistics", "Candy", "Wikipedia", "School")
urls = [
("https://{wiki}/wiki/{title}", 'canonical'),
("https://{wiki}/w/index.php?title={title}&action=history", 'canonical'),
("https://{wiki}/w/index.php?action=history&title={title}", 'ordered-canonical'),
("https://{wiki}/w/index.php?title={title}&action=history&uselang=en", 'non-canonical'),
]
s = requests.Session()
s.headers.update({'X-Forwarded-Proto': 'https'})
for wiki, matches_order in wikis:
print('--- {wiki} ---'.format(wiki=wiki))
for title in titles:
for url_template, url_type in urls:
if url_type == 'canonical':
expect_public = True
elif url_type == 'non-canonical':
expect_public = False
elif url_type == 'ordered-canonical':
expect_public = not matches_order
match = 's-maxage' if expect_public else 'private'
url = url_template.format(wiki=wiki, title=title)
r = s.get(url)
r.raise_for_status()
assert 'wgBackendResponseTime' in r.text
cache_control = r.headers['Cache-Control'].split(',')[0]
ok = cache_control.startswith(match)
if ok:
print('OK: %s %s : expect="%s" got="%s"' % (url_type, url, match, cache_control))
else:
print('NOT OK: %s %s : expect="%s" got="%s"' % (url_type, url, match, cache_control))
assert cache_control.startswith(match)
print('')