From 7e79007a2b5b9ed61e87607a9c0c2675ad1c25dd Mon Sep 17 00:00:00 2001 From: Xavier Guimard Date: Thu, 7 Jan 2016 06:13:14 +0000 Subject: [PATCH] Verify that node titles are not attribute names --- lemonldap-ng-manager/t/80-attributes.t | 35 ++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/lemonldap-ng-manager/t/80-attributes.t b/lemonldap-ng-manager/t/80-attributes.t index a04dd1b23..c836b8234 100644 --- a/lemonldap-ng-manager/t/80-attributes.t +++ b/lemonldap-ng-manager/t/80-attributes.t @@ -7,8 +7,14 @@ use strict; use Test::More; use Data::Dumper; -my $knownExceptions = qr/^(?:remoteCookieName)$/; +# CONSTANTS +# Node names used more than one time +my $usedMoreThanOneTimeInTree = qr/^(?: + remoteCookieName +)$/x; + +# Attributes not managed in web interface my @notManagedAttributes = ( # Complex nodes @@ -28,6 +34,17 @@ my @notManagedAttributes = ( 'protection', ); +# Words used either as attribute name and node title +my $doubleUsage = qr/^(?: + samlSPMetaDataOptions| + samlIDPMetaDataOptions| + oidcRPMetaDataOptions| + oidcOPMetaDataOptions| + vhostOptions +)$/x; + +# TESTS + # 1 - Collect attributes # Attributes.pm is parsed with open() and not loaded to detect double entries @@ -120,6 +137,14 @@ sub scanTree { "Node $name has leafs" ); $count += 4; + + # Nodes must not use attributes name + unless ( $name =~ $doubleUsage ) { + ok( !exists( $h{$name} ), + "Node title ($name) must not be used as attribute name" ); + $count++; + } + foreach my $n (qw(nodes nodes_cond group)) { # Scan subnodes lists @@ -130,9 +155,9 @@ sub scanTree { # Case 2: leaf # Sub case 21: normal leaf - elsif ( $leaf !~ $knownExceptions ) { + elsif ( $leaf !~ $usedMoreThanOneTimeInTree ) { - # Check that leaf corresponds to an attribute name + # Check that leaf is a string ok( $leaf =~ /^\*?\w+/, "Leaf is an attribute name ($leaf)" ); $h2{$leaf}++; @@ -141,8 +166,8 @@ sub scanTree { $count += 2; } - # Sub case 22: $knownExceptions contains leaf used more than one time - # in tree + # Sub case 22: $usedMoreThanOneTimeInTree contains leaf used more than + # one time in tree else { $h2{$leaf}++; }