Merge pull request #1265 from drwetter/more_unittests1

Another (minor) step forwad for unit tests
This commit is contained in:
Dirk Wetter 2019-05-06 11:22:42 +02:00 committed by GitHub
commit c5d76fec27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 51 deletions

View File

@ -9,37 +9,43 @@ use strict;
use Test::More; use Test::More;
use Data::Dumper; 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 $tests = 0;
my $prg="./testssl.sh";
my $check2run ="-p -s -P --pfs -S -h -U -q --ip=one --color 0"; my $check2run ="-p -s -P --pfs -S -h -U -q --ip=one --color 0";
my $uri=""; my $uri="";
my $socketout=""; my $socket_out="";
my $opensslout=""; 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"; # $check2run="--jsonfile tmp.json $check2run";
die "Unable to open $prg" unless -f $prg;
$uri="google.com"; $uri="google.com";
unlink "tmp.json"; # unlink "tmp.json";
printf "\n%s\n", "Baseline unit test IPv4 via sockets --> $uri ..."; printf "\n%s\n", "Baseline unit test IPv4 via sockets --> $uri ...";
$socketout = `./testssl.sh $check2run $uri 2>&1`; $socket_out = `./testssl.sh $check2run $uri 2>&1`;
# my $socket = json('tmp.json'); # $socket_json = json('tmp.json');
unlike($socketout, qr/(e|E)rror|\.\/testssl\.sh: line |(f|F)atal/, ""); unlike($socket_out, qr/$socket_regex_bl/, "");
$tests++; $tests++;
# unlink "tmp.json";
unlink "tmp.json";
printf "\n%s\n", "Baseline unit test IPv4 via OpenSSL --> $uri ..."; printf "\n%s\n", "Baseline unit test IPv4 via OpenSSL --> $uri ...";
$opensslout = `./testssl.sh $check2run --ssl-native $uri 2>&1`; $openssl_out = `./testssl.sh --ssl-native $check2run $uri 2>&1`;
# my $openssl = json('tmp.json'); # $openssl_json = json('tmp.json');
# This happens with Google only, so we white list a pattern here: # With Google only we encounter an error as they return a 0 char with openssl, so we white list this pattern here:
$opensslout =~ s/testssl.*warning: command substitution: ignored null byte in input\n//g; $openssl_out =~ 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/, ""); unlike($openssl_out, qr/$openssl_regex_bl/, "");
$tests++; $tests++;
done_testing($tests); done_testing($tests);
unlink "tmp.json"; unlink "tmp.json";

View File

@ -11,33 +11,43 @@ use strict;
use Test::More; use Test::More;
use Data::Dumper; 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 $tests = 0;
my $prg="./testssl.sh";
my $check2run ="-p -s -P --pfs -S -h -U -q --ip=one --color 0"; my $check2run ="-p -s -P --pfs -S -h -U -q --ip=one --color 0";
my $uri=""; my $uri="";
my $socketout=""; my $socket_out="";
my $opensslout=""; 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"; # $check2run="--jsonfile tmp.json $check2run";
die "Unable to open $prg" unless -f $prg;
$uri="testssl.net"; $uri="testssl.net";
unlink "tmp.json"; # unlink "tmp.json";
printf "\n%s\n", "Baseline unit test IPv6 via sockets --> $uri ..."; printf "\n%s\n", "Baseline unit test IPv6 via sockets --> $uri ...";
$socketout = `./testssl.sh $check2run -6 $uri 2>&1`; $socket_out = `./testssl.sh $check2run -6 $uri 2>&1`;
# my $socket = json('tmp.json'); # $socket_json = json('tmp.json');
unlike($socketout, qr/(e|E)rror|\.\/testssl\.sh: line |(f|F)atal/, ""); unlike($socket_out, qr/$socket_regex_bl/, "");
$tests++; $tests++;
unlink "tmp.json"; # unlink "tmp.json";
printf "\n%s\n", "Baseline unit test IPv6 via OpenSSL --> $uri ..."; printf "\n%s\n", "Baseline unit test IPv6 via OpenSSL --> $uri ...";
$opensslout = `./testssl.sh --ssl-native $check2run -6 $uri 2>&1`; $openssl_out = `./testssl.sh --ssl-native $check2run -6 $uri 2>&1`;
# my $openssl = json('tmp.json'); # $openssl_json = json('tmp.json');
$opensslout =~ s/testssl.*warning: command substitution: ignored null byte in input\n//g; # With Google only we encounter an error as they return a 0 char with openssl, so we white list this pattern here:
unlike($opensslout, qr/(e|E)rror|(f|F)atal|\.\/testssl\.sh: line |Oops|s_client connect problem/, ""); $openssl_out =~ s/testssl.*warning: command substitution: ignored null byte in input\n//g;
unlike($openssl_out, qr/$openssl_regex_bl/, "");
$tests++; $tests++;
done_testing($tests); done_testing($tests);
unlink "tmp.json"; unlink "tmp.json";

