testssl.sh/t/33_isJSON_severitylevel_valid.t
Dirk Wetter 96d4b4f08b Trying to reduced the runtime of travis
Often in the past travis was hitting a limit (50min?).

This is a try to make reasonable cuts to the unit tests:
- For STARTTLS some checks with OPenSSL are skipped
- For JSON and HTML outputs --ids-friendly was added assumming we
  don't change the output of ticketbleed, CCSI, HeartBleed and ROBOT any more.
- There's also not point to run those checks against badssl
- for  the diff check we switch to 'or diag' to display a dfifference
2020-11-27 13:19:52 +01:00

61 lines
1.5 KiB
Perl
Executable File

#!/usr/bin/env perl
use strict;
use Test::More;
use Data::Dumper;
use JSON;
my (
$out,
$json,
$json_pretty,
$found,
$tests
);
$tests = 0;
printf "\n%s\n", "Doing severity level checks";
unlink 'tmp.json';
#1
pass(" .. running testssl.sh against badssl.com to create a JSON report with severity level equal greater than LOW (may take 2~3 minutes)"); $tests++;
$out = `./testssl.sh -S -e -U --ids-friendly --jsonfile tmp.json --severity LOW --color 0 badssl.com`;
$json = json('tmp.json');
unlink 'tmp.json';
$found = 0;
cmp_ok(@$json,'>',0,"At least 1 finding is expected"); $tests++;
foreach my $f ( @$json ) {
if ( $f->{severity} eq "INFO" ) {
$found = 1;
last;
}
}
is($found,0,"We should not have any finding with INFO level"); $tests++;
#2
pass(" .. running testssl.sh against badssl.com to create a JSON-PRETTY report with severity level equal greater than LOW (may take 2~3 minutes)"); $tests++;
$out = `./testssl.sh -S -e -U --ids-friendly --jsonfile-pretty tmp.json --severity LOW --color 0 badssl.com`;
$json_pretty = json('tmp.json');
unlink 'tmp.json';
$found = 0;
my $vulnerabilities = $json_pretty->{scanResult}->[0]->{vulnerabilities};
foreach my $f ( @$vulnerabilities ) {
if ( $f->{severity} eq "INFO" ) {
$found = 1;
last;
}
}
is($found,0,"We should not have any finding with INFO level"); $tests++;
printf "\n";
done_testing($tests);
sub json($) {
my $file = shift;
$file = `cat $file`;
unlink $file;
return from_json($file);
}