More comments
This commit is contained in:
parent
16ec8d6d22
commit
8c4a26d0fe
|
@ -9,15 +9,28 @@ use Data::Dumper;
|
|||
|
||||
my $knownExceptions = qr/^(?:remoteCookieName)$/;
|
||||
|
||||
my @notManagedAttributes = qw(
|
||||
samlSPMetaDataOptions samlIDPMetaDataOptions
|
||||
oidcRPMetaDataOptions oidcOPMetaDataOptions
|
||||
cfgAuthor cfgAuthorIP cfgNum cfgDate cfgLog
|
||||
vhostOptions staticPrefix redirectFormMethod
|
||||
infoFormMethod activeTimer confirmFormMethod
|
||||
protection
|
||||
my @notManagedAttributes = (
|
||||
|
||||
# Complex nodes
|
||||
'samlSPMetaDataOptions', 'samlIDPMetaDataOptions', 'oidcRPMetaDataOptions',
|
||||
'oidcOPMetaDataOptions', 'vhostOptions',
|
||||
|
||||
# Metadatas (added by manager itself)
|
||||
'cfgAuthor', 'cfgAuthorIP', 'cfgNum', 'cfgDate', 'cfgLog',
|
||||
|
||||
# HTML template parameter (for PSGI) (must be set in lemonldap-ng.ini)
|
||||
'staticPrefix',
|
||||
|
||||
# Menu display parameters
|
||||
'redirectFormMethod', 'infoFormMethod', 'activeTimer', 'confirmFormMethod',
|
||||
|
||||
# PSGI/CGI protection (must be set in lemonldap-ng.ini)
|
||||
'protection',
|
||||
);
|
||||
|
||||
# 1 - Collect attributes
|
||||
|
||||
# Attributes.pm is parsed with open() and not loaded to detect double entries
|
||||
ok( open( F, 'lib/Lemonldap/NG/Manager/Build/Attributes.pm' ),
|
||||
'open attributes file' );
|
||||
my $count = 1;
|
||||
|
@ -35,13 +48,15 @@ while (<F>) {
|
|||
}
|
||||
close F;
|
||||
|
||||
# 2 - Parse Tree.pm
|
||||
use_ok('Lemonldap::NG::Manager::Build::Tree');
|
||||
use_ok('Lemonldap::NG::Manager::Build::CTrees');
|
||||
my $tree;
|
||||
ok( $tree = Lemonldap::NG::Manager::Build::Tree::tree(), 'Get tree' );
|
||||
$count += 3;
|
||||
|
||||
scanTree($tree);
|
||||
|
||||
# 3 - Parse CTrees.pm
|
||||
use_ok('Lemonldap::NG::Manager::Build::CTrees');
|
||||
ok( $tree = Lemonldap::NG::Manager::Build::CTrees::cTrees(),
|
||||
'Get conditional tree' );
|
||||
$count++;
|
||||
|
@ -49,57 +64,87 @@ foreach my $t ( values %$tree ) {
|
|||
scanTree($t);
|
||||
}
|
||||
|
||||
# 4 - Check that each leaf correspond to an attribute
|
||||
foreach ( keys %h2 ) {
|
||||
s/^\*//;
|
||||
ok( defined( $h{$_} ), "Leaf $_ exists in attributes" );
|
||||
delete $h{$_};
|
||||
$count++;
|
||||
}
|
||||
|
||||
# 5 - Check that attributes that must not be in manager tree are declared in
|
||||
# Attributes.pm
|
||||
foreach (@notManagedAttributes) {
|
||||
ok( defined( $h{$_} ), "Unmanaged attribute '$_' is declared" );
|
||||
delete $h{$_};
|
||||
$count++;
|
||||
}
|
||||
|
||||
# 6 - Verify that all attributes have been checked
|
||||
ok( !%h, "No remaining attributes" )
|
||||
or print STDERR Dumper( { 'Remaining attributes' => [ keys %h ] } );
|
||||
$count++;
|
||||
|
||||
done_testing($count);
|
||||
exit;
|
||||
|
||||
# 21 / 31 recursive search for leafs
|
||||
sub scanTree {
|
||||
my $tree = shift;
|
||||
if ( ref $tree ) {
|
||||
ok( ref($tree) eq 'ARRAY', 'Tree is an array' );
|
||||
$count++;
|
||||
foreach my $leaf (@$tree) {
|
||||
if ( ref $leaf ) {
|
||||
my $name;
|
||||
ok( $name = $leaf->{title}, "Node has a name" );
|
||||
ok( $name =~ /^\w+$/, "Name is a string" );
|
||||
ok( ref($leaf) eq 'HASH' );
|
||||
ok(
|
||||
(
|
||||
exists( $leaf->{nodes} )
|
||||
or exists( $leaf->{nodes_cond} )
|
||||
or exists( $leaf->{group} )
|
||||
),
|
||||
"Node $name has leafs"
|
||||
);
|
||||
$count += 4;
|
||||
foreach my $n (qw(nodes nodes_cond group)) {
|
||||
scanTree( $leaf->{$n} ) if ( exists $leaf->{$n} );
|
||||
}
|
||||
}
|
||||
elsif ( $leaf !~ $knownExceptions ) {
|
||||
ok( $leaf =~ /^\*?\w+/, "Leaf is an attribute name ($leaf)" );
|
||||
$h2{$leaf}++;
|
||||
ok( $h2{$leaf} == 1, "$leaf is uniq" );
|
||||
$count += 2;
|
||||
}
|
||||
else {
|
||||
$h2{$leaf}++;
|
||||
|
||||
# Lists of nodes must be arrays
|
||||
ok( ref($tree) eq 'ARRAY', 'Tree is an array' );
|
||||
$count++;
|
||||
foreach my $leaf (@$tree) {
|
||||
|
||||
# Scan if sub element is a node or a leaf
|
||||
|
||||
# Case 1: subnode
|
||||
if ( ref $leaf ) {
|
||||
|
||||
# Nodes must be hash
|
||||
ok( ref($leaf) eq 'HASH' );
|
||||
my $name;
|
||||
|
||||
# Nodes must have a title
|
||||
ok( $name = $leaf->{title}, "Node has a name" );
|
||||
ok( $name =~ /^\w+$/, "Name is a string" );
|
||||
|
||||
# Nodes must have leafs or subnodes
|
||||
ok(
|
||||
(
|
||||
exists( $leaf->{nodes} )
|
||||
or exists( $leaf->{nodes_cond} )
|
||||
or exists( $leaf->{group} )
|
||||
),
|
||||
"Node $name has leafs"
|
||||
);
|
||||
$count += 4;
|
||||
foreach my $n (qw(nodes nodes_cond group)) {
|
||||
|
||||
# Scan subnodes lists
|
||||
scanTree( $leaf->{$n} ) if ( exists $leaf->{$n} );
|
||||
}
|
||||
}
|
||||
|
||||
# Case 2: leaf
|
||||
|
||||
# Sub case 21: normal leaf
|
||||
elsif ( $leaf !~ $knownExceptions ) {
|
||||
|
||||
# Check that leaf corresponds to an attribute name
|
||||
ok( $leaf =~ /^\*?\w+/, "Leaf is an attribute name ($leaf)" );
|
||||
$h2{$leaf}++;
|
||||
|
||||
# Check that leaf appears for the first time
|
||||
ok( $h2{$leaf} == 1, "$leaf is uniq" );
|
||||
$count += 2;
|
||||
}
|
||||
|
||||
# Sub case 22: $knownExceptions contains leaf used more than one time
|
||||
# in tree
|
||||
else {
|
||||
$h2{$leaf}++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user