2017-03-09 18:55:04 +01:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Test::More;
|
|
|
|
use Data::Dumper;
|
|
|
|
use JSON;
|
|
|
|
|
2020-01-30 21:28:39 +01:00
|
|
|
my $out="";
|
|
|
|
my $json="";
|
|
|
|
my $json_pretty="";
|
|
|
|
my $csv="";
|
|
|
|
my $found="";
|
|
|
|
my $tests = 0;
|
|
|
|
my $check2run="--ip=one -s -p -P -e -U --ids-friendly --severity LOW --color 0";
|
|
|
|
my $linenum=0;
|
|
|
|
my $prg="./testssl.sh";
|
|
|
|
#my $uri="badssl.com";
|
|
|
|
my $uri="google.com";
|
2017-03-09 18:55:04 +01:00
|
|
|
|
2020-01-30 21:28:39 +01:00
|
|
|
die "Unable to open $prg" unless -f $prg;
|
2017-03-09 18:55:04 +01:00
|
|
|
|
2020-01-30 21:28:39 +01:00
|
|
|
# Provide proper start conditions
|
2020-01-18 21:47:44 +01:00
|
|
|
unlink 'tmp.json';
|
2020-01-30 21:28:39 +01:00
|
|
|
unlink 'tmp.csv';
|
|
|
|
|
|
|
|
printf "\n%s\n", "Doing severity level checks in JSON formats and CSV against \"$uri\"";
|
2020-01-14 18:44:11 +01:00
|
|
|
|
2020-01-30 21:28:39 +01:00
|
|
|
#1 (first run)
|
|
|
|
printf ".. create JSON+CSV reports with severity level >= LOW (may take ~2 minutes)\n";
|
|
|
|
$out = `$prg $check2run --jsonfile tmp.json --csvfile tmp.csv $uri`;
|
2017-03-09 18:55:04 +01:00
|
|
|
$json = json('tmp.json');
|
2020-01-30 21:28:39 +01:00
|
|
|
$csv = csv('tmp.csv');
|
2017-03-09 18:55:04 +01:00
|
|
|
$found = 0;
|
2020-01-30 21:28:39 +01:00
|
|
|
cmp_ok(@$json,'>',0,"At least 1 finding is expected in JSON");
|
|
|
|
$tests++;
|
|
|
|
|
|
|
|
# 2 count lines in CSV
|
|
|
|
$linenum = $csv =~ tr/\n//;
|
|
|
|
ok($linenum ge 4, "we should have at least 4 results in CSV: $linenum" );
|
|
|
|
$tests++;
|
|
|
|
|
|
|
|
#3
|
2017-03-09 18:55:04 +01:00
|
|
|
foreach my $f ( @$json ) {
|
|
|
|
if ( $f->{severity} eq "INFO" ) {
|
|
|
|
$found = 1;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
2020-01-30 21:28:39 +01:00
|
|
|
is($found,0,"We should not have any findings with INFO level in JSON");
|
|
|
|
unlink 'tmp.json';
|
|
|
|
$tests++;
|
|
|
|
|
|
|
|
#4
|
|
|
|
unlike($csv, qr/,\"INFO\",/,"We should not have any findings with INFO level in CSV");
|
|
|
|
unlink 'tmp.csv';
|
|
|
|
$tests++;
|
2017-03-09 18:55:04 +01:00
|
|
|
|
2020-01-30 21:28:39 +01:00
|
|
|
|
|
|
|
#5 (second run)
|
|
|
|
# We still do CSV here despite it's thge same as above.
|
|
|
|
# There was a bug which creates an INFO level output.
|
|
|
|
printf ".. create a JSON-PRETTY report with severity level >= LOW (may take ~2 minutes)\n";
|
|
|
|
$out = `$prg $check2run --jsonfile-pretty tmp.json --csvfile tmp.csv $uri`;
|
2017-03-09 18:55:04 +01:00
|
|
|
$json_pretty = json('tmp.json');
|
2020-01-30 21:28:39 +01:00
|
|
|
$csv = csv('tmp.csv');
|
2017-03-09 18:55:04 +01:00
|
|
|
$found = 0;
|
2020-01-30 21:28:39 +01:00
|
|
|
cmp_ok(@$json,'>',0,"At least 1 finding is expected");
|
|
|
|
$tests++;
|
|
|
|
|
|
|
|
#6 count lines in CSV
|
|
|
|
$linenum = $csv =~ tr/\n//;
|
|
|
|
ok($linenum ge 4, "we should have at least 4 results in CSV: $linenum" );
|
|
|
|
$tests++;
|
|
|
|
|
|
|
|
#7
|
2017-03-09 18:55:04 +01:00
|
|
|
my $vulnerabilities = $json_pretty->{scanResult}->[0]->{vulnerabilities};
|
|
|
|
foreach my $f ( @$vulnerabilities ) {
|
|
|
|
if ( $f->{severity} eq "INFO" ) {
|
|
|
|
$found = 1;
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
2020-01-30 21:28:39 +01:00
|
|
|
is($found,0,"We should not have any findings with INFO level in JSON");
|
|
|
|
unlink "tmp.json";
|
|
|
|
$tests++;
|
|
|
|
|
|
|
|
#8 failed. See bug above
|
|
|
|
unlike($csv, qr/,\"INFO\",/,"We should not have any findings with INFO level in CSV");
|
|
|
|
unlink 'tmp.csv';
|
|
|
|
$tests++;
|
|
|
|
|
2017-03-09 18:55:04 +01:00
|
|
|
|
2020-01-30 21:28:39 +01:00
|
|
|
done_testing();
|
|
|
|
# done_testing($tests);
|
2020-01-14 18:44:11 +01:00
|
|
|
printf "\n";
|
2017-03-09 18:55:04 +01:00
|
|
|
|
|
|
|
sub json($) {
|
|
|
|
my $file = shift;
|
|
|
|
$file = `cat $file`;
|
|
|
|
return from_json($file);
|
2017-03-29 17:42:09 +02:00
|
|
|
}
|
2020-01-30 21:28:39 +01:00
|
|
|
|
|
|
|
sub csv($) {
|
|
|
|
my $file = shift;
|
|
|
|
$file = `cat $file`;
|
|
|
|
return ($file);
|
|
|
|
}
|