mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-15 23:55:03 +03:00
More test updates.
This commit is contained in:
parent
2068357af8
commit
402f6318bb
@ -192,18 +192,26 @@ static int test_op(const char *name, const char *param, const unsigned char *inp
|
||||
var->value = apr_pstrmemdup(g_mp, (char *)input, input_len);
|
||||
var->value_len = input_len;
|
||||
var->metadata = msre_resolve_var(modsecurity->msre, var->name);
|
||||
if (var->metadata == NULL) {
|
||||
*errmsg = apr_psprintf(g_mp, "Failed to resolve variable for op \"%s\": %s", name, var->name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Initialize the operator parameter */
|
||||
rc = metadata->param_init(rule, errmsg);
|
||||
if (rc < 0) {
|
||||
*errmsg = apr_psprintf(g_mp, "Failed to init op \"%s\": %s", name, *errmsg);
|
||||
return rc;
|
||||
if (metadata->param_init != NULL) {
|
||||
rc = metadata->param_init(rule, errmsg);
|
||||
if (rc < 0) {
|
||||
*errmsg = apr_psprintf(g_mp, "Failed to init op \"%s\": %s", name, *errmsg);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
/* Execute the operator */
|
||||
rc = metadata->execute(g_msr, rule, var, errmsg);
|
||||
if (rc < 0) {
|
||||
*errmsg = apr_psprintf(g_mp, "Failed to execute op \"%s\": %s", name, *errmsg);
|
||||
if (metadata->execute != NULL) {
|
||||
rc = metadata->execute(g_msr, rule, var, errmsg);
|
||||
if (rc < 0) {
|
||||
*errmsg = apr_psprintf(g_mp, "Failed to execute op \"%s\": %s", name, *errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
|
@ -1 +1,45 @@
|
||||
### Empty
|
||||
{
|
||||
type => "op",
|
||||
name => "beginsWith",
|
||||
param => "",
|
||||
input => "",
|
||||
ret => 0,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "beginsWith",
|
||||
param => "TestCase",
|
||||
input => "",
|
||||
ret => 0,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "beginsWith",
|
||||
param => "",
|
||||
input => "TestCase",
|
||||
ret => 0,
|
||||
},
|
||||
|
||||
### General
|
||||
{
|
||||
type => "op",
|
||||
name => "beginsWith",
|
||||
param => "abcdef",
|
||||
input => "abcdef",
|
||||
ret => 1,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "beginsWith",
|
||||
param => "abcdef",
|
||||
input => "abcdefghi",
|
||||
ret => 1,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "beginsWith",
|
||||
param => "abcdef",
|
||||
input => "abc",
|
||||
ret => 0,
|
||||
},
|
||||
|
@ -1 +1,52 @@
|
||||
### Empty
|
||||
{
|
||||
type => "op",
|
||||
name => "contains",
|
||||
param => "",
|
||||
input => "",
|
||||
ret => 0,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "contains",
|
||||
param => "TestCase",
|
||||
input => "",
|
||||
ret => 0,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "contains",
|
||||
param => "",
|
||||
input => "TestCase",
|
||||
ret => 0,
|
||||
},
|
||||
|
||||
### General
|
||||
{
|
||||
type => "op",
|
||||
name => "contains",
|
||||
param => "abc",
|
||||
input => "abcdefghi",
|
||||
ret => 1,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "contains",
|
||||
param => "def",
|
||||
input => "abcdefghi",
|
||||
ret => 1,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "contains",
|
||||
param => "ghi",
|
||||
input => "abcdefghi",
|
||||
ret => 1,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "contains",
|
||||
param => "ghij",
|
||||
input => "abcdefghi",
|
||||
ret => 0,
|
||||
},
|
||||
|
@ -1 +1,80 @@
|
||||
### Empty
|
||||
{
|
||||
type => "op",
|
||||
name => "containsWord",
|
||||
param => "",
|
||||
input => "",
|
||||
ret => 0,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "containsWord",
|
||||
param => "TestCase",
|
||||
input => "",
|
||||
ret => 0,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "containsWord",
|
||||
param => "",
|
||||
input => "TestCase",
|
||||
ret => 0,
|
||||
},
|
||||
|
||||
### General
|
||||
{
|
||||
type => "op",
|
||||
name => "containsWord",
|
||||
param => "abc",
|
||||
input => "abcdefghi",
|
||||
ret => 0,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "containsWord",
|
||||
param => "def",
|
||||
input => "abcdefghi",
|
||||
ret => 0,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "containsWord",
|
||||
param => "ghi",
|
||||
input => "abcdefghi",
|
||||
ret => 0,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "containsWord",
|
||||
param => "abc",
|
||||
input => "abc def ghi",
|
||||
ret => 1,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "containsWord",
|
||||
param => "def",
|
||||
input => "abc def ghi",
|
||||
ret => 1,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "containsWord",
|
||||
param => "ghi",
|
||||
input => "abc def ghi",
|
||||
ret => 1,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "containsWord",
|
||||
param => "abc",
|
||||
input => "abc\0def ghi",
|
||||
ret => 1,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "containsWord",
|
||||
param => "def",
|
||||
input => "abc\0def ghi",
|
||||
ret => 1,
|
||||
},
|
||||
|
@ -1 +1,52 @@
|
||||
### Empty
|
||||
{
|
||||
type => "op",
|
||||
name => "endsWith",
|
||||
param => "",
|
||||
input => "",
|
||||
ret => 0,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "endsWith",
|
||||
param => "TestCase",
|
||||
input => "",
|
||||
ret => 0,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "endsWith",
|
||||
param => "",
|
||||
input => "TestCase",
|
||||
ret => 0,
|
||||
},
|
||||
|
||||
### General
|
||||
{
|
||||
type => "op",
|
||||
name => "endsWith",
|
||||
param => "abc",
|
||||
input => "abcdefghi",
|
||||
ret => 0,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "endsWith",
|
||||
param => "def",
|
||||
input => "abcdefghi",
|
||||
ret => 0,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "endsWith",
|
||||
param => "ghi",
|
||||
input => "abcdefghi",
|
||||
ret => 1,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "endsWith",
|
||||
param => "ghi",
|
||||
input => "abcdef\0ghi",
|
||||
ret => 1,
|
||||
},
|
||||
|
@ -1 +1,23 @@
|
||||
### Empty
|
||||
{
|
||||
type => "op",
|
||||
name => "noMatch",
|
||||
param => "",
|
||||
input => "",
|
||||
ret => 0,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "noMatch",
|
||||
param => "TestCase",
|
||||
input => "",
|
||||
ret => 0,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "noMatch",
|
||||
param => "",
|
||||
input => "TestCase",
|
||||
ret => 0,
|
||||
},
|
||||
|
||||
|
@ -1 +1,52 @@
|
||||
### Empty
|
||||
{
|
||||
type => "op",
|
||||
name => "within",
|
||||
param => "",
|
||||
input => "",
|
||||
ret => 0,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "within",
|
||||
param => "TestCase",
|
||||
input => "",
|
||||
ret => 0,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "within",
|
||||
param => "",
|
||||
input => "TestCase",
|
||||
ret => 0,
|
||||
},
|
||||
|
||||
### General
|
||||
{
|
||||
type => "op",
|
||||
name => "within",
|
||||
param => "abcdefghi",
|
||||
input => "abc",
|
||||
ret => 1,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "within",
|
||||
param => "abcdefghi",
|
||||
input => "def",
|
||||
ret => 1,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "within",
|
||||
param => "abcdefghi",
|
||||
input => "ghi",
|
||||
ret => 1,
|
||||
},
|
||||
{
|
||||
type => "op",
|
||||
name => "within",
|
||||
param => "abcdefghi",
|
||||
input => "ghij",
|
||||
ret => 0,
|
||||
},
|
||||
|
@ -8,6 +8,7 @@
|
||||
# Nth in file: run-tests.pl file N
|
||||
#
|
||||
use strict;
|
||||
use POSIX qw(WIFEXITED WEXITSTATUS WIFSIGNALED WTERMSIG);
|
||||
use File::Basename qw(basename dirname);
|
||||
|
||||
my @TYPES = qw(tfn op);
|
||||
@ -45,6 +46,8 @@ sub runfile {
|
||||
my @data = ();
|
||||
my $edata;
|
||||
my @C = ();
|
||||
my @test = ();
|
||||
my $teststr;
|
||||
my $n = 0;
|
||||
my $pass = 0;
|
||||
|
||||
@ -81,13 +84,30 @@ sub runfile {
|
||||
quit(1, "Unknown type \"$t{type}\" - should be one of: " . join(",",@TYPES));
|
||||
}
|
||||
|
||||
open(TEST, "|-", $TEST, $t{type}, $t{name}, $param, (exists($t{ret}) ? ($t{ret}) : ())) or quit(1, "Failed to execute test \"$cfg\": $!");
|
||||
@test = ($t{type}, $t{name}, $param, (exists($t{ret}) ? ($t{ret}) : ()));
|
||||
$teststr = "$TEST " . join(" ", map { "\"$_\"" } @test);
|
||||
open(TEST, "|-", $TEST, @test) or quit(1, "Failed to execute test: $teststr\": $!");
|
||||
print TEST "$in";
|
||||
close TEST;
|
||||
|
||||
|
||||
$rc = $?;
|
||||
$pass += $rc ? 0 : 1;
|
||||
if ( WIFEXITED($rc) ) {
|
||||
$rc = WEXITSTATUS($rc);
|
||||
}
|
||||
elsif( WIFSIGNALED($rc) ) {
|
||||
msg("Test exited with signal " . WTERMSIG($rc) . ".");
|
||||
msg("Executed: $teststr");
|
||||
$rc = -1;
|
||||
}
|
||||
else {
|
||||
msg("Test exited with unknown error.");
|
||||
$rc = -1;
|
||||
}
|
||||
|
||||
if ($rc == 0) {
|
||||
$pass++;
|
||||
}
|
||||
|
||||
msg(sprintf("%s) %s \"%s\": %s", $id, $t{type}, $t{name}, ($rc ? "failed" : "passed")));
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user