Insert custom functions in locationRules test (#820)

This commit is contained in:
Xavier Guimard 2016-02-09 12:19:01 +00:00
parent 08b299f10f
commit bb710cead0
2 changed files with 32 additions and 6 deletions

View File

@ -669,7 +669,9 @@ qr/^(?:(?:https?):\/\/(?:(?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.
'type' => 'text'
},
'customFunctions' => {
'type' => 'text'
'msgFail' => '__badCustomFuncName__',
'test' => qr/^(?:\w+(?:\s+\w+)*)?$/,
'type' => 'text'
},
'dbiAuthChain' => {
'type' => 'text'
@ -1065,8 +1067,18 @@ qr/^(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-
},
'msgFail' => '__badExpression__',
'test' => sub {
my $s = $_[0];
my ( $val, $conf ) = @_;
my $s = $val;
$s =~ s/\b(accept|deny)\b/1/g;
if ( $conf->{'customFunctions'} ) {
foreach my $f (
split( /\s+/, $conf->{'customFunctions'}, 0 ) )
{
return 0, "__badCustomFuncName__ $f"
unless $f =~ /^\w+$/;
$s = "sub $f {1} $s";
}
}
eval $s;
return $@ ? ( 0, "__badExpression__: $@" ) : 1;
}

View File

@ -209,8 +209,13 @@ sub attributes {
default => 'post',
documentation => 'HTTP method for confirm page form',
},
customFunctions => { type => 'text', },
https => {
customFunctions => {
type => 'text',
test => qr/^(?:\w+(?:\s+\w+)*)?$/,
msgFail => "__badCustomFuncName__",
documentation => 'List of custom functions'
},
https => {
default => 0,
type => 'bool',
documentation => 'Use HTTPS for redirection from portal',
@ -864,12 +869,21 @@ sub attributes {
},
keyMsgFail => '__badRegexp__',
test => sub {
my $s = $_[0];
my ( $val, $conf ) = @_;
my $s = $val;
$s =~ s/\b(accept|deny)\b/1/g;
if ( $conf->{customFunctions} ) {
foreach my $f ( split /\s+/, $conf->{customFunctions} )
{
return ( 0, "__badCustomFuncName__ $f" )
unless ( $f =~ /^\w+$/ );
$s = "sub $f {1} $s";
}
}
eval $s;
return $@ ? ( 0, "__badExpression__: $@" ) : (1);
},
msgFail => '__badExpression__',
msgFail => '__badExpression__',
},
keyTest => qr/^$Regexp::Common::URI::RFC2396::hostname$/,
keyMsgFail => '__badHostname__',