jenkins-bot has submitted this change and it was merged.

Change subject: Marked the BounceHandler API as internal
......................................................................


Marked the BounceHandler API as internal

Updated the API and tests to respond to false or malformed API request.

Bug: 72685
Change-Id: I1767fcf126b0b1385725d96eb9eedebac2856a7b
---
M includes/ApiBounceHandler.php
M tests/ApiBounceHandlerTest.php
2 files changed, 58 insertions(+), 10 deletions(-)

Approvals:
  Aaron Schulz: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/ApiBounceHandler.php b/includes/ApiBounceHandler.php
index de34d5a..f6c78ca 100644
--- a/includes/ApiBounceHandler.php
+++ b/includes/ApiBounceHandler.php
@@ -20,17 +20,35 @@
                }
 
                $email = $this->getMain()->getVal( 'email' );
-               $params = array ( 'email' => $email );
-               $title = Title::newFromText( 'BounceHandler Job' );
-               $job = new BounceHandlerJob( $title, $params );
-               JobQueueGroup::singleton()->push( $job );
 
-               $this->getResult()->addValue(
-                       null,
-                       $this->getModuleName(),
-                       array ( 'submitted' => 'job' )
-               );
+               if ( $email ) {
+                       $params = array ( 'email' => $email );
+                       $title = Title::newFromText( 'BounceHandler Job' );
+                       $job = new BounceHandlerJob( $title, $params );
+                       JobQueueGroup::singleton()->push( $job );
 
+                       $this->getResult()->addValue(
+                               null,
+                               $this->getModuleName(),
+                               array ( 'submitted' => 'job' )
+                       );
+               } else {
+                       $this->getResult()->addValue(
+                               null,
+                               $this->getModuleName(),
+                               array ( 'submitted' => 'failure' )
+                       );
+               }
+
+               return true;
+       }
+
+       /**
+        * Mark the API as internal
+        *
+        * @return bool
+        */
+       public function isInternal() {
                return true;
        }
 
diff --git a/tests/ApiBounceHandlerTest.php b/tests/ApiBounceHandlerTest.php
index 42b8d54..b02322c 100644
--- a/tests/ApiBounceHandlerTest.php
+++ b/tests/ApiBounceHandlerTest.php
@@ -18,6 +18,8 @@
 
        /**
         * Tests API request from an allowed IP
+        *
+        *
         */
        function testBounceHandlerWithGoodIPPasses() {
                $this->setMwGlobals( 'wgBounceHandlerInternalIPs', array( 
'127.0.0.1' ) );
@@ -37,10 +39,38 @@
         */
        function testBounceHandlerWithBadIPPasses() {
                $this->setMwGlobals( 'wgBounceHandlerInternalIPs', array( 
'111.111.111.111' ) );
-               $this->doApiRequest( array(
+               list( $apiResult ) = $this->doApiRequest( array(
                        'action' => 'bouncehandler',
                        'email' => self::$bounceEmail
                ) );
        }
 
+       /**
+        * Tests API request with null 'email' param
+        *
+        */
+       function testBounceHandlerWithNullParams() {
+               $this->setMwGlobals( 'wgBounceHandlerInternalIPs', array( 
'127.0.0.1' ) );
+                       list( $apiResult ) = $this->doApiRequest( array(
+                       'action' => 'bouncehandler',
+                       'email' => ''
+                       ) );
+
+               $this->assertEquals( 'failure', 
$apiResult['bouncehandler']['submitted'] );
+       }
+
+       /**
+        * Tests API with Wrong params
+        *
+        */
+       function testBounceHandlerWithWrongParams() {
+               $this->setMwGlobals( 'wgBounceHandlerInternalIPs', array( 
'127.0.0.1' ) );
+               list( $apiResult ) = $this->doApiRequest( array(
+                       'action' => 'bouncehandler',
+                       'emails' => self::$bounceEmail
+               ) );
+
+               $this->assertEquals( 'failure', 
$apiResult['bouncehandler']['submitted'] );
+       }
+
 }
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/170523
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I1767fcf126b0b1385725d96eb9eedebac2856a7b
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/BounceHandler
Gerrit-Branch: master
Gerrit-Owner: 01tonythomas <[email protected]>
Gerrit-Reviewer: 01tonythomas <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Jgreen <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to