From 27048b16706fad48210d6bff36b9e3b882c84d12 Mon Sep 17 00:00:00 2001 From: Xavier Guimard Date: Tue, 9 Feb 2016 12:38:43 +0000 Subject: [PATCH] More tests --- .../lib/Lemonldap/NG/Manager/Attributes.pm | 28 +++++++++++++++---- .../Lemonldap/NG/Manager/Build/Attributes.pm | 18 ++++++++++-- .../site/static/languages/en.json | 2 ++ .../site/static/languages/fr.json | 2 ++ 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Attributes.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Attributes.pm index 703de3a78..60b52d3bb 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Attributes.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Attributes.pm @@ -60,7 +60,15 @@ qr/^(?:(?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a- 'lmAttrOrMacro' => { 'form' => 'text', 'test' => sub { - 1; + my ( $val, $conf ) = @_; + if ( defined $conf->{'exportedVars'}{$val} + or defined $conf->{'macro'}{$val} ) + { + return 1; + } + else { + return 1, '__unknownAttrOrMacro__'; + } } }, 'longtext' => { @@ -100,7 +108,9 @@ qr/^(?:(?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[.])*(?:[a-zA-Z][-a- }, 'password' => { 'msgFail' => '__malformedValue__', - 'test' => qr/.*/ + 'test' => sub { + 1; + } }, 'pcre' => { 'form' => 'text', @@ -196,7 +206,9 @@ qr/^(?:(?:\-+\s*BEGIN\s+(?:PUBLIC\s+KEY|CERTIFICATE)\s*\-+\r?\n)?[a-zA-Z0-9\/\+\ }, 'text' => { 'msgFail' => '__malformedValue__', - 'test' => qr/.*/ + 'test' => sub { + 1; + } }, 'trool' => { 'msgFail' => '__authorizedValues__: -1, 0, 1', @@ -2461,11 +2473,17 @@ qr/^(?:(?:https?):\/\/(?:(?:(?:(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*)?[a-zA-Z0-9])[. }, 'timeout' => { 'default' => 72000, - 'type' => 'int' + 'test' => sub { + $_[0] > 0; + }, + 'type' => 'int' }, 'timeoutActivity' => { 'default' => 0, - 'type' => 'int' + 'test' => sub { + $_[0] >= 0; + }, + 'type' => 'int' }, 'trustedDomains' => { 'type' => 'text' 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 7d6df9861..a928fd831 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Build/Attributes.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Build/Attributes.pm @@ -20,11 +20,11 @@ sub types { # Simple text types text => { - test => qr/.*/, + test => sub { 1 }, msgFail => '__malformedValue__', }, password => { - test => qr/.*/, + test => sub { 1 }, msgFail => '__malformedValue__', }, longtext => { @@ -54,7 +54,17 @@ sub types { }, lmAttrOrMacro => { form => 'text', - test => sub { 1 }, + test => sub { + my ( $val, $conf ) = @_; + if ( defined $conf->{exportedVars}->{$val} + or defined $conf->{macro}->{$val} ) + { + return 1; + } + else { + return ( 1, '__unknownAttrOrMacro__' ); + } + }, }, # Other types @@ -427,11 +437,13 @@ sub attributes { }, timeout => { type => 'int', + test => sub { $_[0] > 0 }, default => 72000, documentation => 'Session timeout on server side', }, timeoutActivity => { type => 'int', + test => sub { $_[0] >= 0 }, default => 0, documentation => 'Session activity timeout on server side', }, diff --git a/lemonldap-ng-manager/site/static/languages/en.json b/lemonldap-ng-manager/site/static/languages/en.json index 0fe5cb07e..e43493f6d 100644 --- a/lemonldap-ng-manager/site/static/languages/en.json +++ b/lemonldap-ng-manager/site/static/languages/en.json @@ -56,6 +56,7 @@ "auto": "Automatic", "backtoportal": "Back to portal", "badCookieName": "Bad cookie name", +"badCustomFuncName": "Bad custom function name", "badDomainName": "Bad domain name", "badEncoding": "Bad encoding", "badExpression": "Bad expression", @@ -585,6 +586,7 @@ "twitterParams": "Twitter parameters", "twitterSecret": "API secret", "uid": "Identifier", +"unknownAttrOrMacro": "Unknown attribute or macro", "unknownError": "Unknown error", "unknownKey": "Unknown key", "unsecuredCookie": "Unsecured cookie", diff --git a/lemonldap-ng-manager/site/static/languages/fr.json b/lemonldap-ng-manager/site/static/languages/fr.json index 9304ee0d2..b829c90fb 100644 --- a/lemonldap-ng-manager/site/static/languages/fr.json +++ b/lemonldap-ng-manager/site/static/languages/fr.json @@ -56,6 +56,7 @@ "auto": "Automatique", "backtoportal": "Retour au portail", "badCookieName": "Mauvais nom de cookie", +"badCustomFuncName": "Mauvais nom de fonction personnalisée", "badDomainName": "Mauvais nom de domaine", "badEncoding": "Mauvais encodage", "badExpression": "Mauvaise expression", @@ -585,6 +586,7 @@ "twitterParams": "Paramètres Twitter", "twitterSecret": "Secret de l'API", "uid": "Identifiant", +"unknownAttrOrMacro": "Attribut ou macro inconnu", "unknownError": "Erreur inconnue", "unknownKey": "Clef inconnue", "unsecuredCookie": "Cookie non sécurisé",