testssl.sh/t/61_diff_testsslsh.t

69 lines
1.7 KiB
Perl
Raw Normal View History

2020-11-26 15:58:13 +01:00
#!/usr/bin/env perl
2020-11-26 16:27:40 +01:00
# Baseline diff test against testssl.sh (csv output)
2020-11-26 15:58:13 +01:00
#
2020-11-26 16:27:40 +01:00
# We don't use a full run yet and only the certificate section.
# There we would need to blacklist more, like:
2020-11-26 15:58:13 +01:00
# cert_serialNumber, cert_fingerprintSHA1, cert_fingerprintSHA256, cert
# cert_expirationStatus, cert_notBefore, cert_notAfter, cert_caIssuers, intermediate_cert
#
use strict;
use Test::More;
use Data::Dumper;
use Text::Diff;
my $tests = 0;
my $prg="./testssl.sh";
my $baseline_csv="./t/baseline_data/default_testssl.csvfile";
my $cat_csv="tmp.csv";
my $check2run="-p -s -P --fs -h -U -c -q --ip=one --color 0 --csvfile $cat_csv";
2020-11-26 15:58:13 +01:00
my $uri="testssl.sh";
my $diff="";
die "Unable to open $prg" unless -f $prg;
die "Unable to open $baseline_csv" unless -f $baseline_csv;
2020-11-26 15:58:13 +01:00
# Provide proper start conditions
unlink $cat_csv;
2020-11-26 15:58:13 +01:00
my @args=("$prg", "$check2run", "$uri", "2>&1");
2020-11-26 15:58:13 +01:00
#1 run
printf "\n%s\n", "Diff unit test (IPv4) against \"$uri\"";
printf "@args\n";
system("@args") == 0
or die ("FAILED: \"@args\" ");
2020-11-26 15:58:13 +01:00
$cat_csv=`cat $cat_csv`;
$baseline_csv=`cat $baseline_csv`;
2020-11-26 15:58:13 +01:00
# Filter for changes that are allowed to occur
$cat_csv =~ s/HTTP_clock_skew.*\n//g;
$baseline_csv =~ s/HTTP_clock_skew.*\n//g;
# HTTP time
$cat_csv =~ s/HTTP_headerTime.*\n//g;
$baseline_csv =~ s/HTTP_headerTime.*\n//g;
2020-11-26 15:58:13 +01:00
# DROWN
$cat_csv =~ s/censys.io.*\n//g;
$baseline_csv =~ s/censys.io.*\n//g;
$diff = diff \$cat_csv, \$baseline_csv;
2021-12-10 18:26:03 +01:00
# Compare the differences to the baseline file -- and print differences if there were detected.
2020-11-26 15:58:13 +01:00
#
ok($cat_csv eq $baseline_csv, "Check whether CSV output matches baseline file from $uri") or
diag ("\n%s\n", "$diff");
2020-11-26 15:58:13 +01:00
unlink "tmp.csv";
$tests++;
2020-11-26 15:58:13 +01:00
done_testing($tests);
printf "\n";
# vim:ts=5:sw=5:expandtab
2020-11-26 15:58:13 +01:00