Tim Landscheidt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/108467


Change subject: Script to test Toolserver redirects
......................................................................

Script to test Toolserver redirects

Bug: 60238
Change-Id: I71adf356d18b59a9bc9e6d2a1a568b8252cafd18
---
A toolserver/test-redirects.py
1 file changed, 63 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/software 
refs/changes/67/108467/1

diff --git a/toolserver/test-redirects.py b/toolserver/test-redirects.py
new file mode 100755
index 0000000..efc04d9
--- /dev/null
+++ b/toolserver/test-redirects.py
@@ -0,0 +1,63 @@
+#!/usr/bin/python
+
+# This script tests whether a host given as a command line argument
+# correctly redirects Toolserver URLs to their new homes.
+
+import argparse
+import httplib
+import sys
+
+# Parse command line arguments.
+parser = argparse.ArgumentParser(
+    description='Test host for correct Toolserver redirects.')
+parser.add_argument('host', help='Host to test')
+args = parser.parse_args()
+
+# Hosts that the redirector should recognize.
+TestHosts = ['toolserver.org',
+             'www.toolserver.org',
+             'ortelius.toolserver.org',
+             'wolfsbane.toolserver.org']
+
+# The following URLs will be tested.  The keys are the paths of the
+# URL to be tested for each of TestHosts, the values are the correct
+# redirects.  Each URL will be tested for http and https, so the
+# redirects don't include schemes.
+TestURLs = {'/': 'meta.wikimedia.org/wiki/Toolserver',
+            '/~timl/wikilint': 'tools.wmflabs.org/wikilint',
+            '/~timl/wikilint/': 'tools.wmflabs.org/wikilint/',
+            '/~timl/wikilint/abc': 'tools.wmflabs.org/wikilint/abc',
+            '/~timl/wikilint/abc?a=1&b=2': 
'tools.wmflabs.org/wikilint/abc?a=1&b=2',
+            '/~timl/wikilintabc': 'meta.wikimedia.org/wiki/Toolserver',
+            '/~daniel/potd/': 'tools.wmflabs.org/potd-feed/',
+            '/~pietrodn/intersectContribs.php': 
'tools.wmflabs.org/intersect-contribs/',
+            '/~pietrodn/sectionLinks.php': 'tools.wmflabs.org/section-links/'}
+
+# Exit status.
+exitstatus = 0
+
+def TestRedirects(conn, scheme, hosts, testurls):
+    global exitstatus
+
+    for host in hosts:
+        for path, redirect in testurls.iteritems():
+            conn.request('GET', path, headers={'Host': host})
+            response = conn.getresponse()
+            response.read()   # Discard body.
+            if response.status != 301 or response.getheader('Location') != 
(scheme + '://' + redirect):
+                print "%s://%s%s should have redirected to %s, but returned 
\"%s %s (%s)" % (scheme, host, path, redirect, response.status, 
response.reason, response.getheader('Location'))
+                exitstatus = 3
+
+# Test http.
+conn = httplib.HTTPConnection(args.host)
+TestRedirects(conn, 'http', TestHosts, TestURLs)
+conn.close()
+
+# Test https.
+conn = httplib.HTTPSConnection(args.host)
+TestRedirects(conn, 'https', TestHosts, TestURLs)
+conn.close()
+
+if exitstatus:
+    print "Found errors."
+    sys.exit(exitstatus)

-- 
To view, visit https://gerrit.wikimedia.org/r/108467
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I71adf356d18b59a9bc9e6d2a1a568b8252cafd18
Gerrit-PatchSet: 1
Gerrit-Project: operations/software
Gerrit-Branch: master
Gerrit-Owner: Tim Landscheidt <t...@tim-landscheidt.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to