Pārlūkot izejas kodu

Add functional testing ability to track down issue #2

Also adds notice to readme about current known incompatibility
Andy Baugh 8 gadi atpakaļ
vecāks
revīzija
4f026225b6
5 mainītis faili ar 52 papildinājumiem un 6 dzēšanām
  1. 1 0
      .gitignore
  2. 1 1
      Makefile
  3. 20 0
      README.md
  4. 1 0
      lib/Cpanel/iContact/Provider/XMPP.pm
  5. 29 5
      t/Cpanel-iContact-Provider-XMPP.t

+ 1 - 0
.gitignore

@@ -1,3 +1,4 @@
 *.bak
 *.swp
 cover_db
+.xmpptestrc

+ 1 - 1
Makefile

@@ -10,4 +10,4 @@ test:
 	[ -x /usr/local/cpanel/3rdparty/bin/prove ] || prove t/*.t
 
 depend:
-	sudo cpan -i Net::XMPP Mozilla::CA Test::More Test::Fatal Test::MockModule
+	perl -MNet::XMPP -MMozilla::CA -MTest::More -MTest::Fatal -MTest::MockModule -MConfig::Simple -e 'exit 0;' || sudo cpan -i Net::XMPP Mozilla::CA Test::More Test::Fatal Test::MockModule Config::Simple

+ 20 - 0
README.md

@@ -21,3 +21,23 @@ Installation and Use:
 * Go to WHM >> Basic Setup and configure the provider options
 * Go to WHM >> Contact Manager and make sure it is set up to spam you mercilessly
 * Do something to trigger notifications from cPanel & WHM
+
+KNOWN BUGS
+----------
+* ejabberd:
+Currently, the DIGEST-MD5 method (used by default in Net::XMPP when authenticating against the latest ejabberd versions)
+causes failures to send notifications. Add `disable_sasl_mechanisms: "DIGEST-MD5"` to your `ejabberd.yml` config file
+to avoid this problem. See issue #2 on the tracker.
+
+TESTING NOTES
+-------------
+If you want to run a functional test of the XMPP iContact code in order to debug problems, set the env var `AUTHOR_TESTS`
+and write out .xmpptestrc in the toplevel directory of this git repository with content like:
+    XMPPUSERNAME: user@domain.tld
+    XMPPPASSWORD: hunter2
+    XMPPCOMPONENTNAME:
+    XMPPUSETLS: 1
+    XMPPVERIFYCERT: 0
+
+You'll note these correspond to the values in the Provider's Schema module. With that set, you should spam yourself with
+a message if the t/Cpanel-iContact-Provider-XMPP.t test passes.

+ 1 - 0
lib/Cpanel/iContact/Provider/XMPP.pm

@@ -88,6 +88,7 @@ sub _send {
         'resource'    => 'cPanel & WHM',
     );
     if( !@result || $result[0] ne "ok" ) {
+        $xmpp_conn->Disconnect();
         die("Error: XMPP authentication failed: $result[1]" );
     }
 

+ 29 - 5
t/Cpanel-iContact-Provider-XMPP.t

@@ -5,21 +5,45 @@ use Cwd qw{abs_path};
 use File::Basename qw{dirname};
 use lib abs_path( dirname(__FILE__) . "/../lib" );
 
-use Test::More 'tests' => 4;
+use Test::More 'tests' => 5;
 use Test::Fatal;
+use Config::Simple ();
 
 is( exception { require Cpanel::iContact::Provider::XMPP; }, undef, 'Module at least compiles' );
 isa_ok( my $xmpp = Cpanel::iContact::Provider::XMPP->new(), "Cpanel::iContact::Provider::XMPP" );
 my $sent;
 {
     no warnings qw{redefine once};
-    *Net::XMPP::Client::Connect     = sub { return 1; };
-    *Net::XMPP::Client::AuthSend    = sub { return ( 'ok', "Assumed Success" ); };
-    *Net::XMPP::Client::MessageSend = sub { return; };
-    *Net::XMPP::Client::Disconnect  = sub { return; };
+    local *Net::XMPP::Client::Connect     = sub { return 1; };
+    local *Net::XMPP::Client::AuthSend    = sub { return ( 'ok', "Assumed Success" ); };
+    local *Net::XMPP::Client::MessageSend = sub { return; };
+    local *Net::XMPP::Client::Disconnect  = sub { return; };
     is( exception { $sent = $xmpp->send(); }, undef, 'send() did not die' );
 }
 ok( $sent, "...and the message appears to have actually sent." );
 
+SKIP: {
+    my $conf_file = abs_path( dirname(__FILE__) . "/../.xmpptestrc" );
+    diag("Conf file '$conf_file' doesn't exist") if !-f $conf_file;
+    skip "Skipping functional testing, needful not supplied", 1 if !$ENV{'AUTHOR_TESTS'} || !-f $conf_file;
+    my $test_conf = { Config::Simple->import_from($conf_file)->vars() };
+    my %args = (
+        'destination' => $test_conf->{'XMPPUSERNAME'},
+        'subject' => 'My Super cool test notification',
+        'content' => "This is a test of Cpanel::iContact::Provider::XMPP. Please Ignore",
+    );
+
+    {
+        no warnings qw{redefine once};
+        local *Cpanel::iContact::Provider::XMPP::new = sub {
+            return bless {
+                'contact' => $test_conf,
+            }, $_[0];
+        };
+        my $spammer = Cpanel::iContact::Provider::XMPP->new();
+        is( exception { $spammer->_send(%args) }, undef, "Didn't fail to send notification using full functional test" );
+    }
+}
+
 # TODO error paths
 #isnt( exception { $xmpp->send(); }, undef, "We blew up when we timed out on connect" );