View File

@ -8,51 +8,56 @@
use strict; use strict;
use Test::More; use Test::More;
use Data::Dumper; 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 $tests = 0;
my $prg="./testssl.sh";
my $check2run ="--client-simulation -q --ip=one --color 0"; my $check2run ="--client-simulation -q --ip=one --color 0";
my $uri=""; my $uri="";
my $socketout=""; my $socket_out="";
my $opensslout=""; 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"; # $check2run="--jsonfile tmp.json $check2run";
die "Unable to open $prg" unless -f $prg;
$uri="google.com"; $uri="google.com";
unlink "tmp.json"; # unlink "tmp.json";
printf "\n%s\n", "Client simulations unit test via sockets --> $uri ..."; printf "\n%s\n", "Client simulations unit test via sockets --> $uri ...";
$socketout = `./testssl.sh $check2run $uri`; $socket_out = `./testssl.sh $check2run $uri 2>&1`;
# my $socket = json('tmp.json'); # $socket_json = json('tmp.json');
#FIXME: This comparison is maybe not sufficient yet: unlike($socket_out, qr/$socket_regex_bl/, "");
unlike($socketout, qr/(e|E)rror|(f|F)atal/, "");
$tests++; $tests++;
# unlink "tmp.json";
unlink "tmp.json";
printf "\n%s\n", "Client simulations unit test via OpenSSL --> $uri ..."; printf "\n%s\n", "Client simulations unit test via OpenSSL --> $uri ...";
$opensslout = `./testssl.sh $check2run --ssl-native $uri`; $openssl_out = `./testssl.sh $check2run --ssl-native $uri 2>&1`;
# my $openssl = json('tmp.json'); # $openssl_json = json('tmp.json');
#FIXME: This comparison is maybe sufficient yet: unlike($openssl_out, qr/$openssl_regex_bl/, "");
unlike($opensslout, qr/(e|E)rror|(f|F)atal|Oops|s_client connect problem/, "");
$tests++; $tests++;
$uri="smtp-relay.gmail.com:587"; $uri="smtp-relay.gmail.com:587";
unlink "tmp.json"; # unlink "tmp.json";
printf "\n%s\n", "STARTTLS: Client simulations unit test via sockets --> $uri ..."; printf "\n%s\n", "STARTTLS: Client simulations unit test via sockets --> $uri ...";
$socketout = `./testssl.sh $check2run -t smtp $uri`; $socket_out = `./testssl.sh $check2run -t smtp $uri 2>&1`;
# my $socket = json('tmp.json'); # $socket_json = json('tmp.json');
unlike($socketout, qr/(e|E)rror|(f|F)atal/, ""); unlike($socket_out, qr/$socket_regex_bl/, "");
$tests++; $tests++;
unlink "tmp.json"; # unlink "tmp.json";
printf "\n%s\n", "STARTTLS: Client simulations unit test via OpenSSL --> $uri ..."; printf "\n%s\n", "STARTTLS: Client simulations unit test via OpenSSL --> $uri ...";
$opensslout = `./testssl.sh --ssl-native $check2run -t smtp $uri`; $openssl_out = `./testssl.sh --ssl-native $check2run -t smtp $uri 2>&1`;
# my $openssl = json('tmp.json'); # $openssl_json = json('tmp.json');
unlike($opensslout, qr/(e|E)rror|(f|F)atal|Oops|s_client connect problem/, ""); unlike($openssl_out, qr/$openssl_regex_bl/, "");
$tests++; $tests++;
done_testing($tests); done_testing($tests);

View File

@ -1,7 +1,9 @@
### Naming scheme ### Naming scheme
* 00-09: Is reporting ok * 00-09: Does the reporting work at all?
* 20-39: Do scans work fine (client side) * 20-39: Do scans work fine (client side)?
* 50-69: Are the results what I expect? (server 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.