2019-04-15 10:34:03 +02:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
# This is more a PoC. Improvements welcome!
|
|
|
|
#
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Test::More;
|
|
|
|
use JSON;
|
2019-08-12 12:25:54 +02:00
|
|
|
|
|
|
|
my $tests = 0;
|
|
|
|
my $prg="./testssl.sh";
|
2020-11-27 13:19:52 +01:00
|
|
|
my $check2run ="--ip=one --ids-friendly -q --color 0";
|
2019-08-12 12:25:54 +02:00
|
|
|
my $uri="";
|
|
|
|
my $json="";
|
|
|
|
my $out="";
|
|
|
|
# Blacklists we use to trigger an error:
|
2020-11-26 13:41:44 +01:00
|
|
|
my $socket_regex_bl='(e|E)rror|\.\/testssl\.sh: line |(f|F)atal|(c|C)ommand not found';
|
|
|
|
my $openssl_regex_bl='(e|E)rror|(f|F)atal|\.\/testssl\.sh: line |Oops|s_client connect problem|(c|C)ommand not found';
|
2019-08-12 12:25:54 +02:00
|
|
|
|
|
|
|
die "Unable to open $prg" unless -f $prg;
|
|
|
|
|
|
|
|
my $uri="cloudflare.com";
|
2019-04-15 10:34:03 +02:00
|
|
|
|
2020-01-14 18:44:11 +01:00
|
|
|
printf "\n%s\n", "Unit testing JSON output ...";
|
2020-01-18 21:47:44 +01:00
|
|
|
unlink 'tmp.json';
|
2020-01-13 23:50:14 +01:00
|
|
|
|
2019-04-15 10:34:03 +02:00
|
|
|
#1
|
2020-01-14 18:44:11 +01:00
|
|
|
printf "%s\n", ".. plain JSON --> $uri ";
|
2019-08-12 12:25:54 +02:00
|
|
|
$out = `./testssl.sh $check2run --jsonfile tmp.json $uri`;
|
2019-04-15 10:34:03 +02:00
|
|
|
$json = json('tmp.json');
|
|
|
|
unlink 'tmp.json';
|
2019-08-12 12:25:54 +02:00
|
|
|
my @errors=eval { decode_json($json) };
|
|
|
|
is(@errors,0,"no errors");
|
|
|
|
$tests++;
|
2019-04-15 10:34:03 +02:00
|
|
|
|
|
|
|
#2
|
2020-01-14 18:44:11 +01:00
|
|
|
printf "%s\n", ".. pretty JSON --> $uri ";
|
2019-08-12 12:25:54 +02:00
|
|
|
$out = `./testssl.sh $check2run --jsonfile-pretty tmp.json $uri`;
|
|
|
|
$json = json('tmp.json');
|
|
|
|
unlink 'tmp.json';
|
|
|
|
@errors=eval { decode_json($json) };
|
2019-04-15 10:34:03 +02:00
|
|
|
is(@errors,0,"no errors");
|
|
|
|
$tests++;
|
|
|
|
|
2019-08-12 12:25:54 +02:00
|
|
|
|
2019-04-15 10:34:03 +02:00
|
|
|
#3
|
2020-11-27 13:19:52 +01:00
|
|
|
# This testssl.sh run deliberately does NOT work as travis-ci.org blocks port 25 egress.
|
2019-08-12 12:25:54 +02:00
|
|
|
# but the output should be fine. The idea is to have a unit test for a failed connection.
|
2020-01-14 18:44:11 +01:00
|
|
|
printf "%s\n", ".. plain JSON for a failed run: '--mx $uri' ...";
|
2019-08-12 12:25:54 +02:00
|
|
|
$out = `./testssl.sh --ssl-native --openssl-timeout=10 $check2run --jsonfile tmp.json --mx $uri`;
|
2019-04-15 10:34:03 +02:00
|
|
|
$json = json('tmp.json');
|
|
|
|
unlink 'tmp.json';
|
2019-08-12 12:25:54 +02:00
|
|
|
@errors=eval { decode_json($json) };
|
|
|
|
is(@errors,0,"no errors");
|
|
|
|
$tests++;
|
2019-04-15 10:34:03 +02:00
|
|
|
|
|
|
|
#4
|
2019-08-12 12:25:54 +02:00
|
|
|
# Same as above but with pretty JSON
|
2020-01-14 18:44:11 +01:00
|
|
|
printf "%s\n", ".. pretty JSON for a failed run '--mx $uri' ...";
|
2019-08-12 12:25:54 +02:00
|
|
|
$out = `./testssl.sh --ssl-native --openssl-timeout=10 $check2run --jsonfile-pretty tmp.json --mx $uri`;
|
|
|
|
$json = json('tmp.json');
|
|
|
|
unlink 'tmp.json';
|
|
|
|
@errors=eval { decode_json($json) };
|
2019-04-15 10:34:03 +02:00
|
|
|
is(@errors,0,"no errors");
|
|
|
|
$tests++;
|
|
|
|
|
2019-04-17 09:04:39 +02:00
|
|
|
#5
|
2019-08-12 12:25:54 +02:00
|
|
|
my $uri = "smtp-relay.gmail.com:587";
|
2020-01-14 18:44:11 +01:00
|
|
|
printf "%s\n", " .. plain JSON and STARTTLS --> $uri ...";
|
2019-08-12 12:25:54 +02:00
|
|
|
$out = `./testssl.sh --jsonfile tmp.json $check2run -t smtp $uri`;
|
2019-04-17 09:04:39 +02:00
|
|
|
$json = json('tmp.json');
|
|
|
|
unlink 'tmp.json';
|
2019-08-12 12:25:54 +02:00
|
|
|
@errors=eval { decode_json($json) };
|
2019-04-17 09:04:39 +02:00
|
|
|
is(@errors,0,"no errors");
|
|
|
|
$tests++;
|
|
|
|
|
2020-01-14 18:44:11 +01:00
|
|
|
printf "\n";
|
2019-04-15 10:34:03 +02:00
|
|
|
done_testing($tests);
|
|
|
|
|
|
|
|
sub json($) {
|
|
|
|
my $file = shift;
|
|
|
|
$file = `cat $file`;
|
|
|
|
return from_json($file);
|
|
|
|
}
|
|
|
|
|
|
|
|
|