[OpenSRF-GIT] OpenSRF branch master updated. 3d089bdfd067676f99807f7cb2014e122c4dbf72

Evergreen Git git at git.evergreen-ils.org
Mon Dec 12 13:24:17 EST 2011


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "OpenSRF".

The branch, master has been updated
       via  3d089bdfd067676f99807f7cb2014e122c4dbf72 (commit)
       via  5e1fbcc1c8ae2f969dbeac93fe1da80c008ca42b (commit)
      from  b6b64deb16ed3f005d64f99365b0220a82d72431 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 3d089bdfd067676f99807f7cb2014e122c4dbf72
Author: Dan Scott <dscott at laurentian.ca>
Date:   Mon Dec 12 13:09:13 2011 -0500

    Update Perl OpenSRF build and tests for O:A:Validator
    
    Kickstarted by wanting to bring OpenSRF::Application::Validator into the
    MANIFEST and testing coverage, I noticed a few other files that needed
    to be added to the MANIFEST as well. This gets us closer to acceptable
    according to "./Build distcheck"
    
    Signed-off-by: Dan Scott <dscott at laurentian.ca>

diff --git a/src/perl/Build.PL b/src/perl/Build.PL
index bfeae7d..1d75bd2 100644
--- a/src/perl/Build.PL
+++ b/src/perl/Build.PL
@@ -11,6 +11,7 @@ my $build = Module::Build->new( module_name => 'OpenSRF',
                                               'Error'            => 0,
                                               'IO'               => 0,
                                               'JSON::XS'         => 0,
+                                              'Net::DNS'         => 0,
                                               'Net::Domain'      => 0,
                                               'Net::Server'      => 0,
                                               'Time::HiRes'      => 0,
diff --git a/src/perl/MANIFEST b/src/perl/MANIFEST
index 6bace88..2f8a129 100644
--- a/src/perl/MANIFEST
+++ b/src/perl/MANIFEST
@@ -9,12 +9,19 @@ lib/OpenSRF/Application/Persist.pm
 lib/OpenSRF/Application/Settings.pm
 lib/OpenSRF/Application/Demo/Math.pm
 lib/OpenSRF/Application/Demo/MathDB.pm
+lib/OpenSRF/Application/Demo/SimpleText.pm
+lib/OpenSRF/Application/Validator.pm
+lib/OpenSRF/Application/Validator/Base.pm
+lib/OpenSRF/Application/Validator/EmailAddress/DNS.pm
+lib/OpenSRF/Application/Validator/EmailAddress/Regex.pm
+lib/OpenSRF/Application/Validator/Invalid.pm
 lib/OpenSRF/AppSession.pm
 lib/OpenSRF/DomainObject/oilsMessage.pm
 lib/OpenSRF/DomainObject/oilsMethod.pm
 lib/OpenSRF/DomainObject/oilsResponse.pm
 lib/OpenSRF/EX.pm
 lib/OpenSRF/MultiSession.pm
+lib/OpenSRF/Server.pm
 lib/OpenSRF/System.pm
 lib/OpenSRF/Transport.pm
 lib/OpenSRF/Transport/Listener.pm
@@ -33,5 +40,20 @@ lib/OpenSRF/Utils/Logger.pm
 lib/OpenSRF/Utils/SettingsClient.pm
 lib/OpenSRF/Utils/SettingsParser.pm
 t/00-load.t
+t/01-Application.t
+t/02-AppSession.t
+t/03-DomainObject.t
+t/04-EX.t
+t/05-MultiSession.t
+t/06-System.t
+t/07-Transport.t
+t/08-Server.t
+t/09-Utils-Cache.t
+t/09-Utils-Config.t
+t/09-Utils-JSON.t
+t/09-Utils-Logger.t
+t/09-Utils-SettingsClient.t
+t/09-Utils-SettingsParser.t
+t/09-Utils.t
 t/pod-coverage.t
 t/pod.t
diff --git a/src/perl/t/01-Application.t b/src/perl/t/01-Application.t
index 009dd60..02c1a50 100644
--- a/src/perl/t/01-Application.t
+++ b/src/perl/t/01-Application.t
@@ -1,6 +1,6 @@
 #!perl -T
 
-use Test::More tests => 4;
+use Test::More tests => 9;
 
 BEGIN {
 	use_ok( 'OpenSRF::Application' );
@@ -9,3 +9,8 @@ BEGIN {
 use_ok( 'OpenSRF::Application::Client' );
 use_ok( 'OpenSRF::Application::Persist' );
 use_ok( 'OpenSRF::Application::Settings' );
+use_ok( 'OpenSRF::Application::Validator' );
+use_ok( 'OpenSRF::Application::Validator::Base' );
+use_ok( 'OpenSRF::Application::Validator::EmailAddress::DNS' );
+use_ok( 'OpenSRF::Application::Validator::EmailAddress::Regex' );
+use_ok( 'OpenSRF::Application::Validator::Invalid' );

commit 5e1fbcc1c8ae2f969dbeac93fe1da80c008ca42b
Author: Thomas Berezansky <tsbere at mvlc.org>
Date:   Fri Dec 9 15:19:12 2011 -0500

    OpenSRF Validator Service
    
    Add a new Validator service, and EmailAddress validators.
    
    The service runs a chain of one or more validators, each one being fed the
    normalized output of the previous one.
    
    The return from each validator should be a hash of valid (0 or 1), the new
    normalized output (the untouched input if invalid or nothing needed to be
    changed), and if invalid an error string. Optionally, a validator can also
    include an "additionals" hash of extra information to be included in the
    final response.
    
    The complete list of validators included is:
    
    OpenSRF::Application::Validator::Base
        The base validator. Always returns valid.
    OpenSRF::Application::Validator::Invalid
        Always returns invalid for testing purposes.
    OpenSRF::Application::Validator::EmailAddress::Regex
        Does a very basic regular expression check on email addresses.
    OpenSRF::Application::Validator::EmailAddress::DNS
        Uses Net::DNS to look up the domain on an email address
    
    Signed-off-by: Thomas Berezansky <tsbere at mvlc.org>
    Signed-off-by: Dan Scott <dscott at laurentian.ca>

diff --git a/examples/opensrf.xml.example b/examples/opensrf.xml.example
index 0dc2704..9b0ed97 100644
--- a/examples/opensrf.xml.example
+++ b/examples/opensrf.xml.example
@@ -182,6 +182,45 @@ vim:et:ts=2:sw=2:
           <max_spare_children>5</max_spare_children>
         </unix_config>
       </opensrf.settings>
+
+      <opensrf.validator>
+        <keepalive>1</keepalive>
+        <stateless>1</stateless>
+        <language>perl</language>
+        <implementation>OpenSRF::Application::Validator</implementation>
+        <max_requests>17</max_requests>
+        <unix_config>
+          <unix_sock>opensrf.validator_unix.sock</unix_sock>
+          <unix_pid>opensrf.validator_unix.pid</unix_pid>
+          <max_requests>1000</max_requests>
+          <unix_log>opensrf.validator_unix.log</unix_log>
+          <min_children>5</min_children>
+          <max_children>15</max_children>
+          <min_spare_children>3</min_spare_children>
+          <max_spare_children>5</max_spare_children>
+        </unix_config>
+        <app_settings>
+          <validators>
+            <emailaddress>
+              <modules>
+                <a_regex>
+                    <implementation>OpenSRF::Application::Validator::EmailAddress::Regex</implementation>
+                </a_regex>
+                <b_dns>
+                    <implementation>OpenSRF::Application::Validator::EmailAddress::DNS</implementation>
+                    <check_mx_a>1</check_mx_a>
+                    <!-- Change this to a 1 to check for IPV6 records as well as IPV4 -->
+                    <check_aaaa>0</check_aaaa>
+                    <!-- Uncomment this to specify a resolve.conf-like config file for DNS lookups -->
+                    <!--<config_file>/path/to/file</config_file>-->
+                    <!-- A set of IPs to ignore - Useful when your DNS provider intercepts NXDOMAIN (say, OpenDNS) -->
+                    <ignore_ips>127.0.0.1,67.215.65.132</ignore_ips>
+                </b_dns>
+              </modules>
+            </emailaddress>
+          </validators>
+        </app_settings>
+      </opensrf.validator>
     </apps>
   </default>
 
@@ -202,6 +241,7 @@ vim:et:ts=2:sw=2:
         <appname>opensrf.settings</appname>
         <appname>opensrf.math</appname>
         <appname>opensrf.dbmath</appname>
+        <appname>opensrf.validator</appname>
       </activeapps>
 
       <apps>
diff --git a/src/extras/Makefile.install b/src/extras/Makefile.install
index 56725c9..51d8890 100644
--- a/src/extras/Makefile.install
+++ b/src/extras/Makefile.install
@@ -101,6 +101,7 @@ DEBS =  \
 	libgdbm-dev \
 	liblog-log4perl-perl\
 	libmodule-build-perl\
+	libnet-dns-perl\
 	libnet-jabber-perl\
 	libperl-dev\
 	libreadline5-dev\
@@ -161,6 +162,7 @@ CENTOS = \
 	perl-Log-Log4perl \
 	perl-Memcached-libmemcached \
 	perl-Module-Build \
+	perl-Net-DNS \
 	perl-Net-Server \
 	perl-Template-Toolkit \
 	perl-Test-Pod \
@@ -219,6 +221,7 @@ FEDORAS = \
 	perl-libwww-perl \
 	perl-Log-Log4perl \
 	perl-Module-Build \
+	perl-Net-DNS \
 	perl-Net-Jabber \
 	perl-Net-Server \
 	perl-RPC-XML \
diff --git a/src/perl/lib/OpenSRF/Application/Validator.pm b/src/perl/lib/OpenSRF/Application/Validator.pm
new file mode 100644
index 0000000..dc9b072
--- /dev/null
+++ b/src/perl/lib/OpenSRF/Application/Validator.pm
@@ -0,0 +1,50 @@
+package OpenSRF::Application::Validator;
+use base qw/OpenSRF::Application/;
+use OpenSRF::Application;
+use OpenSRF::Utils::SettingsClient;
+use OpenSRF::Utils::Logger;
+use Module::Load;
+
+my $logger = OpenSRF::Utils::Logger;
+my %modules;
+
+sub initialize {
+    my $sc = OpenSRF::Utils::SettingsClient->new;
+    my $validators = $sc->config_value( apps => 'opensrf.validator' => app_settings => 'validators' );
+    while(my $module = each %$validators ) {
+        __PACKAGE__->register_method(
+            api_name => "opensrf.validator.$module.validate",
+            method => 'do_validate',
+            argc => 1,
+            validator_name => $module
+        );
+        $modules{$module} = $validators->{$module};
+    }
+}
+
+sub do_validate {
+    my $self = shift;
+    my $client = shift;
+    my $input = shift;
+    my $return = { 'valid' => 1, 'normalized' => $input }; # Default return
+    my $validators = $modules{$self->{validator_name}}->{modules};
+    my @validator_names = sort keys %$validators;
+    my $additionals = ();
+
+    my $submodulename, $submodule;
+    while($return->{valid} && ($submodulename = shift @validator_names)) {
+        $submodule = $validators->{$submodulename};
+        my $implementation = $submodule->{implementation};
+        $logger->debug("Running request through $submodulename ($implementation)");
+        load $implementation;
+        my $result = $implementation->validate($return->{normalized}, $submodule);
+        if($result) {
+            $return = $result;
+            $additionals = {%$additionals, %{$return->{additionals}}} if $return->{additionals};
+        }
+    }
+    $return->{additionals} = $additionals;
+    return $return;
+}
+
+1;
diff --git a/src/perl/lib/OpenSRF/Application/Validator/Base.pm b/src/perl/lib/OpenSRF/Application/Validator/Base.pm
new file mode 100644
index 0000000..bf7d34f
--- /dev/null
+++ b/src/perl/lib/OpenSRF/Application/Validator/Base.pm
@@ -0,0 +1,12 @@
+package OpenSRF::Application::Validator::Base;
+use strict;
+use warnings;
+
+sub validate {
+    my $self = shift;
+    my $input = shift;
+    my $settings = shift;
+    return { 'valid' => 1, 'normalized' => $input };
+}
+
+1;
diff --git a/src/perl/lib/OpenSRF/Application/Validator/EmailAddress/DNS.pm b/src/perl/lib/OpenSRF/Application/Validator/EmailAddress/DNS.pm
new file mode 100644
index 0000000..8121ccd
--- /dev/null
+++ b/src/perl/lib/OpenSRF/Application/Validator/EmailAddress/DNS.pm
@@ -0,0 +1,96 @@
+package OpenSRF::Application::Validator::EmailAddress::DNS;
+use base qw/OpenSRF::Application::Validator::Base/;
+
+use OpenSRF::Application::Validator::Base;
+use Net::DNS;
+
+use strict;
+use warnings;
+
+sub validate {
+    my $self = shift;
+    my $input = shift;
+    my $settings = shift;
+    
+    my $return = { 'valid' => 0, 'normalized' => $input };
+
+    if(!$input->{emailaddress}) {
+        return { 'valid' => 0, 'normalized' => $input, 'error' => 'No Address' };
+    } elsif ($input->{emailaddress} !~ /@([^@]+)$/) {
+        return { 'valid' => 0, 'normalized' => $input, 'error' => 'Bad Address - Regex Check Failed' };
+    }
+    my $domain = $1;
+    my $checkMXA = $settings->{check_mx_a};
+    my $checkAAAA = $settings->{check_aaaa};
+    my $config_file = $settings->{config_file};
+    my @badAddrs;
+    if($settings->{ignore_ips}) {
+        @badAddrs = split(',', $settings->{ignore_ips});
+    }
+    my $res;
+    $res = Net::DNS::Resolver->new(config_file => $config_file, defnames => 0) if $config_file;
+    $res = Net::DNS::Resolver->new(defnames => 0) if !$config_file;
+    my @arecords;
+    # Look for MX records first
+    my $answer = $res->send($domain, 'MX');
+    foreach($answer->answer) {
+        if($_->type eq 'MX') {
+            push(@arecords, $_->exchange);
+        }
+    }
+    if(@arecords) {
+        if($checkMXA) {
+            OUTER: foreach my $checkdomain (@arecords) {
+                $answer = $res->send($checkdomain, 'A');
+                foreach my $record ($answer->answer) {
+                    last if $record->type eq 'CNAME' || $record->type eq 'DNAME';
+                    if($record->type eq 'A') {
+                        next if grep { $_ eq $record->address } @badAddrs;
+                        $return->{valid} = 1;
+                        last OUTER;
+                    }
+                }
+                if($checkAAAA) {
+                    $answer = $res->send($checkdomain, 'AAAA');
+                    foreach my $record ($answer->answer) {
+                        last if $record->type eq 'CNAME' || $record->type eq 'DNAME';
+                        if($record->type eq 'AAAA') {
+                            next if grep { $_ eq $record->address } @badAddrs;
+                            $return->{valid} = 1;
+                            last OUTER;
+                        }
+                    }
+                }
+            }
+            $return->{error} = "MX Records Invalid" if(!$return->{valid});
+        } else {
+            $return->{valid} = 1;
+        }
+    } else {
+        $answer = $res->send($domain,'A');
+        foreach my $record ($answer->answer) {
+            last if $record->type eq 'CNAME' || $record->type eq 'DNAME';
+            if($record->type eq 'A') {
+                next if grep { $_ eq $record->address } @badAddrs;
+                $return->{valid} = 1;
+                last;
+            }
+        }
+        if(!$return->{valid} && $checkAAAA) {
+            $answer = $res->send($domain, 'AAAA');
+            foreach my $record ($answer->answer) {
+                last if $record->type eq 'CNAME' || $record->type eq 'DNAME';
+                if($record->type eq 'AAAA') {
+                    next if grep { $_ eq $record->address } @badAddrs; 
+                    $return->{valid} = 1;
+                    last;
+                }
+            }
+        }
+        $return->{error} = "No A Records Found" if(!$return->{valid});
+    }
+    $return->{normalized}->{emailaddress} = lc($return->{normalized}->{emailaddress}) if($return->{valid});
+    return $return;
+}
+
+1;
diff --git a/src/perl/lib/OpenSRF/Application/Validator/EmailAddress/Regex.pm b/src/perl/lib/OpenSRF/Application/Validator/EmailAddress/Regex.pm
new file mode 100644
index 0000000..25036fc
--- /dev/null
+++ b/src/perl/lib/OpenSRF/Application/Validator/EmailAddress/Regex.pm
@@ -0,0 +1,23 @@
+package OpenSRF::Application::Validator::EmailAddress::Regex;
+use base qw/OpenSRF::Application::Validator::Base/;
+
+use OpenSRF::Application::Validator::Base;
+
+use strict;
+use warnings;
+
+sub validate {
+    my $self = shift;
+    my $input = shift;
+    my $settings = shift;
+
+    if(!$input->{emailaddress}) {
+        return { 'valid' => 0, 'normalized' => $input, 'error' => 'No Address' };
+    } elsif ($input->{emailaddress} !~ /^.+@[^@]+\.[^@]{2,}$/) {
+        return { 'valid' => 0, 'normalized' => $input, 'error' => 'Bad Address - Regex Check Failed' };
+    }
+    $input->{emailaddress} = lc($input->{emailaddress});
+    return { 'valid' => 1, 'normalized' => $input };
+}
+
+1;
diff --git a/src/perl/lib/OpenSRF/Application/Validator/Invalid.pm b/src/perl/lib/OpenSRF/Application/Validator/Invalid.pm
new file mode 100644
index 0000000..76f9676
--- /dev/null
+++ b/src/perl/lib/OpenSRF/Application/Validator/Invalid.pm
@@ -0,0 +1,16 @@
+package OpenSRF::Application::Validator::Invalid;
+use base qw/OpenSRF::Application::Validator::Base/;
+
+use OpenSRF::Application::Validator::Base;
+
+use strict;
+use warnings;
+
+sub validate {
+    my $self = shift;
+    my $input = shift;
+    my $settings = shift;
+    return { 'valid' => 0, 'normalized' => $input, 'error' => 'Forced Invalid' };
+}
+
+1;

-----------------------------------------------------------------------

Summary of changes:
 examples/opensrf.xml.example                       |   40 ++++++++
 src/extras/Makefile.install                        |    3 +
 src/perl/Build.PL                                  |    1 +
 src/perl/MANIFEST                                  |   22 +++++
 src/perl/lib/OpenSRF/Application/Validator.pm      |   50 ++++++++++
 src/perl/lib/OpenSRF/Application/Validator/Base.pm |   12 +++
 .../Application/Validator/EmailAddress/DNS.pm      |   96 ++++++++++++++++++++
 .../Application/Validator/EmailAddress/Regex.pm    |   23 +++++
 .../lib/OpenSRF/Application/Validator/Invalid.pm   |   16 ++++
 src/perl/t/01-Application.t                        |    7 ++-
 10 files changed, 269 insertions(+), 1 deletions(-)
 create mode 100644 src/perl/lib/OpenSRF/Application/Validator.pm
 create mode 100644 src/perl/lib/OpenSRF/Application/Validator/Base.pm
 create mode 100644 src/perl/lib/OpenSRF/Application/Validator/EmailAddress/DNS.pm
 create mode 100644 src/perl/lib/OpenSRF/Application/Validator/EmailAddress/Regex.pm
 create mode 100644 src/perl/lib/OpenSRF/Application/Validator/Invalid.pm


hooks/post-receive
-- 
OpenSRF


More information about the opensrf-commits mailing list