11# !/usr/bin/env perl
22
3- # This is more a PoC. Improvements welcome!
3+ # Checking whether both JSON outputs are valid
44#
55
66use strict;
@@ -9,7 +9,8 @@ use JSON;
99
1010my $tests = 0;
1111my $prg =" ./testssl.sh" ;
12- my $json =" tmp.json" ;
12+ my $json =" " ;
13+ my $json_file =" " ;
1314my $check2run =" --ip=one --ids-friendly -q --color 0" ;
1415my $uri =" example.com" ; # Cloudflare blocks too often
1516my $out =" " ;
@@ -26,36 +27,37 @@ STDOUT->autoflush(1);
2627die " Unable to open $prg " unless -f $prg ;
2728
2829# Provide proper start conditions
29- unlink $json ;
30+ $json_file =" tmp.json" ;
31+ unlink $json_file ;
3032
3133# Title
3234printf " \n %s \n " , " Unit testing JSON output ..." ;
3335
3436# 1
3537printf " %s \n " , " .. plain JSON --> $uri " ;
36- $out = ` $prg $check2run --jsonfile tmp.json $uri ` ;
37- $json = json(' tmp.json ' );
38- unlink ' tmp.json ' ;
38+ $out = ` $prg $check2run --jsonfile $json_file $uri ` ;
39+ $json = json($json_file );
40+ unlink $json_file ;
3941my @errors =eval { decode_json($json ) };
4042is(@errors ,0," no errors" );
4143$tests ++;
4244
4345# 2
4446printf " %s \n " , " .. pretty JSON --> $uri " ;
45- $out = ` $prg $check2run --jsonfile-pretty tmp.json $uri ` ;
46- $json = json(' tmp.json ' );
47- unlink ' tmp.json ' ;
47+ $out = ` $prg $check2run --jsonfile-pretty $json_file $uri ` ;
48+ $json = json($json_file );
49+ unlink $json_file ;
4850@errors =eval { decode_json($json ) };
4951is(@errors ,0," no errors" );
5052$tests ++;
5153
5254
5355# 3
54- my $ uri = " smtp-relay.gmail.com:587" ;
56+ uri = " smtp-relay.gmail.com:587" ;
5557printf " %s \n " , " .. plain JSON and STARTTLS --> $uri ..." ;
56- $out = ` $prg --jsonfile tmp.json $check2run -t smtp $uri ` ;
57- $json = json(' tmp.json ' );
58- unlink ' tmp.json ' ;
58+ $out = ` $prg --jsonfile $json_file $check2run -t smtp $uri ` ;
59+ $json = json($json_file );
60+ unlink $json_file ;
5961@errors =eval { decode_json($json ) };
6062is(@errors ,0," no errors" );
6163$tests ++;
@@ -68,19 +70,19 @@ if ( $os eq "linux" ){
6870 # This testssl.sh run deliberately does NOT work as github actions block port 25 egress.
6971 # but the output should be fine. The idea is to have a unit test for a failed connection.
7072 printf " %s \n " , " .. plain JSON for a failed run: '--mx $uri ' ..." ;
71- $out = ` $prg --ssl-native --openssl-timeout=10 $check2run --jsonfile tmp.json --mx $uri ` ;
72- $json = json(' tmp.json ' );
73- unlink ' tmp.json ' ;
73+ $out = ` $prg --ssl-native --openssl-timeout=10 $check2run --jsonfile $json_file --mx $uri ` ;
74+ $json = json($json_file );
75+ unlink $json_file ;
7476 @errors =eval { decode_json($json ) };
7577 is(@errors ,0," no errors" );
7678 $tests ++;
7779
7880 # 5
7981 # Same as above but with pretty JSON
8082 printf " %s \n " , " .. pretty JSON for a failed run '--mx $uri ' ..." ;
81- $out = ` $prg --ssl-native --openssl-timeout=10 $check2run --jsonfile-pretty tmp.json --mx $uri ` ;
82- $json = json(' tmp.json ' );
83- unlink ' tmp.json ' ;
83+ $out = ` $prg --ssl-native --openssl-timeout=10 $check2run --jsonfile-pretty $json_file --mx $uri ` ;
84+ $json = json($json_file );
85+ unlink $json_file ;
8486 @errors =eval { decode_json($json ) };
8587 is(@errors ,0," no errors" );
8688 $tests ++;
@@ -90,7 +92,7 @@ if ( $os eq "linux" ){
9092}
9193
9294done_testing($tests );
93- printf " \n " ;
95+ printf " \n\n " ;
9496
9597sub json ($) {
9698 my $file = shift ;
0 commit comments