Skip to content

Commit

Permalink
Add new test /static-checks/html-links
Browse files Browse the repository at this point in the history
Test verifies that HTML links from datastream are accessible.

Rewrite of old `Sanity/oscap-html-links` test.
  • Loading branch information
matusmarhefka authored and mildas committed Mar 12, 2024
1 parent 6633966 commit a4ec118
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
9 changes: 9 additions & 0 deletions conf/waivers-upstream
Original file line number Diff line number Diff line change
Expand Up @@ -294,5 +294,14 @@
/scanning/disa-alignment/.*/kernel_module_tipc_disabled
rhel == 9

# HTML links from datastreams waivers
#
# Inaccessible until form is filled:
/static-checks/html-links/https://docs-prv.pcisecuritystandards.org/PCI%20DSS/Standard/PCI-DSS-v4_0.pdf
True
# https://github.com/ComplianceAsCode/content/issues/11678
/static-checks/html-links/http://www.cnss.gov/Assets/pdf/CNSSI-1253.pdf
True


# vim: syntax=python
15 changes: 15 additions & 0 deletions static-checks/html-links/main.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
summary: Verify that HTML links from datastream are accessible.
test: python3 -m lib.runtest ./test.py
result: custom
environment+:
PYTHONPATH: ../..
duration: 5m
recommend+:
- python3-requests
tag:
- daily
adjust:
- enabled: false
when: arch != x86_64
continue: false
extra-summary: /CoreOS/scap-security-guide/static-checks/html-links
25 changes: 25 additions & 0 deletions static-checks/html-links/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/python3

import re
import requests

from lib import util, results


headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64;)'}
url_regex = re.compile(r'href=[\'"]?(http[^\'" ]+)', re.IGNORECASE)

with open(util.get_datastream(), 'r') as ds:
ds_content = ds.read()
urls = set(url_regex.findall(ds_content))

for url in urls:
try:
r = requests.get(url, timeout=10, headers=headers)
r.raise_for_status()
except requests.exceptions.RequestException as err:
results.report('fail', url, err)
else:
results.report('pass', url)

results.report_and_exit()

0 comments on commit a4ec118

Please sign in to comment.