Start hash parameters test (#820)
This commit is contained in:
parent
7fc0e05371
commit
b59b728e6a
|
@ -240,7 +240,8 @@ sub attributes {
|
||||||
'type' => 'category'
|
'type' => 'category'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'type' => 'catAndAppList'
|
'keyTest' => qr/\w/,
|
||||||
|
'type' => 'catAndAppList'
|
||||||
},
|
},
|
||||||
'authChoiceModules' => {
|
'authChoiceModules' => {
|
||||||
'keyTest' => qr/^(\d*)?[a-zA-Z0-9_]+$/,
|
'keyTest' => qr/^(\d*)?[a-zA-Z0-9_]+$/,
|
||||||
|
@ -1408,7 +1409,8 @@ qr/^(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-
|
||||||
'loa-4' => 4,
|
'loa-4' => 4,
|
||||||
'loa-5' => 5
|
'loa-5' => 5
|
||||||
},
|
},
|
||||||
'type' => 'keyTextContainer'
|
'keyTest' => qr/\w/,
|
||||||
|
'type' => 'keyTextContainer'
|
||||||
},
|
},
|
||||||
'oidcServiceMetaDataAuthorizeURI' => {
|
'oidcServiceMetaDataAuthorizeURI' => {
|
||||||
'default' => 'authorize',
|
'default' => 'authorize',
|
||||||
|
|
|
@ -300,6 +300,7 @@ sub attributes {
|
||||||
},
|
},
|
||||||
applicationList => {
|
applicationList => {
|
||||||
type => 'catAndAppList',
|
type => 'catAndAppList',
|
||||||
|
keyTest => qr/\w/,
|
||||||
help => 'portalmenu.html#categories_and_applications',
|
help => 'portalmenu.html#categories_and_applications',
|
||||||
default => {
|
default => {
|
||||||
default => { catname => 'Default category', type => "category" }
|
default => { catname => 'Default category', type => "category" }
|
||||||
|
@ -2103,6 +2104,7 @@ m{^(?:ldapi://[^/]*/?|\w[\w\-\.]*(?::\d{1,5})?|ldap(?:s|\+tls)?://\w[\w\-\.]*(?:
|
||||||
},
|
},
|
||||||
oidcServiceMetaDataAuthnContext => {
|
oidcServiceMetaDataAuthnContext => {
|
||||||
type => 'keyTextContainer',
|
type => 'keyTextContainer',
|
||||||
|
keyTest => qr/\w/,
|
||||||
default => {
|
default => {
|
||||||
'loa-1' => 1,
|
'loa-1' => 1,
|
||||||
'loa-2' => 2,
|
'loa-2' => 2,
|
||||||
|
|
|
@ -828,7 +828,28 @@ sub _unitTest {
|
||||||
$res = 0;
|
$res = 0;
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Hash parameters
|
||||||
|
if ( $key =~ $simpleHashKeys or $attr->{type} =~ /Container$/ ) {
|
||||||
|
$conf->{$key} //= {};
|
||||||
|
unless ( ref $conf->{$key} eq 'HASH' ) {
|
||||||
|
push @{ $self->errors },
|
||||||
|
{ message => "$key is not a hash ref" };
|
||||||
|
$res = 0;
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
}
|
||||||
if ( $key =~ $simpleHashKeys ) {
|
if ( $key =~ $simpleHashKeys ) {
|
||||||
|
foreach my $k ( keys %{ $conf->{$key} } ) {
|
||||||
|
my $keyMsg = $attr->{keyMsgFail} // $type->{keyMsgFail}
|
||||||
|
// 'Bad hash key';
|
||||||
|
$res = 0
|
||||||
|
unless $self->_execTest( $attr->{keyTest}
|
||||||
|
// $type->{keyTest} // qr/^\w+$/,
|
||||||
|
$k, "$key/$k", $attr, $keyMsg, $conf );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elsif ( $attr->{type} =~ /Container$/ ) {
|
||||||
|
|
||||||
#TODO
|
#TODO
|
||||||
}
|
}
|
||||||
|
@ -836,53 +857,46 @@ sub _unitTest {
|
||||||
|
|
||||||
#TODO
|
#TODO
|
||||||
}
|
}
|
||||||
elsif ( $attr->{type} =~ /Container$/ ) {
|
|
||||||
|
|
||||||
#TODO
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
die "Unkown type $attr->{type}"
|
die "Unkown type $attr->{type}"
|
||||||
unless ( $type = $types->{ $attr->{type} } );
|
unless ( $type = $types->{ $attr->{type} } );
|
||||||
my $test = $attr->{test} // $type->{test};
|
my $msg = $attr->{msgFail} // $type->{msgFail};
|
||||||
my $msg = $attr->{msgFail} // $type->{msgFail};
|
$res = 0
|
||||||
if ( my $ref = ref($test) ) {
|
unless (
|
||||||
if ( $ref eq 'CODE' ) {
|
$self->_execTest(
|
||||||
my ( $r, $w ) =
|
$attr->{test} // $type->{test},
|
||||||
$test->( $conf->{$key}, $conf, $attr );
|
$conf->{$key}, $key, $attr, $msg, $conf
|
||||||
unless ($r) {
|
)
|
||||||
push @{ $self->errors },
|
);
|
||||||
{ message => "$key: " . ( $w ? $w : $msg ) };
|
|
||||||
$res = 0;
|
|
||||||
}
|
|
||||||
elsif ($w) {
|
|
||||||
push @{ $self->warnings },
|
|
||||||
{ message => "$key: $w" };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
elsif ( $ref eq 'Regexp' ) {
|
|
||||||
die "msgFail undefined for type \"$attr->{type}\""
|
|
||||||
unless ( defined $msg );
|
|
||||||
unless ( $conf->{$key} =~ $test ) {
|
|
||||||
push @{ $self->errors },
|
|
||||||
{ message => "$key: $msg ($conf->{$key})" };
|
|
||||||
$res = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
die
|
|
||||||
"Malformed test: only regexp ref or sub are accepted (type \"$ref\")";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
die
|
|
||||||
"Malformed test: only regexp ref or sub are accepted (\"$test\")";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
##@method private boolean _execTest($test, $value)
|
||||||
|
# Execute the given test with value
|
||||||
|
#@param test that can be a code-ref, or a regexp
|
||||||
|
#@return result of test
|
||||||
|
sub _execTest {
|
||||||
|
my ( $self, $test, $value, $key, $attr, $msg, $conf ) = @_;
|
||||||
|
my $ref;
|
||||||
|
die "Malformed test: only regexp ref or sub are accepted (type \"$ref\")"
|
||||||
|
unless ( $ref = ref($test) and $ref =~ /^(CODE|Regexp)$/ );
|
||||||
|
if ( $1 eq 'CODE' ) {
|
||||||
|
my ( $r, $m ) = ( $test->( $value, $conf, $attr ) );
|
||||||
|
push @{ $self->{ ( $r ? 'warnings' : 'error' ) } },
|
||||||
|
{ message => "$key: $m" }
|
||||||
|
if ($m);
|
||||||
|
return $r;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
my $r = $value =~ $test;
|
||||||
|
push @{ $self->errors }, { message => "$key: $msg" } unless ($r);
|
||||||
|
return $r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
##@method private boolean _globalTest()
|
##@method private boolean _globalTest()
|
||||||
# Launch all tests declared in Lemonldap::NG::Manager::Conf::Tests::tests()
|
# Launch all tests declared in Lemonldap::NG::Manager::Conf::Tests::tests()
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in New Issue
Block a user