mirror of
https://github.com/drwetter/testssl.sh.git
synced 2025-12-09 08:44:01 +01:00
Add 0-RTT, more in line with other files
... and simplyfied
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
# baseline test for testssl, screen and JSON output
|
||||
# Baseline test for testssl, screen and JSON output
|
||||
|
||||
# We could also inspect the JSON for any problems for
|
||||
# "id" : "scanProblem"
|
||||
@@ -13,13 +13,11 @@ use JSON;
|
||||
|
||||
my $tests = 0;
|
||||
my $prg="./testssl.sh";
|
||||
my $tmp_json="tmp.json";
|
||||
my $check2run="-p -s -P --fs -S -h -U -q --ip=one --color 0 --jsonfile $tmp_json";
|
||||
my $json_file="";
|
||||
my $check2run="-p -s -P --fs -S -h -U -q --ip=one --color 0 --jsonfile";
|
||||
my $uri="google.com";
|
||||
my $socket_out="";
|
||||
my $openssl_out="";
|
||||
my $socket_json="";
|
||||
my $openssl_json="";
|
||||
my $terminal_out="";
|
||||
my $json_string="";
|
||||
#FIXME: Pattern we use to trigger an error, but likely we can skip that and instead we should?/could use the following??
|
||||
# @args="$prg $check2run $uri >/dev/null";
|
||||
# system("@args") == 0
|
||||
@@ -34,35 +32,65 @@ STDOUT->autoflush(1);
|
||||
die "Unable to open $prg" unless -f $prg;
|
||||
|
||||
# Provide proper start conditions
|
||||
unlink $tmp_json;
|
||||
$json_file="tmp.json";
|
||||
unlink $json_file;
|
||||
|
||||
# Title
|
||||
printf "\n%s\n", "Baseline unit test IPv4 against \"$uri\"";
|
||||
$socket_out = `$prg $check2run $uri 2>&1`;
|
||||
$socket_json = json($tmp_json);
|
||||
|
||||
|
||||
# run the check
|
||||
$terminal_out = `$prg $check2run $json_file $uri 2>&1`;
|
||||
$json_string = json($json_file);
|
||||
|
||||
|
||||
#1
|
||||
unlike($socket_out, qr/$socket_errors≈/, "via sockets, checking terminal output");
|
||||
unlike($terminal_out, qr/$socket_errors≈/, "via sockets, checking terminal output");
|
||||
$tests++;
|
||||
|
||||
#2
|
||||
unlike($socket_json, qr/$json_errors/, "via sockets checking JSON output");
|
||||
unlike($json_string, qr/$json_errors/, "via sockets checking JSON output");
|
||||
$tests++;
|
||||
unlink $tmp_json;
|
||||
unlink $json_file;
|
||||
|
||||
#3
|
||||
$openssl_out = `$prg --ssl-native $check2run $uri 2>&1`;
|
||||
$openssl_json = json($tmp_json);
|
||||
unlike($openssl_out, qr/$openssl_errors/, "via (builtin) OpenSSL, checking terminal output");
|
||||
$terminal_out = `$prg --ssl-native $check2run $json_file $uri 2>&1`;
|
||||
$json_string = json($json_file);
|
||||
unlike($terminal_out, qr/$openssl_errors/, "via (builtin) OpenSSL, checking terminal output");
|
||||
$tests++;
|
||||
|
||||
#4
|
||||
unlike($openssl_json, qr/$json_errors/, "via OpenSSL (builtin) checking JSON output");
|
||||
unlike($json_string, qr/$json_errors/, "via OpenSSL (builtin) checking JSON output");
|
||||
$tests++;
|
||||
|
||||
#5 -- early data test. We just take the last check
|
||||
my $found=0;
|
||||
open my $fh, '<', $json_file or die "Can't open '$json_file': $!";
|
||||
local $/; # undef slurp mode
|
||||
my $data = decode_json(<$fh>);
|
||||
close $fh;
|
||||
|
||||
# Check if the decoded data is an array
|
||||
if (ref $data eq 'ARRAY') {
|
||||
# Iterate through the array of JSON objects
|
||||
foreach my $obj (@$data) {
|
||||
# Check if the 'id' is "early_data" and 'severity' is "HIGH"
|
||||
if ($obj->{id} eq 'early_data' && $obj->{severity} eq 'HIGH') {
|
||||
$found=1;
|
||||
last; # we can leave the loop
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($found) {
|
||||
ok(1, "0‑RTT found in JSON from $uri");
|
||||
} else {
|
||||
fail("0‑RTT test for $uri failed");
|
||||
}
|
||||
$tests++;
|
||||
unlink $tmp_json;
|
||||
|
||||
done_testing($tests);
|
||||
printf "\n";
|
||||
printf "\n\n";
|
||||
|
||||
|
||||
sub json($) {
|
||||
@@ -72,6 +100,5 @@ sub json($) {
|
||||
return from_json($file);
|
||||
}
|
||||
|
||||
|
||||
# vim:ts=5:sw=5:expandtab
|
||||
|
||||
|
||||
Reference in New Issue
Block a user