2017-04-19 15:19:24 +02:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
2019-11-16 12:41:44 +01:00
|
|
|
# Checking whether the HTML output is somehow valid
|
|
|
|
# This could be amended by using HTML::Tidy or HTML::Valid
|
|
|
|
|
2017-04-19 15:19:24 +02:00
|
|
|
use strict;
|
|
|
|
use Test::More;
|
|
|
|
use Data::Dumper;
|
2020-10-02 13:07:13 +02:00
|
|
|
use Text::Diff;
|
2017-04-19 15:19:24 +02:00
|
|
|
|
|
|
|
my $tests = 0;
|
2019-11-16 12:41:44 +01:00
|
|
|
my $prg="./testssl.sh";
|
2020-01-22 11:30:21 +01:00
|
|
|
my $uri="heise.de";
|
2019-11-16 12:41:44 +01:00
|
|
|
my $out="";
|
|
|
|
my $html="";
|
|
|
|
my $debughtml="";
|
|
|
|
my $edited_html="";
|
2020-11-27 13:19:52 +01:00
|
|
|
my $check2run="--ip=one --ids-friendly --color 0 --htmlfile tmp.html";
|
2020-10-02 13:07:13 +02:00
|
|
|
my $diff="";
|
2019-11-16 12:41:44 +01:00
|
|
|
die "Unable to open $prg" unless -f $prg;
|
2017-04-19 15:19:24 +02:00
|
|
|
|
2020-01-14 18:44:11 +01:00
|
|
|
printf "\n%s\n", "Doing HTML output checks";
|
2020-01-18 21:47:44 +01:00
|
|
|
unlink 'tmp.html';
|
2020-01-14 18:44:11 +01:00
|
|
|
|
2019-11-16 12:41:44 +01:00
|
|
|
#1
|
2020-01-21 22:41:50 +01:00
|
|
|
printf "%s\n", " .. running $prg against \"$uri\" to create HTML and terminal outputs (may take ~2 minutes)";
|
2017-04-19 15:19:24 +02:00
|
|
|
# specify a TERM_WIDTH so that the two calls to testssl.sh don't create HTML files with different values of TERM_WIDTH
|
2019-11-16 12:41:44 +01:00
|
|
|
$out = `TERM_WIDTH=120 $prg $check2run $uri`;
|
|
|
|
$html = `cat tmp.html`;
|
|
|
|
# $edited_html will contain the HTML with formatting information removed in order to compare against terminal output
|
2017-04-19 15:19:24 +02:00
|
|
|
# Start by removing the HTML header.
|
2019-11-16 12:41:44 +01:00
|
|
|
$edited_html = `tail -n +11 tmp.html`;
|
2017-04-19 15:19:24 +02:00
|
|
|
unlink 'tmp.html';
|
|
|
|
|
|
|
|
# Remove the HTML footer
|
2019-11-16 12:41:44 +01:00
|
|
|
$edited_html =~ s/\n\<\/pre\>\n\<\/body\>\n\<\/html\>//;
|
2017-04-19 15:19:24 +02:00
|
|
|
# Remove any hypertext links for URLs
|
2019-11-16 12:41:44 +01:00
|
|
|
$edited_html =~ s/<a href=[0-9A-Za-z ";:=\/\.\?\-]*>//g;
|
|
|
|
$edited_html =~ s/<\/a>//g;
|
2017-04-19 15:19:24 +02:00
|
|
|
|
|
|
|
# Replace escaped characters with their original text
|
2019-11-16 12:41:44 +01:00
|
|
|
$edited_html =~ s/&/&/g;
|
|
|
|
$edited_html =~ s/</</g;
|
|
|
|
$edited_html =~ s/>/>/g;
|
|
|
|
$edited_html =~ s/"/"/g;
|
|
|
|
$edited_html =~ s/'/'/g;
|
2017-04-19 15:19:24 +02:00
|
|
|
|
2019-11-16 12:41:44 +01:00
|
|
|
cmp_ok($edited_html, "eq", $out, "HTML file matches terminal output");
|
|
|
|
$tests++;
|
2017-04-19 15:19:24 +02:00
|
|
|
|
2020-10-02 13:07:13 +02:00
|
|
|
$diff = diff \$edited_html, \$out;
|
|
|
|
printf "\n%s\n", "$diff";
|
|
|
|
|
2019-11-16 12:41:44 +01:00
|
|
|
#2
|
2020-01-21 22:41:50 +01:00
|
|
|
printf "\n%s\n", " .. running again $prg against \"$uri\", now with --debug 4 to create HTML output (may take another ~2 minutes)";
|
2017-04-19 15:19:24 +02:00
|
|
|
# Redirect stderr to /dev/null in order to avoid some unexplained "date: invalid date" error messages
|
2019-11-16 12:41:44 +01:00
|
|
|
$out = `TERM_WIDTH=120 $prg $check2run --debug 4 $uri 2> /dev/null`;
|
|
|
|
$debughtml = `cat tmp.html`;
|
2017-04-19 15:19:24 +02:00
|
|
|
unlink 'tmp.html';
|
|
|
|
|
|
|
|
# Remove date information from the Start and Done banners in the two HTML files, since they were created at different times
|
2019-11-16 12:41:44 +01:00
|
|
|
$html =~ s/Start 2[0-9][0-9][0-9]-[0-3][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]/Start XXXX-XX-XX XX:XX:XX/;
|
2017-04-19 15:19:24 +02:00
|
|
|
$debughtml =~ s/Start 2[0-9][0-9][0-9]-[0-3][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]/Start XXXX-XX-XX XX:XX:XX/;
|
|
|
|
|
2019-11-16 12:41:44 +01:00
|
|
|
$html =~ s/Done 2[0-9][0-9][0-9]-[0-3][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9] \[ *[0-9]*s\]/Done XXXX-XX-XX XX:XX:XX [ Xs]/;
|
2017-04-19 15:19:24 +02:00
|
|
|
$debughtml =~ s/Done 2[0-9][0-9][0-9]-[0-3][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9] \[ *[0-9]*s\]/Done XXXX-XX-XX XX:XX:XX [ Xs]/;
|
|
|
|
|
|
|
|
# Remove time difference from "HTTP clock skew" line
|
2019-11-16 12:41:44 +01:00
|
|
|
$html =~ s/HTTP clock skew \+?-?[0-9]* /HTTP clock skew X /;
|
2017-04-19 15:19:24 +02:00
|
|
|
$debughtml =~ s/HTTP clock skew \+?-?[0-9]* /HTTP clock skew X /;
|
|
|
|
|
2019-03-30 11:27:22 +01:00
|
|
|
$debughtml =~ s/ Pre-test: .*\n//g;
|
2020-01-04 16:52:38 +01:00
|
|
|
$debughtml =~ s/.*OK: below 825 days.*\n//g;
|
2020-01-21 22:41:50 +01:00
|
|
|
$debughtml =~ s/.*DEBUG:.*\n//g;
|
2019-03-30 11:27:22 +01:00
|
|
|
|
2019-11-16 12:41:44 +01:00
|
|
|
cmp_ok($debughtml, "eq", $html, "HTML file created with --debug 4 matches HTML file created without --debug");
|
|
|
|
$tests++;
|
2017-04-19 15:19:24 +02:00
|
|
|
|
2020-10-02 13:07:13 +02:00
|
|
|
$diff = diff \$debughtml, \$html;
|
|
|
|
printf "\n%s\n", "$diff";
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-01-14 18:44:11 +01:00
|
|
|
printf "\n";
|
2017-04-19 15:19:24 +02:00
|
|
|
done_testing($tests);
|
2021-05-31 22:39:22 +02:00
|
|
|
|
|
|
|
|
|
|
|
# vim:ts=5:sw=5:expandtab
|
|
|
|
|