From d82f809c6d46deb87fd1a8e480ad1722f6270f53 Mon Sep 17 00:00:00 2001 From: David Cooper Date: Fri, 14 Apr 2017 11:24:26 -0400 Subject: [PATCH 1/4] Add Travis test for HTML output I've never programmed in perl before, but this script seems to work. It includes two checks: * I runs testssl.sh without the `--debug` flags and checks that the HTML file is the same as what is sent to the terminal. * It runs testssl.sh with `--debug 4` and checks that the HTML file created is the same as the one created without the `--debug` flag. --- t/02_http.t | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 t/02_http.t diff --git a/t/02_http.t b/t/02_http.t new file mode 100644 index 0000000..1a72d17 --- /dev/null +++ b/t/02_http.t @@ -0,0 +1,47 @@ +#!/usr/bin/env perl + +use strict; +use Test::More; +use Data::Dumper; + +my $tests = 0; + +pass("Running testssl.sh against badssl.com to create HTML and terminal outputs (may take 2~3 minutes)"); $tests++; +# specify a TERM_WIDTH so that the two calls to testssl.sh don't create HTML files with different values of TERM_WIDTH +my $okout = `TERM_WIDTH=80 ./testssl.sh --color 0 --quiet --append --htmlfile tmp.html badssl.com`; +my $okhtml = `cat tmp.html`; +# $modedhtml will contain the HTML with formatting information removed in order to compare against terminal output +my $modedhtml = `cat tmp.html`; +unlink 'tmp.html'; + +# Remove any hypertext links for URLs +$modedhtml =~ s///g; +$modedhtml =~ s/<\/a>//g; + +# Replace escaped characters with their original text +$modedhtml =~ s/&/&/g; +$modedhtml =~ s/<//g; +$modedhtml =~ s/"/"/g; +$modedhtml =~ s/'/'/g; + +pass("Comparing HTML and terminal outputs"); $tests++; +cmp_ok($modedhtml, "eq", $okout, "HTML file matches terminal output"); $tests++; + +pass("Running testssl.sh against badssl.com with --debug 4 to create HTML output (may take 2~3 minutes)"); $tests++; +# Redirect stderr to /dev/null in order to avoid some unexplained "date: invalid date" error messages +my $debugout = `TERM_WIDTH=80 ./testssl.sh --color 0 --quiet --append --debug 4 --htmlfile tmp.html badssl.com 2> /dev/null`; +my $debughtml = `cat tmp.html`; +unlink 'tmp.html'; + +# Remove date information from the Start and Done banners in the two HTML files, since they were created at different times +$okhtml =~ 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]//; +$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]//; + +$okhtml =~ 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\]//; +$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\]//; + +pass("Checking that using the --debug option doesn't affect the HTML file"); $tests++; +cmp_ok($debughtml, "eq", $okhtml, "HTML file created with --debug 4 matches HTML file created without --debug"); $tests++; + +done_testing($tests); From 1249157afd7be896bfed78c20c2a842229f6b0cd Mon Sep 17 00:00:00 2001 From: David Cooper Date: Fri, 14 Apr 2017 11:39:28 -0400 Subject: [PATCH 2/4] Handle differing HTTP clock skew Occasionally the HTTP clock skew will differ between the two runs of testssl.sh, so remove that text from the strings that are compared. --- t/02_http.t | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/t/02_http.t b/t/02_http.t index 1a72d17..1055dfb 100644 --- a/t/02_http.t +++ b/t/02_http.t @@ -41,6 +41,10 @@ $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- $okhtml =~ 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\]//; $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\]//; +# Remove time difference from "HTTP clock skew" line +$okhtml =~ s/HTTP clock skew +?-?[0-9]* //; +$debughtml =~ s/HTTP clock skew +?-?[0-9]* //; + pass("Checking that using the --debug option doesn't affect the HTML file"); $tests++; cmp_ok($debughtml, "eq", $okhtml, "HTML file created with --debug 4 matches HTML file created without --debug"); $tests++; From 6d55b2e6f332b5e95ffb48d96312bf35ae9a023b Mon Sep 17 00:00:00 2001 From: David Cooper Date: Fri, 14 Apr 2017 16:25:49 -0400 Subject: [PATCH 3/4] Include banner in check * Changed calls to testssl.sh to not include `--quiet` or `--append` flags. Modified perl script to remove HTML header and footer before comparing to terminal output. * Changed `TERM_WIDTH` to 120 (doesn't affect test, but 80 created too much line wrapping). * Replace date and time information with X's rather than removing entirely. This should not affect the comparison, but will make the output created displayed in an error message look closer to the actual output of testssl.sh --- t/02_http.t | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/t/02_http.t b/t/02_http.t index 1055dfb..e33aeb7 100644 --- a/t/02_http.t +++ b/t/02_http.t @@ -8,12 +8,15 @@ my $tests = 0; pass("Running testssl.sh against badssl.com to create HTML and terminal outputs (may take 2~3 minutes)"); $tests++; # specify a TERM_WIDTH so that the two calls to testssl.sh don't create HTML files with different values of TERM_WIDTH -my $okout = `TERM_WIDTH=80 ./testssl.sh --color 0 --quiet --append --htmlfile tmp.html badssl.com`; +my $okout = `TERM_WIDTH=120 ./testssl.sh --color 0 --htmlfile tmp.html badssl.com`; my $okhtml = `cat tmp.html`; # $modedhtml will contain the HTML with formatting information removed in order to compare against terminal output -my $modedhtml = `cat tmp.html`; +# Start by removing the HTML header. +my $modedhtml = `tail -n +11 tmp.html`; unlink 'tmp.html'; +# Remove the HTML footer +$modedhtml =~ s/\n\<\/pre\>\n\<\/body\>\n\<\/html\>//; # Remove any hypertext links for URLs $modedhtml =~ s///g; $modedhtml =~ s/<\/a>//g; @@ -30,20 +33,20 @@ cmp_ok($modedhtml, "eq", $okout, "HTML file matches terminal output"); $tests++; pass("Running testssl.sh against badssl.com with --debug 4 to create HTML output (may take 2~3 minutes)"); $tests++; # Redirect stderr to /dev/null in order to avoid some unexplained "date: invalid date" error messages -my $debugout = `TERM_WIDTH=80 ./testssl.sh --color 0 --quiet --append --debug 4 --htmlfile tmp.html badssl.com 2> /dev/null`; +my $debugout = `TERM_WIDTH=120 .testssl.sh --color 0 --debug 4 --htmlfile tmp.html badssl.com 2> /dev/null`; my $debughtml = `cat tmp.html`; unlink 'tmp.html'; # Remove date information from the Start and Done banners in the two HTML files, since they were created at different times -$okhtml =~ 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]//; -$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]//; +$okhtml =~ 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/; +$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/; -$okhtml =~ 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\]//; -$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\]//; +$okhtml =~ 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]/; +$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 -$okhtml =~ s/HTTP clock skew +?-?[0-9]* //; -$debughtml =~ s/HTTP clock skew +?-?[0-9]* //; +$okhtml =~ s/HTTP clock skew +?-?[0-9]* /HTTP clock skew X /; +$debughtml =~ s/HTTP clock skew +?-?[0-9]* /HTTP clock skew X /; pass("Checking that using the --debug option doesn't affect the HTML file"); $tests++; cmp_ok($debughtml, "eq", $okhtml, "HTML file created with --debug 4 matches HTML file created without --debug"); $tests++; From c76f6019e3fd3d553fb405868ef8b152eac9affd Mon Sep 17 00:00:00 2001 From: David Cooper Date: Fri, 14 Apr 2017 16:31:46 -0400 Subject: [PATCH 4/4] Fix typo Missing "/" in second call to testssl.sh --- t/02_http.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/02_http.t b/t/02_http.t index e33aeb7..8ef1fd2 100644 --- a/t/02_http.t +++ b/t/02_http.t @@ -33,7 +33,7 @@ cmp_ok($modedhtml, "eq", $okout, "HTML file matches terminal output"); $tests++; pass("Running testssl.sh against badssl.com with --debug 4 to create HTML output (may take 2~3 minutes)"); $tests++; # Redirect stderr to /dev/null in order to avoid some unexplained "date: invalid date" error messages -my $debugout = `TERM_WIDTH=120 .testssl.sh --color 0 --debug 4 --htmlfile tmp.html badssl.com 2> /dev/null`; +my $debugout = `TERM_WIDTH=120 ./testssl.sh --color 0 --debug 4 --htmlfile tmp.html badssl.com 2> /dev/null`; my $debughtml = `cat tmp.html`; unlink 'tmp.html';