Merge branch 'lint-url-improvements' into 'master'

Lint URL improvements

See merge request fdroid/fdroidserver!681
This commit is contained in:
Hans-Christoph Steiner 2019-10-07 08:36:18 +00:00
commit f8c954d89e
3 changed files with 56 additions and 3 deletions

View file

@ -33,7 +33,7 @@ options = None
def enforce_https(domain): def enforce_https(domain):
return (re.compile(r'^[^h][^t][^t][^p][^s]://[^/]*' + re.escape(domain) + r'(/.*)?', re.IGNORECASE), return (re.compile(r'^http://([^/]*\.)?' + re.escape(domain) + r'(/.*)?', re.IGNORECASE),
domain + " URLs should always use https://") domain + " URLs should always use https://")
@ -120,9 +120,11 @@ http_url_shorteners = [
] ]
http_checks = https_enforcings + http_url_shorteners + [ http_checks = https_enforcings + http_url_shorteners + [
(re.compile(r'.*github\.com/[^/]+/[^/]+\.git'), (re.compile(r'^(?!https?://)[^/]+'),
_("URL must start with https:// or http://")),
(re.compile(r'^https://(github|gitlab)\.com(/[^/]+){2,3}\.git'),
_("Appending .git is not necessary")), _("Appending .git is not necessary")),
(re.compile(r'.*://[^/]*(github|gitlab|bitbucket|rawgit)[^/]*/([^/]+/){1,3}master'), (re.compile(r'^https://[^/]*(github|gitlab|bitbucket|rawgit|githubusercontent)\.[a-zA-Z]+/([^/]+/){2,3}master/'),
_("Use /HEAD instead of /master to point at a file in the default branch")), _("Use /HEAD instead of /master to point at a file in the default branch")),
] ]
@ -726,6 +728,7 @@ APPROVED_LICENSES = [
'LiLiQ-Rplus-1.1', 'LiLiQ-Rplus-1.1',
'MIT', 'MIT',
'MIT-0', 'MIT-0',
'MIT-CMU',
'MPL-1.0', 'MPL-1.0',
'MPL-1.1', 'MPL-1.1',
'MPL-2.0', 'MPL-2.0',

View file

@ -82,6 +82,7 @@ else
fi fi
echo "build_server_always = True" > config.py echo "build_server_always = True" > config.py
echo "deploy_process_logs = True" >> config.py
# if the local mediawiki is available, then use it # if the local mediawiki is available, then use it
if nc -z -w1 localhost 32445; then if nc -z -w1 localhost 32445; then
wikiflag="--wiki" wikiflag="--wiki"

View file

@ -70,6 +70,55 @@ class LintTest(unittest.TestCase):
logging.debug(warn) logging.debug(warn)
self.assertTrue(anywarns) self.assertTrue(anywarns)
def test_source_urls(self):
config = dict()
fdroidserver.common.fill_config_defaults(config)
fdroidserver.common.config = config
fdroidserver.lint.config = config
app = {
'Name': 'My App',
'Summary': 'just a placeholder',
'Description': 'This app does all sorts of useful stuff',
}
good_urls = [
'https://github.com/Matteljay/mastermindy-android',
'https://gitlab.com/origin/master',
'https://gitlab.com/group/subgroup/masterthing',
'https://raw.githubusercontent.com/Seva-coder/Finder/HEAD/ChangeLog.txt',
'https://github.com/scoutant/blokish/blob/HEAD/README.md#changelog',
'https://git.ieval.ro/?p=fonbot.git;a=blob;f=Changes;hb=HEAD',
'https://htmlpreview.github.io/?https://github.com/YasuakiHonda/Maxima-on-Android-AS/blob/HEAD/app/src/main/assets/About_MoA/index.html',
'',
]
anywarns = False
for url in good_urls:
app['SourceCode'] = url
for warn in fdroidserver.lint.check_regexes(app):
anywarns = True
logging.debug(warn)
self.assertFalse(anywarns)
bad_urls = [
'github.com/my/proj',
'http://github.com/not/secure',
'https://github.com/foo/bar.git',
'https://gitlab.com/group/subgroup/project.git',
'https://raw.githubusercontent.com/Seva-coder/Finder/master/ChangeLog.txt',
'https://github.com/scoutant/blokish/blob/master/README.md#changelog',
'http://htmlpreview.github.io/?https://github.com/my/project/blob/HEAD/index.html',
'http://fdroid.gitlab.io/fdroid-website',
]
logging.debug('bad urls:')
for url in bad_urls:
anywarns = False
app['SourceCode'] = url
for warn in fdroidserver.lint.check_regexes(app):
anywarns = True
logging.debug(warn)
self.assertTrue(anywarns, url + " does not fail lint!")
def test_check_app_field_types(self): def test_check_app_field_types(self):
config = dict() config = dict()
fdroidserver.common.fill_config_defaults(config) fdroidserver.common.fill_config_defaults(config)