Commit c68f8cf3 authored by Jelmer Vernooij's avatar Jelmer Vernooij

When trying to fix a HTTP homepage, retrieve and compare HTTP/HTTPS pages.

parent a3da53a4
#!/usr/bin/python3
from lintian_brush.control import (
update_control,
)
import urllib.parse
import urllib.request
known_https = [
'github.com', 'launchpad.net', 'pypi.python.org',
'pear.php.net', 'pecl.php.net', 'www.bioconductor.org',
'cran.r-project.org', 'wiki.debian.org']
def same_page(http_contents, https_contents):
# This is a pretty crude way to determine we end up on the same page, but
# it works.
http_contents = http_contents.replace(b'https', b'').replace(b'http', b'')
https_contents = https_contents.replace(b'https', b'').replace(
b'http', b'')
return http_contents == https_contents
def fix_homepage(http_url):
if not http_url.startswith('http:'):
return http_url
https_url = 'https:' + http_url[len('http:'):]
result = urllib.parse.urlparse(http_url)
if result.netloc in known_https:
return https_url
# Fall back to just comparing the two
http_contents = urllib.request.urlopen(http_url).read()
https_contents = urllib.request.urlopen(https_url).read()
if same_page(http_contents, https_contents):
return https_url
return http_url
def fix_homepage_header(control):
try:
homepage = control["Homepage"]
except KeyError:
return
control["Homepage"] = fix_homepage(homepage)
update_control(source_package_cb=fix_homepage_header)
print("Use secure URI in Homepage field.")
print("Fixed-Lintian-Tags: homepage-field-uses-insecure-uri")
#!/bin/sh
perl -p -i -e 's/^Homepage: http:\/\/github.com/Homepage: https:\/\/github.com/' debian/control
perl -p -i -e 's/^Homepage: http:\/\/launchpad.net/Homepage: https:\/\/launchpad.net/' debian/control
perl -p -i -e 's/^Homepage: http:\/\/pypi.python.org/Homepage: https:\/\/pypi.python.org/' debian/control
perl -p -i -e 's/^Homepage: http:\/\/pear.php.net/Homepage: https:\/\/pear.php.net/' debian/control
perl -p -i -e 's/^Homepage: http:\/\/pecl.php.net/Homepage: https:\/\/pecl.php.net/' debian/control
perl -p -i -e 's/^Homepage: http:\/\/www.bioconductor.org/Homepage: https:\/\/www.bioconductor.org/' debian/control
perl -p -i -e 's/^Homepage: http:\/\/bioconductor.org/Homepage: https:\/\/bioconductor.org/' debian/control
perl -p -i -e 's/^Homepage: http:\/\/cran.r-project.org/Homepage: https:\/\/cran.r-project.org/' debian/control
perl -p -i -e 's/^Homepage: http:\/\/wiki.debian.org/Homepage: https:\/\/wiki.debian.org/' debian/control
echo "Use secure URI in Homepage field."
echo "Fixed-Lintian-Tags: homepage-field-uses-insecure-uri"
......@@ -34,7 +34,7 @@ Lintian-Tags: dm-upload-allowed-is-obsolete
Fix-Script: file-contains-trailing-whitespace.sh
Lintian-Tags: file-contains-trailing-whitespace
Fix-Script: homepage-field-uses-insecure-uri.sh
Fix-Script: homepage-field-uses-insecure-uri.py
Lintian-Tags: homepage-field-uses-insecure-uri
Fix-Script: insecure-copyright-format-uri.sh
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment