mirror of
https://github.com/drwetter/testssl.sh.git
synced 2025-12-10 09:14:00 +01:00
json and html unit tests more seamless
- html_file / json_file - file name comes in command, not earlier - Both a title - avoid fixed string for file names over and over
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
# This is more a PoC. Improvements welcome!
|
||||
# Checking whether both JSON outputs are valid
|
||||
#
|
||||
|
||||
use strict;
|
||||
@@ -9,7 +9,8 @@ use JSON;
|
||||
|
||||
my $tests = 0;
|
||||
my $prg="./testssl.sh";
|
||||
my $json="tmp.json";
|
||||
my $json="";
|
||||
my $json_file="";
|
||||
my $check2run ="--ip=one --ids-friendly -q --color 0";
|
||||
my $uri="example.com"; # Cloudflare blocks too often
|
||||
my $out="";
|
||||
@@ -26,36 +27,37 @@ STDOUT->autoflush(1);
|
||||
die "Unable to open $prg" unless -f $prg;
|
||||
|
||||
# Provide proper start conditions
|
||||
unlink $json;
|
||||
$json_file="tmp.json";
|
||||
unlink $json_file;
|
||||
|
||||
# Title
|
||||
printf "\n%s\n", "Unit testing JSON output ...";
|
||||
|
||||
#1
|
||||
printf "%s\n", ".. plain JSON --> $uri ";
|
||||
$out = `$prg $check2run --jsonfile tmp.json $uri`;
|
||||
$json = json('tmp.json');
|
||||
unlink 'tmp.json';
|
||||
$out = `$prg $check2run --jsonfile $json_file $uri`;
|
||||
$json = json($json_file);
|
||||
unlink $json_file;
|
||||
my @errors=eval { decode_json($json) };
|
||||
is(@errors,0,"no errors");
|
||||
$tests++;
|
||||
|
||||
#2
|
||||
printf "%s\n", ".. pretty JSON --> $uri ";
|
||||
$out = `$prg $check2run --jsonfile-pretty tmp.json $uri`;
|
||||
$json = json('tmp.json');
|
||||
unlink 'tmp.json';
|
||||
$out = `$prg $check2run --jsonfile-pretty $json_file $uri`;
|
||||
$json = json($json_file);
|
||||
unlink $json_file;
|
||||
@errors=eval { decode_json($json) };
|
||||
is(@errors,0,"no errors");
|
||||
$tests++;
|
||||
|
||||
|
||||
#3
|
||||
my $uri = "smtp-relay.gmail.com:587";
|
||||
uri = "smtp-relay.gmail.com:587";
|
||||
printf "%s\n", " .. plain JSON and STARTTLS --> $uri ...";
|
||||
$out = `$prg --jsonfile tmp.json $check2run -t smtp $uri`;
|
||||
$json = json('tmp.json');
|
||||
unlink 'tmp.json';
|
||||
$out = `$prg --jsonfile $json_file $check2run -t smtp $uri`;
|
||||
$json = json($json_file);
|
||||
unlink $json_file;
|
||||
@errors=eval { decode_json($json) };
|
||||
is(@errors,0,"no errors");
|
||||
$tests++;
|
||||
@@ -68,9 +70,9 @@ if ( $os eq "linux" ){
|
||||
# This testssl.sh run deliberately does NOT work as github actions block port 25 egress.
|
||||
# but the output should be fine. The idea is to have a unit test for a failed connection.
|
||||
printf "%s\n", ".. plain JSON for a failed run: '--mx $uri' ...";
|
||||
$out = `$prg --ssl-native --openssl-timeout=10 $check2run --jsonfile tmp.json --mx $uri`;
|
||||
$json = json('tmp.json');
|
||||
unlink 'tmp.json';
|
||||
$out = `$prg --ssl-native --openssl-timeout=10 $check2run --jsonfile $json_file --mx $uri`;
|
||||
$json = json($json_file);
|
||||
unlink $json_file;
|
||||
@errors=eval { decode_json($json) };
|
||||
is(@errors,0,"no errors");
|
||||
$tests++;
|
||||
@@ -78,9 +80,9 @@ if ( $os eq "linux" ){
|
||||
#5
|
||||
# Same as above but with pretty JSON
|
||||
printf "%s\n", ".. pretty JSON for a failed run '--mx $uri' ...";
|
||||
$out = `$prg --ssl-native --openssl-timeout=10 $check2run --jsonfile-pretty tmp.json --mx $uri`;
|
||||
$json = json('tmp.json');
|
||||
unlink 'tmp.json';
|
||||
$out = `$prg --ssl-native --openssl-timeout=10 $check2run --jsonfile-pretty $json_file --mx $uri`;
|
||||
$json = json($json_file);
|
||||
unlink $json_file;
|
||||
@errors=eval { decode_json($json) };
|
||||
is(@errors,0,"no errors");
|
||||
$tests++;
|
||||
@@ -90,7 +92,7 @@ if ( $os eq "linux" ){
|
||||
}
|
||||
|
||||
done_testing($tests);
|
||||
printf "\n";
|
||||
printf "\n\n";
|
||||
|
||||
sub json($) {
|
||||
my $file = shift;
|
||||
|
||||
Reference in New Issue
Block a user