Mailing List Archive

svn commit: r1916223 - in /spamassassin/trunk: MANIFEST Makefile.PL lib/Mail/SpamAssassin/Util/DependencyInfo.pm t/dnsplatform.t
Author: sidney
Date: Mon Mar 11 03:10:43 2024
New Revision: 1916223

URL: http://svn.apache.org/viewvc?rev=1916223&view=rev
Log:
bug 8227 - Add tests for proper DNS resolver setup during build/install

Added:
spamassassin/trunk/t/dnsplatform.t
Modified:
spamassassin/trunk/MANIFEST
spamassassin/trunk/Makefile.PL
spamassassin/trunk/lib/Mail/SpamAssassin/Util/DependencyInfo.pm

Modified: spamassassin/trunk/MANIFEST
URL: http://svn.apache.org/viewvc/spamassassin/trunk/MANIFEST?rev=1916223&r1=1916222&r2=1916223&view=diff
==============================================================================
--- spamassassin/trunk/MANIFEST (original)
+++ spamassassin/trunk/MANIFEST Mon Mar 11 03:10:43 2024
@@ -527,6 +527,7 @@ t/dkim.t
t/dnsbl.t
t/dnsbl_sc_meta.t
t/dnsbl_subtests.t
+t/dnsplatform.t
t/enable_compat.t
t/extracttext.t
t/freemail.t

Modified: spamassassin/trunk/Makefile.PL
URL: http://svn.apache.org/viewvc/spamassassin/trunk/Makefile.PL?rev=1916223&r1=1916222&r2=1916223&view=diff
==============================================================================
--- spamassassin/trunk/Makefile.PL (original)
+++ spamassassin/trunk/Makefile.PL Mon Mar 11 03:10:43 2024
@@ -335,6 +335,15 @@ if (Mail::SpamAssassin::Util::Dependency
exit 0;
}

+if (Mail::SpamAssassin::Util::DependencyInfo::test_network_dns() != 0) {
+ # If Net::DNS is already installed this checks if this system succeeds on DNS
+ # queries to some of our test records. Testing here and aborting on failure
+ # prevents having many test failure reports on CPAN test machines with poorly configured networks
+ # while also preventing Spamassassin from being installed on such systems.
+ # To force installation without adequate DNS, don't install Net::DNS in the first place.
+ exit 0;
+}
+
foreach my $file (@FILES_THAT_MUST_EXIST) {
open (TOUCH, ">>$file") or die "cannot touch '$file'";
close TOUCH;

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Util/DependencyInfo.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Util/DependencyInfo.pm?rev=1916223&r1=1916222&r2=1916223&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Util/DependencyInfo.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Util/DependencyInfo.pm Mon Mar 11 03:10:43 2024
@@ -400,6 +400,21 @@ if ($^O eq 'freebsd') {
};
}

+# The numbers being tested only have to be anything more than truncated packets will have
+# That allows some flexibility if the exact test records are changed in the future
+our @NETWORK_TESTS = (
+{
+ 'name' => 'txttcp.spamassassin.org',
+ 'type' => 'TXT',
+ 'min_answers' => 10,
+},
+{
+ 'name' => 'multihomed.dnsbltest.spamassassin.org',
+ 'type' => 'A',
+ 'min_answers' => 4,
+},
+);
+
###########################################################################

=head1 METHODS
@@ -743,4 +758,23 @@ sub try_module {
}
}

+sub test_network_dns {
+ # This allows CPAN testing to abort early on inadequate networks
+ # If Net::DNS is not installed yet, this will get caught later in tests anyway
+ eval { require Net::DNS ; Net::DNS->VERSION("1.10"); 1 } || return 0;
+ my $test_failed = 0;
+ my $res = Net::DNS::Resolver->new();
+ foreach my $testname (@NETWORK_TESTS) {
+ my $reply = $res->send($testname->{name}, $testname->{type}, "IN");
+ if ( !($reply && (scalar($reply->answer) >= $testname->{min_answers})) ) {
+ print "\n", ("*" x 75), "\n";
+ printf("NOTE: DNS test failed, expected %d answers, for %s %s, reply received was:\n%s\n",
+ $testname->{min_answers}, $testname->{name}, $testname->{type}, $reply?($reply->string):'undef');
+ $test_failed++;
+ }
+ }
+ print "\nCorrect the network DNS configuration before installing SpamAssassin\n", ("*" x 75), "\n" if $test_failed;
+ return $test_failed;
+}
+
1;

Added: spamassassin/trunk/t/dnsplatform.t
URL: http://svn.apache.org/viewvc/spamassassin/trunk/t/dnsplatform.t?rev=1916223&view=auto
==============================================================================
--- spamassassin/trunk/t/dnsplatform.t (added)
+++ spamassassin/trunk/t/dnsplatform.t Mon Mar 11 03:10:43 2024
@@ -0,0 +1,34 @@
+#!/usr/bin/perl -T
+
+use lib '.'; use lib 't';
+use SATest; sa_t_init("dnsplatform");
+
+use Test::More;
+plan skip_all => "Net tests disabled" unless conf_bool('run_net_tests');
+plan tests => 2;
+
+use Net::DNS;
+use Net::DNS::Resolver;
+
+my $explanation = '
+Problems found with network and DNS setup on this system, not SpamAssassin bug:
+';
+
+my $res = Net::DNS::Resolver->new();
+my $reply1 = $res->send("txttcp.spamassassin.org", "TXT", "IN");
+if ($reply1 && (scalar($reply1->answer) == 17) && ($reply1->size > 1200)) {
+ pass('txttcp');
+} else {
+ diag($explanation);
+ diag(($reply1 && $reply1->string) || 'No reply for txttcp TXT');
+ fail('txttcp');
+}
+
+my $reply2 = $res->send("multihomed.dnsbltest.spamassassin.org", "A", "IN");
+if ($reply2 && (scalar($reply2->answer) == 4)) {
+ pass('multihomed');
+} else {
+ diag($explanation);
+ diag(($reply2 && $reply2->string) || 'No reply for multihomed A');
+ fail('multihomed');
+}