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";
|
2023-07-31 16:34:56 +02:00
|
|
|
my $uri="heise.de";
|
2019-11-16 12:41:44 +01:00
|
|
|
my $out="";
|
|
|
|
my $html="";
|
|
|
|
my $debughtml="";
|
|
|
|
my $edited_html="";
|
2023-03-12 15:09:24 +01:00
|
|
|
my $htmlfile="tmp.html";
|
2023-07-31 16:34:56 +02:00
|
|
|
my $check2run="--ip=one --sneaky --ids-friendly --color 0 --htmlfile $htmlfile";
|
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";
|
2023-03-12 15:09:24 +01:00
|
|
|
unlink $htmlfile;
|
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`;
|
2023-03-12 15:09:24 +01:00
|
|
|
$html = `cat $htmlfile`;
|
2019-11-16 12:41:44 +01:00
|
|
|
# $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.
|
2023-03-12 15:09:24 +01:00
|
|
|
$edited_html = `tail -n +11 $htmlfile`;
|
|
|
|
unlink $htmlfile;
|
2017-04-19 15:19:24 +02:00
|
|
|
|
|
|
|
# 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
|
2022-05-14 12:06:09 +02:00
|
|
|
$edited_html =~ s/<a href=[0-9A-Za-z ";:_&=\/\.\?\-]*>//g;
|
2019-11-16 12:41:44 +01:00
|
|
|
$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";
|
|
|
|
|
2023-03-12 15:09:24 +01:00
|
|
|
|
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`;
|
2023-03-12 15:09:24 +01:00
|
|
|
$debughtml = `cat $htmlfile`;
|
|
|
|
unlink $htmlfile;
|
2017-04-19 15:19:24 +02:00
|
|
|
|
|
|
|
# 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;
|
2023-03-12 15:09:24 +01:00
|
|
|
$debughtml =~ s/No engine or GOST support via engine with your.*\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
|
|
|
|
|