Skip to content

Commit

Permalink
v0.5.4 - html report
Browse files Browse the repository at this point in the history
  • Loading branch information
peppelinux committed Mar 24, 2021
1 parent 6428ffc commit 0b77cb2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def readme():

setup(
name='spid_sp_test',
version='0.5.3',
version='0.5.4',
description="SAML2 SPID Service Provider validation tool that can be run from the command line",
long_description=readme(),
long_description_content_type='text/markdown',
Expand Down
23 changes: 18 additions & 5 deletions src/spid_sp_test/spid_sp_test
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ from spid_sp_test.metadata_extra import SpidSpMetadataCheckExtra
from spid_sp_test.authn_request import SpidSpAuthnReqCheck
from spid_sp_test.authn_request_extra import SpidSpAuthnReqCheckExtra
from spid_sp_test.response import SpidSpResponseCheck
from spid_sp_test.utils import get_xmlsec1_bin
from spid_sp_test.utils import get_xmlsec1_bin, report_to_html


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -147,7 +147,15 @@ if __name__ == '__main__':

parser.add_argument(
'-o', required=False,
help="json report to file, -report is required"
help="report to file, -report is required"
)

parser.add_argument(
'-rf', '--report_format',
required=False,
default='json',
choices=['json', 'html'],
help="Report format, json or pdf"
)

parser.add_argument(
Expand Down Expand Up @@ -273,13 +281,18 @@ if __name__ == '__main__':
data['test']['sp'][i.category] = i.report_to_dict()[i.category]

output = json.dumps(data, indent=2)
if args.report:
print(output)

if args.o:
if args.report_format == 'json':
pass
elif args.report_format == 'html':
output = report_to_html(data)

with open(args.o, 'w') as f:
f.write(output)

if args.report and not args.o:
print(output)

# check exit status
tests = sum([len(i.results) for i in tests_done])
tests_errors = sum([len(i.errors) for i in tests_done])
Expand Down
24 changes: 24 additions & 0 deletions src/spid_sp_test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,27 @@ def html_absolute_paths(html_content, url):
attr['href'] = f"{url}/{attr['href']}"

return html.tostring(q)


def report_to_html(o):
res = []
for h1_title in o.keys():
res.append('<h1>%s</h1>' % h1_title)
for h2_title in o[h1_title].keys():
res.append('<h2>%s</h2>' % h2_title)
for h3_title in o[h1_title][h2_title].keys():
res.append('<h3>%s</h3>' % h3_title)
for test_case in o[h1_title][h2_title][h3_title].keys():
res.append('<h4>%s</h4>' % test_case)
for t in o[h1_title][h2_title][h3_title][test_case]: # noqa
res.append('<p><strong>Description:</strong> %s</p>' % t['test']) # noqa
if t['result'] == 'success':
res.append('<div style="background-color: #f2ffe6; padding: 5px; border: 1px solid green; margin: 5px">') # noqa
res.append('<h5 style="color: green">%s</h5>' % t['result']) # noqa
else:
res.append('<div style="background-color: #ffebe6; padding: 5px; border: 1px solid red; margin: 5px">') # noqa
res.append('<h5 style="color: red">%s</h5>' % t['result']) # noqa
# res.append('<p>Test: %s</p>' % t['test'].replace('\n', '<br/>')) # noqa
res.append('<p>Obtained value: %s</p>' % t['value'])
res.append('</div>')
return '\n'.join(res)

0 comments on commit 0b77cb2

Please sign in to comment.