From 876c420ed5d6d795fab7df2ef92dffb6b2fd8dc9 Mon Sep 17 00:00:00 2001 From: Xavier Guimard Date: Mon, 4 Jan 2016 20:43:15 +0000 Subject: [PATCH] Update tests --- .../lib/Lemonldap/NG/Manager/Attributes.pm | 40 ++++++++++++++----- .../Lemonldap/NG/Manager/Build/Attributes.pm | 33 ++++++++++----- lemonldap-ng-manager/t/20-test-coverage.t | 2 +- 3 files changed, 55 insertions(+), 20 deletions(-) diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Attributes.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Attributes.pm index d0ff803ae..c0a8d028e 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Attributes.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Attributes.pm @@ -55,6 +55,12 @@ qr/^(?:(?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a- 'msgFail' => '__badValue__', 'test' => qr/^.*$/ }, + 'keyTextContainer' => { + 'keyMsgFail' => 'Bad key name', + 'keyTest' => qr/^\w[\w\.\-]*$/, + 'msgFail' => 'Empty value non accorded', + 'test' => qr/./ + }, 'lmAttrOrMacro' => { 'form' => 'text', 'test' => sub { @@ -175,12 +181,18 @@ qr/^(?:(?:\-+\s*BEGIN\s+PUBLIC\s+KEY\s*\-+\r?\n)?[a-zA-Z0-9\/\+\r\n]+={0,2}(?:\r 'test' => sub { my $test = grep( { $_ eq $_[0]; } - map( { $$_{'k'}; } @{ $_[2]{'select'}; } ) ); + map( { $_->{'k'}; } @{ $_[2]{'select'}; } ) ); return $test ? 1 : ( 0, "Invalid value '$_[0]' for this select" ); } }, + 'subContainer' => { + 'keyTest' => qr/\w/, + 'test' => sub { + 1; + } + }, 'text' => { 'msgFail' => '__malformedValue__', 'test' => qr/.*/ @@ -194,11 +206,6 @@ qr/^(?:(?:\-+\s*BEGIN\s+PUBLIC\s+KEY\s*\-+\r?\n)?[a-zA-Z0-9\/\+\r\n]+={0,2}(?:\r 'msgFail' => '__badUrl__', 'test' => qr/^(?:(?:https?):\/\/(?:(?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-9]*[a-zA-Z0-9]|[a-zA-Z])[.]?)|(?:[0-9]+[.][0-9]+[.][0-9]+[.][0-9]+)))(?::(?:(?:[0-9]*)))?(?:\/(?:(?:(?:(?:(?:(?:[a-zA-Z0-9\-_.!~*'():@&=+$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():@&=+$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*)(?:\/(?:(?:(?:[a-zA-Z0-9\-_.!~*'():@&=+$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)(?:;(?:(?:[a-zA-Z0-9\-_.!~*'():@&=+$,]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*))*))*))(?:[?](?:(?:(?:[;\/?:@&=+$,a-zA-Z0-9\-_.!~*'()]+|(?:%[a-fA-F0-9][a-fA-F0-9]))*)))?))?)$/ - }, - 'virtualHost' => { - 'test' => sub { - 1; - } } }; } @@ -392,6 +399,9 @@ sub attributes { } ] ], + 'test' => sub { + 1; + }, 'type' => 'authChoiceContainer' }, 'authChoiceParam' => { @@ -787,6 +797,9 @@ qr/^(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0- }; return $@ ? ( 0, "__badExpression__: $@" ) : 1; }, + 'test' => sub { + 1; + }, 'type' => 'grantContainer' }, 'groups' => { @@ -985,7 +998,7 @@ qr/^(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0- 'default' => 'ldap://localhost', 'test' => sub { my $l = shift(); - my (@s) = split( /[\s,]+/, $l, 0 ); + my @s = split( /[\s,]+/, $l, 0 ); foreach my $s (@s) { return 0, qq[Bad ldap uri "$s"] unless $s =~ @@ -1031,8 +1044,10 @@ m[^(?:ldapi://[^/]*/?|\w[\w\-\.]*(?::\d{1,5})?|ldap(?:s|\+tls)?://\w[\w\-\.]*(?: }, 'keyTest' => qr/^(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-9]*[a-zA-Z0-9]|[a-zA-Z])[.]?)$/, - 'msgFail' => '__badHostname__', - 'type' => 'ruleContainer' + 'test' => sub { + 1; + }, + 'type' => 'ruleContainer' }, 'loginHistoryEnabled' => { 'default' => 1, @@ -1561,6 +1576,9 @@ qr/^(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0- 'post' => { 'keyTest' => qr/^(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a-zA-Z0-9]*[a-zA-Z0-9]|[a-zA-Z])[.]?)$/, + 'test' => sub { + 1; + }, 'type' => 'postContainer' }, 'protection' => { @@ -1711,6 +1729,8 @@ qr/^(?:(?:https?):\/\/(?:(?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[. 'samlIDPMetaDataExportedAttributes' => { 'default' => ';;;', 'keyTest' => qr/^[a-zA-Z](?:[a-zA-Z0-9_\-\.]*\w)?$/, + 'msgFail' => '__badValue__', + 'test' => qr/\w/, 'type' => 'samlAttributeContainer' }, 'samlIDPMetaDataNodes' => { @@ -2000,6 +2020,8 @@ qr/^(?:(?:https?):\/\/(?:(?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[. 'samlSPMetaDataExportedAttributes' => { 'default' => ';;;', 'keyTest' => qr/^[a-zA-Z](?:[a-zA-Z0-9_\-\.]*\w)?$/, + 'msgFail' => '__badValue__', + 'test' => qr/\w/, 'type' => 'samlAttributeContainer' }, 'samlSPMetaDataNodes' => { diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Build/Attributes.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Build/Attributes.pm index 672b93f4c..380970a87 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Build/Attributes.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Build/Attributes.pm @@ -74,6 +74,16 @@ sub types { test => $perlExpr, msgFail => '__notAValidPerlExpression__', }, + keyTextContainer => { + test => qr/./, + msgFail => 'Empty value non accorded', + keyTest => qr/^\w[\w\.\-]*$/, + keyMsgFail => 'Bad key name', + }, + subContainer => { + keyTest => qr/\w/, + test => sub { 1 }, + }, # Files type (long text) file => { @@ -158,10 +168,6 @@ qr/^(?:(?:\-+\s*BEGIN\s+RSA\s+PRIVATE\s+KEY\s*\-+\r?\n)?[a-zA-Z0-9\/\+\r\n]+={0, : ( 0, "Invalid value '$_[0]' for this select" ); }, }, - virtualHost => { - test => sub { 1 } - }, - }; } @@ -359,6 +365,7 @@ sub attributes { grantSessionRules => { type => 'grantContainer', keyTest => $perlExpr, + test => sub { 1 }, }, hiddenAttributes => { type => 'text', @@ -534,7 +541,6 @@ sub attributes { }, # Notification - notificationStorage => { type => 'PerlModule', }, notificationWildcard => { type => 'text', default => 'allusers', @@ -845,11 +851,12 @@ sub attributes { }, locationRules => { - type => 'ruleContainer', - help => 'writingrulesand_headers.html#rules', - keyTest => qr/^$Regexp::Common::URI::RFC2396::hostname$/, - msgFail => '__badHostname__', - default => { + type => 'ruleContainer', + help => 'writingrulesand_headers.html#rules', + test => sub { 1 }, + keyTest => qr/^$Regexp::Common::URI::RFC2396::hostname$/, + keyMsgFail => '__badHostname__', + default => { default => 'deny', }, documentation => 'Virtualhost rules', @@ -864,6 +871,7 @@ sub attributes { post => { type => 'postContainer', help => 'formreplay.html', + test => sub { 1 }, keyTest => qr/^$Regexp::Common::URI::RFC2396::hostname$/, keyMsgFail => '__badHostname__', documentation => 'Virtualhost urls/Datas to post', @@ -1234,6 +1242,8 @@ sub attributes { help => 'authsaml.html#exported_attributes', keyTest => qr/^[a-zA-Z](?:[a-zA-Z0-9_\-\.]*\w)?$/, keyMsgFail => 'Bad metadata name', + test => qr/\w/, + msgFail => '__badValue__', default => ';;;', }, samlIDPMetaDataXML => { @@ -1349,6 +1359,8 @@ sub attributes { help => 'idpsaml.html#exported_attributes', keyTest => qr/^[a-zA-Z](?:[a-zA-Z0-9_\-\.]*\w)?$/, keyMsgFail => 'Bad metadata name', + test => qr/\w/, + msgFail => '__badValue__', default => ';;;', }, samlSPMetaDataXML => { @@ -1932,6 +1944,7 @@ m{^(?:ldapi://[^/]*/?|\w[\w\-\.]*(?::\d{1,5})?|ldap(?:s|\+tls)?://\w[\w\-\.]*(?: type => 'authChoiceContainer', keyTest => qr/^(\d*)?[a-zA-Z0-9_]+$/, keyMsgFail => 'Bad choice key', + test => sub { 1 }, select => [ [ { k => 'Apache', v => 'Apache' }, diff --git a/lemonldap-ng-manager/t/20-test-coverage.t b/lemonldap-ng-manager/t/20-test-coverage.t index 78f63baf4..a53049e73 100644 --- a/lemonldap-ng-manager/t/20-test-coverage.t +++ b/lemonldap-ng-manager/t/20-test-coverage.t @@ -14,11 +14,11 @@ ok( $types = Lemonldap::NG::Manager::Build::Attributes::types(), 'Get types' ); $count += 2; foreach my $attr ( keys %$attrs ) { + next if($attr=~/^virtualHosts|.*MetaDataNodes|applicationList$/); ok( ( ref( $attrs->{$attr}->{test} ) or ref( $types->{ $attrs->{$attr}->{type} }->{test} ) - or $attrs->{$attr}->{type} =~ /Container$/ ), "Test exists for $attr" );