Skip to content

Commit 2b06c97

Browse files
committed
Add 0-RTT, more in line with other files
... and simplyfied
1 parent b1d79b6 commit 2b06c97

1 file changed

Lines changed: 47 additions & 20 deletions

File tree

t/10_baseline_ipv4_http.t

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env perl
22

3-
# baseline test for testssl, screen and JSON output
3+
# Baseline test for testssl, screen and JSON output
44

55
# We could also inspect the JSON for any problems for
66
# "id" : "scanProblem"
@@ -13,13 +13,11 @@ use JSON;
1313

1414
my $tests = 0;
1515
my $prg="./testssl.sh";
16-
my $tmp_json="tmp.json";
17-
my $check2run="-p -s -P --fs -S -h -U -q --ip=one --color 0 --jsonfile $tmp_json";
16+
my $json_file="";
17+
my $check2run="-p -s -P --fs -S -h -U -q --ip=one --color 0 --jsonfile";
1818
my $uri="google.com";
19-
my $socket_out="";
20-
my $openssl_out="";
21-
my $socket_json="";
22-
my $openssl_json="";
19+
my $terminal_out="";
20+
my $json_string="";
2321
#FIXME: Pattern we use to trigger an error, but likely we can skip that and instead we should?/could use the following??
2422
# @args="$prg $check2run $uri >/dev/null";
2523
# system("@args") == 0
@@ -34,35 +32,65 @@ STDOUT->autoflush(1);
3432
die "Unable to open $prg" unless -f $prg;
3533

3634
# Provide proper start conditions
37-
unlink $tmp_json;
35+
$json_file="tmp.json";
36+
unlink $json_file;
3837

3938
# Title
4039
printf "\n%s\n", "Baseline unit test IPv4 against \"$uri\"";
41-
$socket_out = `$prg $check2run $uri 2>&1`;
42-
$socket_json = json($tmp_json);
40+
41+
42+
# run the check
43+
$terminal_out = `$prg $check2run $json_file $uri 2>&1`;
44+
$json_string = json($json_file);
45+
4346

4447
#1
45-
unlike($socket_out, qr/$socket_errors/, "via sockets, checking terminal output");
48+
unlike($terminal_out, qr/$socket_errors/, "via sockets, checking terminal output");
4649
$tests++;
4750

4851
#2
49-
unlike($socket_json, qr/$json_errors/, "via sockets checking JSON output");
52+
unlike($json_string, qr/$json_errors/, "via sockets checking JSON output");
5053
$tests++;
51-
unlink $tmp_json;
54+
unlink $json_file;
5255

5356
#3
54-
$openssl_out = `$prg --ssl-native $check2run $uri 2>&1`;
55-
$openssl_json = json($tmp_json);
56-
unlike($openssl_out, qr/$openssl_errors/, "via (builtin) OpenSSL, checking terminal output");
57+
$terminal_out = `$prg --ssl-native $check2run $json_file $uri 2>&1`;
58+
$json_string = json($json_file);
59+
unlike($terminal_out, qr/$openssl_errors/, "via (builtin) OpenSSL, checking terminal output");
5760
$tests++;
5861

5962
#4
60-
unlike($openssl_json, qr/$json_errors/, "via OpenSSL (builtin) checking JSON output");
63+
unlike($json_string, qr/$json_errors/, "via OpenSSL (builtin) checking JSON output");
64+
$tests++;
65+
66+
#5 -- early data test. We just take the last check
67+
my $found=0;
68+
open my $fh, '<', $json_file or die "Can't open '$json_file': $!";
69+
local $/; # undef slurp mode
70+
my $data = decode_json(<$fh>);
71+
close $fh;
72+
73+
# Check if the decoded data is an array
74+
if (ref $data eq 'ARRAY') {
75+
# Iterate through the array of JSON objects
76+
foreach my $obj (@$data) {
77+
# Check if the 'id' is "early_data" and 'severity' is "HIGH"
78+
if ($obj->{id} eq 'early_data' && $obj->{severity} eq 'HIGH') {
79+
$found=1;
80+
last; # we can leave the loop
81+
}
82+
}
83+
}
84+
85+
if ($found) {
86+
ok(1, "0‑RTT found in JSON from $uri");
87+
} else {
88+
fail("0‑RTT test for $uri failed");
89+
}
6190
$tests++;
62-
unlink $tmp_json;
6391

6492
done_testing($tests);
65-
printf "\n";
93+
printf "\n\n";
6694

6795

6896
sub json($) {
@@ -72,6 +100,5 @@ sub json($) {
72100
return from_json($file);
73101
}
74102

75-
76103
# vim:ts=5:sw=5:expandtab
77104

0 commit comments

Comments
 (0)