mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-15 23:55:03 +03:00
Fix a bug in testing framework where NUL is lost in parameter and add support for running only a single test in a conf file.
This commit is contained in:
parent
246ed9cbc5
commit
9504be7d78
@ -323,7 +323,7 @@ int main(int argc, const char * const argv[])
|
|||||||
type = argv[1];
|
type = argv[1];
|
||||||
name = argv[2];
|
name = argv[2];
|
||||||
param_len = strlen(argv[3]);
|
param_len = strlen(argv[3]);
|
||||||
param = apr_pmemdup(g_mp, argv[3], param_len);
|
param = (unsigned char *)apr_pstrmemdup(g_mp, argv[3], param_len);
|
||||||
unescape_inplace(param, ¶m_len);
|
unescape_inplace(param, ¶m_len);
|
||||||
if (argc >= 5) {
|
if (argc >= 5) {
|
||||||
returnval = argv[4];
|
returnval = argv[4];
|
||||||
|
@ -1,4 +1,12 @@
|
|||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
|
#
|
||||||
|
# Run unit tests.
|
||||||
|
#
|
||||||
|
# Syntax:
|
||||||
|
# All: run-tests.pl
|
||||||
|
# All in file: run-tests.pl file
|
||||||
|
# Nth in file: run-tests.pl file N
|
||||||
|
#
|
||||||
use strict;
|
use strict;
|
||||||
use File::Basename qw(basename dirname);
|
use File::Basename qw(basename dirname);
|
||||||
|
|
||||||
@ -10,7 +18,7 @@ my $PASSED = 0;
|
|||||||
my $TOTAL = 0;
|
my $TOTAL = 0;
|
||||||
|
|
||||||
if (defined $ARGV[0]) {
|
if (defined $ARGV[0]) {
|
||||||
runfile(dirname($ARGV[0]), basename($ARGV[0]));
|
runfile(dirname($ARGV[0]), basename($ARGV[0]), $ARGV[1]);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +40,7 @@ done();
|
|||||||
|
|
||||||
|
|
||||||
sub runfile {
|
sub runfile {
|
||||||
my($dir, $cfg) = @_;
|
my($dir, $cfg, $testnum) = @_;
|
||||||
my $fn = "$dir/$cfg";
|
my $fn = "$dir/$cfg";
|
||||||
my @data = ();
|
my @data = ();
|
||||||
my $edata;
|
my $edata;
|
||||||
@ -54,8 +62,11 @@ sub runfile {
|
|||||||
|
|
||||||
msg("\nLoaded ".@C." tests from $fn");
|
msg("\nLoaded ".@C." tests from $fn");
|
||||||
for my $t (@C) {
|
for my $t (@C) {
|
||||||
|
$n++;
|
||||||
|
next if (defined $testnum and $n != $testnum);
|
||||||
|
|
||||||
my %t = %{$t || {}};
|
my %t = %{$t || {}};
|
||||||
my $id = sprintf("%6d", $n + 1);
|
my $id = sprintf("%6d", $n);
|
||||||
my $in = $t{input};
|
my $in = $t{input};
|
||||||
my $out = escape($t{output}); # Escape so we can send via commandline
|
my $out = escape($t{output}); # Escape so we can send via commandline
|
||||||
quit(1, "Failed to interpret output \"$cfg\": $@") if ($@);
|
quit(1, "Failed to interpret output \"$cfg\": $@") if ($@);
|
||||||
@ -76,7 +87,6 @@ sub runfile {
|
|||||||
print TEST "$in";
|
print TEST "$in";
|
||||||
close TEST;
|
close TEST;
|
||||||
|
|
||||||
$n++;
|
|
||||||
|
|
||||||
$rc = $?;
|
$rc = $?;
|
||||||
$pass += $rc ? 0 : 1;
|
$pass += $rc ? 0 : 1;
|
||||||
@ -84,10 +94,10 @@ sub runfile {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$TOTAL += $n;
|
$TOTAL += $testnum ? 1 : $n;
|
||||||
$PASSED += $pass;
|
$PASSED += $pass;
|
||||||
|
|
||||||
msg(sprintf("Passed: %2d; Failed %2d", $pass, ($n - $pass)));
|
msg(sprintf("Passed: %2d; Failed %2d", $pass, $testnum ? (1 - $pass) : ($n - $pass)));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub escape {
|
sub escape {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user