diff --git a/t/20_baseline_ipv4_http.t b/t/20_baseline_ipv4_http.t index 4caf1b6..3e0bba3 100755 --- a/t/20_baseline_ipv4_http.t +++ b/t/20_baseline_ipv4_http.t @@ -9,37 +9,43 @@ use strict; use Test::More; use Data::Dumper; # use JSON; +# if we need JSON we need to comment this and the lines below in my $tests = 0; +my $prg="./testssl.sh"; my $check2run ="-p -s -P --pfs -S -h -U -q --ip=one --color 0"; my $uri=""; -my $socketout=""; -my $opensslout=""; +my $socket_out=""; +my $openssl_out=""; +# Blacklists we use to trigger an error: +my $socket_regex_bl='(e|E)rror|\.\/testssl\.sh: line |(f|F)atal'; +my $openssl_regex_bl='(e|E)rror|(f|F)atal|\.\/testssl\.sh: line |Oops|s_client connect problem'; +# my $socket_json=""; +# my $openssl_json=""; # $check2run="--jsonfile tmp.json $check2run"; +die "Unable to open $prg" unless -f $prg; $uri="google.com"; -unlink "tmp.json"; +# unlink "tmp.json"; printf "\n%s\n", "Baseline unit test IPv4 via sockets --> $uri ..."; -$socketout = `./testssl.sh $check2run $uri 2>&1`; -# my $socket = json('tmp.json'); -unlike($socketout, qr/(e|E)rror|\.\/testssl\.sh: line |(f|F)atal/, ""); +$socket_out = `./testssl.sh $check2run $uri 2>&1`; +# $socket_json = json('tmp.json'); +unlike($socket_out, qr/$socket_regex_bl/, ""); $tests++; - -unlink "tmp.json"; +# unlink "tmp.json"; printf "\n%s\n", "Baseline unit test IPv4 via OpenSSL --> $uri ..."; -$opensslout = `./testssl.sh $check2run --ssl-native $uri 2>&1`; -# my $openssl = json('tmp.json'); -# This happens with Google only, so we white list a pattern here: -$opensslout =~ s/testssl.*warning: command substitution: ignored null byte in input\n//g; -unlike($opensslout, qr/(e|E)rror|(f|F)atal|\.\/testssl\.sh: line |Oops|s_client connect problem/, ""); +$openssl_out = `./testssl.sh --ssl-native $check2run $uri 2>&1`; +# $openssl_json = json('tmp.json'); +# With Google only we encounter an error as they return a 0 char with openssl, so we white list this pattern here: +$openssl_out =~ s/testssl.*warning: command substitution: ignored null byte in input\n//g; +unlike($openssl_out, qr/$openssl_regex_bl/, ""); $tests++; - done_testing($tests); unlink "tmp.json"; diff --git a/t/21_baseline_ipv6_http.t.DISABLED b/t/21_baseline_ipv6_http.t.DISABLED index d98fc90..f8ff53b 100755 --- a/t/21_baseline_ipv6_http.t.DISABLED +++ b/t/21_baseline_ipv6_http.t.DISABLED @@ -11,33 +11,43 @@ use strict; use Test::More; use Data::Dumper; # use JSON; +# if we need JSON we need to comment this and the lines below in my $tests = 0; +my $prg="./testssl.sh"; my $check2run ="-p -s -P --pfs -S -h -U -q --ip=one --color 0"; my $uri=""; -my $socketout=""; -my $opensslout=""; +my $socket_out=""; +my $openssl_out=""; +# Blacklists we use to trigger an error: +my $socket_regex_bl='(e|E)rror|\.\/testssl\.sh: line |(f|F)atal'; +my $openssl_regex_bl='(e|E)rror|(f|F)atal|\.\/testssl\.sh: line |Oops|s_client connect problem'; +# my $socket_json=""; +# my $openssl_json=""; # $check2run="--jsonfile tmp.json $check2run"; +die "Unable to open $prg" unless -f $prg; $uri="testssl.net"; -unlink "tmp.json"; +# unlink "tmp.json"; printf "\n%s\n", "Baseline unit test IPv6 via sockets --> $uri ..."; -$socketout = `./testssl.sh $check2run -6 $uri 2>&1`; -# my $socket = json('tmp.json'); -unlike($socketout, qr/(e|E)rror|\.\/testssl\.sh: line |(f|F)atal/, ""); +$socket_out = `./testssl.sh $check2run -6 $uri 2>&1`; +# $socket_json = json('tmp.json'); +unlike($socket_out, qr/$socket_regex_bl/, ""); $tests++; -unlink "tmp.json"; +# unlink "tmp.json"; printf "\n%s\n", "Baseline unit test IPv6 via OpenSSL --> $uri ..."; -$opensslout = `./testssl.sh --ssl-native $check2run -6 $uri 2>&1`; -# my $openssl = json('tmp.json'); -$opensslout =~ s/testssl.*warning: command substitution: ignored null byte in input\n//g; -unlike($opensslout, qr/(e|E)rror|(f|F)atal|\.\/testssl\.sh: line |Oops|s_client connect problem/, ""); +$openssl_out = `./testssl.sh --ssl-native $check2run -6 $uri 2>&1`; +# $openssl_json = json('tmp.json'); +# With Google only we encounter an error as they return a 0 char with openssl, so we white list this pattern here: +$openssl_out =~ s/testssl.*warning: command substitution: ignored null byte in input\n//g; +unlike($openssl_out, qr/$openssl_regex_bl/, ""); $tests++; + done_testing($tests); unlink "tmp.json"; diff --git a/t/23_client_simulation.t b/t/23_client_simulation.t index c00c7e5..60ab990 100755 --- a/t/23_client_simulation.t +++ b/t/23_client_simulation.t @@ -8,51 +8,56 @@ use strict; use Test::More; use Data::Dumper; -use JSON; +# use JSON; +# if we need JSON we need to comment this and the lines below in my $tests = 0; +my $prg="./testssl.sh"; my $check2run ="--client-simulation -q --ip=one --color 0"; my $uri=""; -my $socketout=""; -my $opensslout=""; +my $socket_out=""; +my $openssl_out=""; +# Blacklists we use to trigger an error: +my $socket_regex_bl='(e|E)rror|\.\/testssl\.sh: line |(f|F)atal'; +my $openssl_regex_bl='(e|E)rror|(f|F)atal|\.\/testssl\.sh: line |Oops|s_client connect problem'; +# my $socket_json=""; +# my $openssl_json=""; # $check2run="--jsonfile tmp.json $check2run"; +die "Unable to open $prg" unless -f $prg; $uri="google.com"; -unlink "tmp.json"; +# unlink "tmp.json"; printf "\n%s\n", "Client simulations unit test via sockets --> $uri ..."; -$socketout = `./testssl.sh $check2run $uri`; -# my $socket = json('tmp.json'); -#FIXME: This comparison is maybe not sufficient yet: -unlike($socketout, qr/(e|E)rror|(f|F)atal/, ""); +$socket_out = `./testssl.sh $check2run $uri 2>&1`; +# $socket_json = json('tmp.json'); +unlike($socket_out, qr/$socket_regex_bl/, ""); $tests++; - -unlink "tmp.json"; +# unlink "tmp.json"; printf "\n%s\n", "Client simulations unit test via OpenSSL --> $uri ..."; -$opensslout = `./testssl.sh $check2run --ssl-native $uri`; -# my $openssl = json('tmp.json'); -#FIXME: This comparison is maybe sufficient yet: -unlike($opensslout, qr/(e|E)rror|(f|F)atal|Oops|s_client connect problem/, ""); +$openssl_out = `./testssl.sh $check2run --ssl-native $uri 2>&1`; +# $openssl_json = json('tmp.json'); +unlike($openssl_out, qr/$openssl_regex_bl/, ""); $tests++; $uri="smtp-relay.gmail.com:587"; -unlink "tmp.json"; +# unlink "tmp.json"; printf "\n%s\n", "STARTTLS: Client simulations unit test via sockets --> $uri ..."; -$socketout = `./testssl.sh $check2run -t smtp $uri`; -# my $socket = json('tmp.json'); -unlike($socketout, qr/(e|E)rror|(f|F)atal/, ""); +$socket_out = `./testssl.sh $check2run -t smtp $uri 2>&1`; +# $socket_json = json('tmp.json'); +unlike($socket_out, qr/$socket_regex_bl/, ""); $tests++; -unlink "tmp.json"; +# unlink "tmp.json"; printf "\n%s\n", "STARTTLS: Client simulations unit test via OpenSSL --> $uri ..."; -$opensslout = `./testssl.sh --ssl-native $check2run -t smtp $uri`; -# my $openssl = json('tmp.json'); -unlike($opensslout, qr/(e|E)rror|(f|F)atal|Oops|s_client connect problem/, ""); +$openssl_out = `./testssl.sh --ssl-native $check2run -t smtp $uri 2>&1`; +# $openssl_json = json('tmp.json'); +unlike($openssl_out, qr/$openssl_regex_bl/, ""); $tests++; done_testing($tests); diff --git a/t/Readme.md b/t/Readme.md index 123b395..7cfb01e 100644 --- a/t/Readme.md +++ b/t/Readme.md @@ -1,7 +1,9 @@ ### Naming scheme -* 00-09: Is reporting ok -* 20-39: Do scans work fine (client side) -* 50-69: Are the results what I expect? (server side) +* 00-09: Does the reporting work at all? +* 20-39: Do scans work fine (client side)? +* 50-69: Are the results what I expect (server side)? -Please help to write Travis/CI tests! Documentation can be found [here](https://perldoc.perl.org/Test/More.html) and consulting the existing code (e.g. 20_baseline_ipv4_http.t) +Please help to write Travis/CI tests! Documentation can be found [here](https://perldoc.perl.org/Test/More.html). +You can consult the existing code here. Feel free to use `20_baseline_ipv4_http.t` or `23_client_simulation.t` as a +template.