From 8878e7098292c94b50c7650f33411bde28a8e067 Mon Sep 17 00:00:00 2001
From: sun <sun@unleashedmind.com>
Date: Tue, 29 May 2012 06:12:24 +0200
Subject: [PATCH] - #1551424 by sun: Fixed testing mode may unset API keys and
 save them.

---
 mollom.drupal.inc |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/mollom.drupal.inc b/mollom.drupal.inc
index 37f6742..7ea3a4f 100644
--- a/mollom.drupal.inc
+++ b/mollom.drupal.inc
@@ -246,6 +246,7 @@ class MollomDrupalTest extends MollomDrupal {
       $this->configuration_map['privateKey'] = 'mollom_test_private_key';
     }
 
+    // Load and set publicKey and privateKey configuration values.
     parent::__construct();
 
     // Any Mollom API request requires valid API keys, or no API calls can be
@@ -267,7 +268,7 @@ class MollomDrupalTest extends MollomDrupal {
     // Verifying keys may return an authentication error, from which we will
     // automatically recover below, so do not write the request log (yet).
     $this->writeLog = FALSE;
-    if (!empty($this->publicKey)) {
+    if (!empty($this->publicKey) && !empty($this->privateKey)) {
       $result = $this->verifyKeys();
     }
     else {
@@ -277,8 +278,9 @@ class MollomDrupalTest extends MollomDrupal {
 
     // If current keys are invalid, create and save new testing API keys.
     if ($result === self::AUTH_ERROR) {
-      $this->createKeys();
-      $this->saveKeys();
+      if ($this->createKeys()) {
+        $this->saveKeys();
+      }
     }
   }
 
@@ -307,12 +309,14 @@ class MollomDrupalTest extends MollomDrupal {
     $this->oAuthStrategy = $oAuthStrategy;
 
     // Set class properties.
-    if (is_array($result) && isset($result['publicKey'])) {
+    if (is_array($result) && !empty($result['publicKey']) && !empty($result['privateKey'])) {
       $this->publicKey = $result['publicKey'];
       $this->privateKey = $result['privateKey'];
+      return TRUE;
     }
     else {
       unset($this->publicKey, $this->privateKey);
+      return FALSE;
     }
   }
 
-- 
1.7.6.msysgit.0

