docs: Reject non-https external links

Add a '--require-https' switch to 'check-html-references' helper script
which will error out if any non-https external link is used from our web
and use it while builidng docs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2024-10-08 13:38:34 +02:00
parent 8618535990
commit 86a5acbe10
2 changed files with 22 additions and 0 deletions

View File

@ -358,6 +358,7 @@ if tests_enabled[0]
python3_prog, python3_prog,
args: [ args: [
check_html_references_prog.full_path(), check_html_references_prog.full_path(),
'--require-https',
'--webroot', '--webroot',
meson.project_build_root() / 'docs' meson.project_build_root() / 'docs'
], ],

View File

@ -224,6 +224,18 @@ def check_images(usedimages, imagefiles, ignoreimages):
return fail return fail
# checks that all links are accessed via https
def check_https(links):
fail = False
for link in links:
if link.startswith('http://'):
print(f'ERROR: URI \'{link}\' uses insecure "http" protocol')
fail = True
return fail
parser = argparse.ArgumentParser(description='HTML reference checker') parser = argparse.ArgumentParser(description='HTML reference checker')
parser.add_argument('--webroot', required=True, parser.add_argument('--webroot', required=True,
help='path to the web root') help='path to the web root')
@ -233,6 +245,8 @@ parser.add_argument('--external', action="store_true",
help='print external references instead') help='print external references instead')
parser.add_argument('--ignore-images', action='append', parser.add_argument('--ignore-images', action='append',
help='paths to images that should be considered as used') help='paths to images that should be considered as used')
parser.add_argument('--require-https', action="store_true",
help='require secure https for external links')
args = parser.parse_args() args = parser.parse_args()
@ -269,6 +283,13 @@ else:
if check_images(usedimages, imagefiles, args.ignore_images): if check_images(usedimages, imagefiles, args.ignore_images):
fail = True fail = True
if args.require_https:
if check_https(externallinks):
fail = True
if check_https(externalimages):
fail = True
if fail: if fail:
sys.exit(1) sys.exit(1)