Skip to content

Commit 8e39d16

Browse files
committed
cleaner code
1 parent 0640eb9 commit 8e39d16

1 file changed

Lines changed: 23 additions & 20 deletions

File tree

t/10_baseline_ipv4_http.t

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,48 +15,51 @@ use JSON;
1515

1616
my $tests = 0;
1717
my $prg="./testssl.sh";
18-
my $check2run="-p -s -P --fs -S -h -U -q --ip=one --color 0";
18+
my $tmp_json="tmp.json";
19+
my $check2run="-p -s -P --fs -S -h -U -q --ip=one --color 0 --jsonfile $tmp_json";
1920
my $uri="google.com";
2021
my $socket_out="";
2122
my $openssl_out="";
22-
# Blacklists we use to trigger an error:
23-
my $socket_regex_bl='(e|E)rror|\.\/testssl\.sh: line |(f|F)atal|(c|C)ommand not found';
24-
my $openssl_regex_bl='(e|E)rror|(f|F)atal|\.\/testssl\.sh: line |Oops|s_client connect problem|(c|C)ommand not found';
25-
my $json_regex_bl='(id".*:\s"scanProblem"|severity".*:\s"FATAL"|"Scan interrupted")';
26-
2723
my $socket_json="";
2824
my $openssl_json="";
29-
$check2run="--jsonfile tmp.json $check2run";
25+
#FIXME: Blacklists we use to trigger an error, but likely we can skip that and instead we should?/could use
26+
# @args="$prg $check2run $uri >/dev/null";
27+
# system("@args") == 0
28+
# or die ("FAILED: \"@args\" ");
29+
my $socket_errors='(e|E)rror|\.\/testssl\.sh: line |(f|F)atal|(c|C)ommand not found';
30+
my $openssl_errors='(e|E)rror|(f|F)atal|\.\/testssl\.sh: line |Oops|s_client connect problem|(c|C)ommand not found';
31+
my $json_errors='(id".*:\s"scanProblem"|severity".*:\s"FATAL"|"Scan interrupted")';
32+
3033

3134
die "Unable to open $prg" unless -f $prg;
3235

3336
# Provide proper start conditions
34-
unlink "tmp.json";
37+
unlink $tmp_json;
3538

3639
# Title
3740
printf "\n%s\n", "Baseline unit test IPv4 against \"$uri\"";
3841

3942
#1
4043
$socket_out = `$prg $check2run $uri 2>&1`;
41-
$socket_json = json('tmp.json');
42-
unlink "tmp.json";
43-
unlike($socket_out, qr/$socket_regex_bl/, "via sockets, terminal output");
44+
$socket_json = json($tmp_json);
45+
unlike($socket_out, qr/$socket_errors/, "via sockets, checking terminal output");
4446
$tests++;
45-
unlike($socket_json, qr/$json_regex_bl/, "via sockets JSON output");
47+
unlike($socket_json, qr/$json_errors/, "via sockets checking JSON output");
4648
$tests++;
4749

50+
unlink $tmp_json;
51+
52+
4853
#2
4954
$openssl_out = `$prg --ssl-native $check2run $uri 2>&1`;
50-
$openssl_json = json('tmp.json');
51-
unlink "tmp.json";
52-
# With Google only we sometimes encounter an error as they return a 0 char with openssl, so we white list this pattern here:
53-
# It should be fixed in the code though so we comment this out
54-
# $openssl_out =~ s/testssl.*warning: command substitution: ignored null byte in input\n//g;
55-
unlike($openssl_out, qr/$openssl_regex_bl/, "via OpenSSL");
55+
$openssl_json = json($tmp_json);
56+
unlike($openssl_out, qr/$openssl_errors/, "via (builtin) OpenSSL, checking terminal output");
5657
$tests++;
57-
unlike($openssl_json, qr/$json_regex_bl/, "via OpenSSL JSON output");
58+
unlike($openssl_json, qr/$json_errors/, "via OpenSSL (builtin) checking JSON output");
5859
$tests++;
5960

61+
unlink $tmp_json;
62+
6063
done_testing($tests);
6164
printf "\n";
6265

@@ -69,5 +72,5 @@ sub json($) {
6972
}
7073

7174

72-
# vim:ts=5:sw=5:expandtab
75+
# vim:ts=5:sw=5:expandtab
7376

0 commit comments

Comments
 (0)